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 / UpdateTableStatisticsOperation.java @ 44058

History | View | Annotate | Download (1.89 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.List;
7
import org.gvsig.fmap.dal.exception.DataException;
8
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
9
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
10
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException;
11
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
12
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
13

    
14
public class UpdateTableStatisticsOperation extends AbstractConnectionWritableOperation {
15

    
16
    private final TableReference table;
17

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

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

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

    
38
    public void updateTableStatistics(
39
            Connection conn,
40
            TableReference table
41
        ) throws DataException {
42

    
43
        JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
44
        sqlbuilder.update_table_statistics().table()
45
                .database(this.table.getDatabase())
46
                .schema(this.table.getSchema())
47
                .name(this.table.getTable());
48
        List<String> sqls;
49
        sqls = sqlbuilder.update_table_statistics().toStrings();
50

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