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 @ 43020
History | View | Annotate | Download (1.99 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 |
|
13 |
public class UpdateTableStatisticsOperation extends AbstractConnectionOperation { |
14 |
|
15 |
private final String schemaName; |
16 |
private final String tableName; |
17 |
private final String dbName; |
18 |
|
19 |
public UpdateTableStatisticsOperation(
|
20 |
JDBCHelper helper |
21 |
) { |
22 |
this(helper, null, null, null); |
23 |
} |
24 |
|
25 |
public UpdateTableStatisticsOperation(
|
26 |
JDBCHelper helper, |
27 |
String dbName,
|
28 |
String schemaName,
|
29 |
String tableName
|
30 |
) { |
31 |
super(helper);
|
32 |
this.dbName = dbName;
|
33 |
this.schemaName = schemaName;
|
34 |
this.tableName = tableName;
|
35 |
} |
36 |
|
37 |
@Override
|
38 |
public final Object perform(Connection conn) throws DataException { |
39 |
this.updateTableStatistics(conn, dbName, schemaName, tableName);
|
40 |
return true; |
41 |
} |
42 |
|
43 |
public void updateTableStatistics( |
44 |
Connection conn,
|
45 |
String database,
|
46 |
String schema,
|
47 |
String table
|
48 |
) throws DataException {
|
49 |
|
50 |
JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
|
51 |
sqlbuilder.update_table_statistics().table().database(database).schema(schema).name(table); |
52 |
|
53 |
List<String> sqls; |
54 |
sqls = sqlbuilder.update_table_statistics().toStrings(); |
55 |
|
56 |
Statement st = null; |
57 |
try {
|
58 |
st = conn.createStatement(); |
59 |
for (String sql : sqls) { |
60 |
JDBCUtils.execute(st, sql); |
61 |
} |
62 |
} catch (SQLException ex) { |
63 |
throw new JDBCSQLException(ex); |
64 |
} finally {
|
65 |
JDBCUtils.closeQuietly(st); |
66 |
} |
67 |
} |
68 |
} |