Statistics
| Revision:

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
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
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
12

    
13
public class DropTableOperation extends AbstractConnectionWritableOperation {
14

    
15
    private final TableReference table;
16

    
17
    public DropTableOperation(
18
            JDBCHelper helper
19
    ) {
20
        this(helper, null);
21
    }
22

    
23
    public DropTableOperation(
24
            JDBCHelper helper,
25
            TableReference table
26
    ) {
27
        super(helper);
28
        this.table = table;
29
    }
30

    
31
    @Override
32
    public final Object perform(Connection conn) throws DataException {
33
        this.dropTable(conn, table);
34
        return true;
35
    }
36

    
37
    public void dropTable(Connection conn,
38
            TableReference table) throws DataException {
39

    
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

    
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
}