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 @ 44058
History | View | Annotate | Download (1.71 KB)
1 | 43020 | jjdelcerro | 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 org.gvsig.fmap.dal.exception.DataException; |
||
7 | import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
||
8 | import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
||
9 | import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException; |
||
10 | import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils; |
||
11 | 44058 | jjdelcerro | import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
12 | 43020 | jjdelcerro | |
13 | 43377 | jjdelcerro | public class DropTableOperation extends AbstractConnectionWritableOperation { |
14 | 43020 | jjdelcerro | |
15 | 44058 | jjdelcerro | private final TableReference table; |
16 | 43020 | jjdelcerro | |
17 | public DropTableOperation(
|
||
18 | JDBCHelper helper |
||
19 | ) { |
||
20 | 44058 | jjdelcerro | this(helper, null); |
21 | 43020 | jjdelcerro | } |
22 | |||
23 | public DropTableOperation(
|
||
24 | JDBCHelper helper, |
||
25 | 44058 | jjdelcerro | TableReference table |
26 | 43020 | jjdelcerro | ) { |
27 | super(helper);
|
||
28 | 44058 | jjdelcerro | this.table = table;
|
29 | 43020 | jjdelcerro | } |
30 | |||
31 | @Override
|
||
32 | public final Object perform(Connection conn) throws DataException { |
||
33 | 44058 | jjdelcerro | this.dropTable(conn, table);
|
34 | 43020 | jjdelcerro | return true; |
35 | } |
||
36 | |||
37 | public void dropTable(Connection conn, |
||
38 | 44058 | jjdelcerro | TableReference table) throws DataException {
|
39 | 43020 | jjdelcerro | |
40 | JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
|
||
41 | 44058 | jjdelcerro | sqlbuilder.drop_table().table() |
42 | .database(this.table.getDatabase())
|
||
43 | .schema(this.table.getSchema())
|
||
44 | .name(this.table.getTable());
|
||
45 | 43020 | jjdelcerro | |
46 | Statement st = null; |
||
47 | try {
|
||
48 | st = conn.createStatement(); |
||
49 | for (String sql : sqlbuilder.drop_table().toStrings()) { |
||
50 | JDBCUtils.execute(st, sql); |
||
51 | } |
||
52 | } catch (SQLException ex) { |
||
53 | throw new JDBCSQLException(ex); |
||
54 | } finally {
|
||
55 | JDBCUtils.closeQuietly(st); |
||
56 | } |
||
57 | } |
||
58 | } |