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 | 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 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 | 44058 | jjdelcerro | import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
13 | 43020 | jjdelcerro | |
14 | 43377 | jjdelcerro | public class UpdateTableStatisticsOperation extends AbstractConnectionWritableOperation { |
15 | 43020 | jjdelcerro | |
16 | 44058 | jjdelcerro | private final TableReference table; |
17 | 43020 | jjdelcerro | |
18 | public UpdateTableStatisticsOperation(
|
||
19 | JDBCHelper helper |
||
20 | ) { |
||
21 | 44058 | jjdelcerro | this(helper, null); |
22 | 43020 | jjdelcerro | } |
23 | |||
24 | public UpdateTableStatisticsOperation(
|
||
25 | JDBCHelper helper, |
||
26 | 44058 | jjdelcerro | TableReference table |
27 | 43020 | jjdelcerro | ) { |
28 | super(helper);
|
||
29 | 44058 | jjdelcerro | this.table = table;
|
30 | 43020 | jjdelcerro | } |
31 | |||
32 | @Override
|
||
33 | public final Object perform(Connection conn) throws DataException { |
||
34 | 44058 | jjdelcerro | this.updateTableStatistics(conn, table);
|
35 | 43020 | jjdelcerro | return true; |
36 | } |
||
37 | |||
38 | public void updateTableStatistics( |
||
39 | Connection conn,
|
||
40 | 44058 | jjdelcerro | TableReference table |
41 | 43020 | jjdelcerro | ) throws DataException {
|
42 | |||
43 | JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
|
||
44 | 44058 | jjdelcerro | sqlbuilder.update_table_statistics().table() |
45 | .database(this.table.getDatabase())
|
||
46 | .schema(this.table.getSchema())
|
||
47 | .name(this.table.getTable());
|
||
48 | 43020 | jjdelcerro | 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 | } |