svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.db / org.gvsig.fmap.dal.db.jdbc / src / main / java / org / gvsig / fmap / dal / store / jdbc2 / spi / operations / DropTableOperation.java @ 44678
History | View | Annotate | Download (1.83 KB)
1 |
package org.gvsig.fmap.dal.store.jdbc2.spi.operations; |
---|---|
2 |
|
3 |
import java.sql.Connection; |
4 |
import java.sql.SQLException; |
5 |
import java.sql.Statement; |
6 |
import java.util.ArrayList; |
7 |
import java.util.List; |
8 |
import org.gvsig.fmap.dal.exception.DataException; |
9 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
10 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
11 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException; |
12 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
13 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
14 |
|
15 |
public class DropTableOperation extends AbstractConnectionWritableOperation { |
16 |
|
17 |
private final TableReference table; |
18 |
|
19 |
public DropTableOperation(
|
20 |
JDBCHelper helper |
21 |
) { |
22 |
this(helper, null); |
23 |
} |
24 |
|
25 |
public DropTableOperation(
|
26 |
JDBCHelper helper, |
27 |
TableReference table |
28 |
) { |
29 |
super(helper);
|
30 |
this.table = table;
|
31 |
} |
32 |
|
33 |
@Override
|
34 |
public final Object perform(Connection conn) throws DataException { |
35 |
this.dropTable(conn);
|
36 |
return true; |
37 |
} |
38 |
|
39 |
public List<String> getSQLs() { |
40 |
JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
|
41 |
sqlbuilder.drop_table().table() |
42 |
.database(this.table.getDatabase())
|
43 |
.schema(this.table.getSchema())
|
44 |
.name(this.table.getTable());
|
45 |
List<String> sqls = sqlbuilder.drop_table().toStrings(); |
46 |
return sqls;
|
47 |
} |
48 |
|
49 |
public void dropTable(Connection conn) throws DataException { |
50 |
|
51 |
Statement st = null; |
52 |
try {
|
53 |
st = conn.createStatement(); |
54 |
for (String sql : this.getSQLs()) { |
55 |
JDBCUtils.execute(st, sql); |
56 |
} |
57 |
} catch (SQLException ex) { |
58 |
throw new JDBCSQLException(ex); |
59 |
} finally {
|
60 |
JDBCUtils.closeQuietly(st); |
61 |
} |
62 |
} |
63 |
} |