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 @ 43377

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 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

    
12
public class DropTableOperation extends AbstractConnectionWritableOperation {
13

    
14
    private final String schemaName;
15
    private final String tableName;
16
    private final String dbName;
17

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

    
24
    public DropTableOperation(
25
            JDBCHelper helper,
26
            String dbName,
27
            String schemaName,
28
            String tableName
29
    ) {
30
        super(helper);
31
        this.dbName = dbName;
32
        this.schemaName = schemaName;
33
        this.tableName = tableName;
34
    }
35

    
36
    @Override
37
    public final Object perform(Connection conn) throws DataException {
38
        this.dropTable(conn, dbName, schemaName, tableName);
39
        return true;
40
    }
41

    
42
    public void dropTable(Connection conn,
43
            String dbName,
44
            String schemaName,
45
            String tableName) throws DataException {
46

    
47
        JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
48
        sqlbuilder.drop_table().table().database(dbName).schema(schemaName).name(tableName);
49

    
50
        Statement st = null;
51
        try {
52
            st = conn.createStatement();
53
            for (String sql : sqlbuilder.drop_table().toStrings()) {
54
                JDBCUtils.execute(st, sql);
55
            }
56
        } catch (SQLException ex) {
57
            throw new JDBCSQLException(ex);
58
        } finally {
59
            JDBCUtils.closeQuietly(st);
60
        }
61
    }
62
}