Revision 44058

View differences:

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/jdbc/JDBCNewStoreParameters.java
23 23
package org.gvsig.fmap.dal.store.jdbc;
24 24

  
25 25
import org.apache.commons.lang3.StringUtils;
26
import org.gvsig.fmap.dal.feature.EditableFeatureType;
27
import org.gvsig.fmap.dal.feature.FeatureType;
28
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters;
29 26
import org.gvsig.fmap.dal.store.db.DBNewStoreParameters;
30 27

  
31 28
import static org.gvsig.fmap.dal.store.jdbc.JDBCConnectionParameters.CATALOG_PARAMTER_NAME;
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/impl/JDBCSetProvider.java
55 55

  
56 56
public class JDBCSetProvider extends AbstractFeatureSetProvider {
57 57

  
58
    final static protected Logger logger = LoggerFactory.getLogger(JDBCSetProvider.class);
58
    final static protected Logger LOGGER = LoggerFactory.getLogger(JDBCSetProvider.class);
59 59

  
60 60
    private class EmptyJDBCIterator extends JDBCIterator {
61 61

  
......
248 248
                filtersql = filter.getSQL();
249 249
            }
250 250
            CountOperation selectCount = this.getOperations().createCount(
251
                    params.getDBName(),
252
                    params.getSchema(),
253
                    params.getTable(),
254
                    params.getSQL(),
251
                    this.getOperations().createTableReference(params),
255 252
                    params.getBaseFilter(), 
256 253
                    filtersql
257 254
            );
......
270 267
                if( filter != null ) {
271 268
                    filtersql = filter.getSQL();
272 269
                }
273
                TableIsEmptyOperation isEmpty = this.getOperations().createTableIsEmpty(
274
                        params.getDBName(),
275
                        params.getSchema(),
276
                        params.getTable(),
277
                        params.getSQL(),
270
                TableIsEmptyOperation isEmpty_ = this.getOperations().createTableIsEmpty(
271
                        this.getOperations().createTableReference(params),
278 272
                        params.getBaseFilter(), 
279 273
                        filtersql
280 274
                );
281
                this.isEmpty = (Boolean) isEmpty.perform();   
275
                this.isEmpty = (Boolean) isEmpty_.perform();   
282 276
            } else {
283 277
                this.isEmpty = (this.size < 1);
284 278
            }
......
303 297
		.getProviderFeatureType(this.getFeatureType().getId());
304 298
        ResultSetForSetProviderOperation createResultSet 
305 299
            = getOperations().createResultSetForSetProvider(
306
                    params.getDBName(),
307
                    params.getSchema(), 
308
                    params.getTable(), 
309
                    params.getSQL(), 
300
                    this.getOperations().createTableReference(params),
310 301
                    params.getBaseFilter(), 
311 302
                    params.getBaseOrder(), 
312 303
                    this.getQuery(), 
......
344 335
		.getProviderFeatureType(this.getFeatureType().getId());
345 336
        ResultSetForSetProviderOperation createResultSet 
346 337
            = getOperations().createResultSetForSetProvider(
347
                    params.getDBName(),
348
                    params.getSchema(), 
349
                    params.getTable(), 
350
                    params.getSQL(), 
338
                    this.getOperations().createTableReference(params),
351 339
                    params.getBaseFilter(), 
352 340
                    params.getBaseOrder(), 
353 341
                    this.getQuery(), 
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/OperationsFactory.java
10 10
import org.gvsig.fmap.dal.feature.FeatureType;
11 11
import org.gvsig.fmap.dal.SQLBuilder;
12 12
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices;
13
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters;
14
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
13 15
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
14 16
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.AppendOperation;
15 17
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.CalculateEnvelopeOfColumnOperation;
......
30 32

  
31 33
public interface OperationsFactory {
32 34

  
33
    public FetchFeatureTypeOperation createFetchFeatureType(
34
            EditableFeatureType type,
35
    public interface TableReference {
36
        public String getDatabase();
37
        public String getSchema();
38
        public String getTable();
39
        public String getSubquery();
40
        public boolean hasDatabase();
41
        public boolean hasSchema();
42
        public boolean hasTable();
43
        public boolean hasSubquery();
44
    }
45
    
46
    public TableReference createTableReference(
35 47
            String database,
36 48
            String schema,
37 49
            String table,
50
            String subquery            
51
    );
52
    
53
    public TableReference createTableReference(JDBCStoreParameters params);
54
    public TableReference createTableReference(JDBCNewStoreParameters params);
55
    
56
    public FetchFeatureTypeOperation createFetchFeatureType(
57
            EditableFeatureType type,
58
            TableReference table,
38 59
            List<String> primaryKeys,
39 60
            String defaultGeometryField,
40 61
            IProjection crs
41 62
    );
42 63
    
43
//    public FetchFeatureTypeOperation createFetchFeatureType(
44
//                EditableFeatureType type, 
45
//                String defaultGeometryField, 
46
//                IProjection crs
47
//    );
48
//
49 64
    public FetchFeatureProviderByReferenceOperation createFetchFeatureProviderByReference(
50 65
            FeatureReferenceProviderServices reference,
51 66
            FeatureType featureType,
52
            String database,
53
            String schema,
54
            String table
67
            TableReference table
55 68
    );
56 69

  
57 70
    public CalculateEnvelopeOfColumnOperation createCalculateEnvelopeOfColumn(
58
            String subquery,
59
            String database,
60
            String schema,
61
            String table,
71
            TableReference table,
62 72
            String columnName,
63 73
            String baseFilter,
64 74
            Envelope workingArea,
......
66 76
    );
67 77

  
68 78
    public PerformChangesOperation createPerformChanges(
69
            String database,
70
            String schema,
71
            String table,
79
            TableReference table,
72 80
            FeatureType type,
73 81
            Iterator deleteds,
74 82
            Iterator inserteds,
......
77 85
    );
78 86

  
79 87
    public AppendOperation createAppend(
80
            String database,
81
            String schema,
82
            String table,
88
            TableReference table,
83 89
            FeatureType type
84 90
    );
85 91

  
86 92
    public CountOperation createCount(
87
            String database,
88
            String schema,
89
            String table,
90
            String sql,
93
            TableReference table,
91 94
            String baseFilter,
92 95
            String filter
93 96
    );
94 97

  
95 98
    public TableIsEmptyOperation createTableIsEmpty(
96
            String database,
97
            String schema,
98
            String table,
99
            String sql,
99
            TableReference table,
100 100
            String baseFilter,
101 101
            String filtersql
102 102
    );
103 103

  
104 104
    public ResultSetForSetProviderOperation createResultSetForSetProvider(
105
            String database,
106
            String schema,
107
            String table,
108
            String subquery,
105
            TableReference table,
109 106
            String baseFilter,
110 107
            String baseOrder,
111 108
            FeatureQuery query,
......
123 120
    );
124 121

  
125 122
    public DropTableOperation createDropTable(
126
            String database,
127
            String schemaName,
128
            String tableName
123
            TableReference table
129 124
    );
130 125

  
131 126
    public CreateTableOperation createTable(
132
            String database,
133
            String schemaName,
134
            String tableName,
127
            TableReference table,
135 128
            FeatureType type,
136 129
            List<Pair<String, SQLBuilder.Privilege>> userAndPrivileges,
137 130
            List<String> additionalSQLs
......
140 133
    public CanCreateTablesOperation createCanCreateTables();
141 134
    
142 135
    public UpdateTableStatisticsOperation createUpdateTableStatistics(
143
            String database,
144
            String schemaName,
145
            String tableName
136
            TableReference table
146 137
    );
147 138

  
148 139
    public CanModifyTableOperation createCanModifyTableOperation(
149
            String dbName,
150
            String schemaName, 
151
            String tableName
140
            TableReference table
152 141
    );
153 142
    
154 143
    public ExecuteOperation createExecute(String sql);
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/TableIsEmptyOperation.java
10 10
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
11 11
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException;
12 12
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
13
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
13 14

  
14 15
public class TableIsEmptyOperation extends AbstractConnectionOperation {
15 16

  
16
    private final String schemaName;
17
    private final String tableName;
18
    private final String subquery;
17
    private final TableReference table;
19 18
    private final String baseFilter;
20 19
    private final String filter;
21
    private final String dbName;
22 20

  
23 21
    public TableIsEmptyOperation(
24 22
            JDBCHelper helper
25 23
        ) {
26
        this(helper, null, null, null, null, null, null);
24
        this(helper, null, null, null);
27 25
    }
28 26

  
29 27
    public TableIsEmptyOperation(
30 28
            JDBCHelper helper,
31
            String dbName,
32
            String schemaName,
33
            String tableName,
34
            String subquery,
29
            TableReference table,
35 30
            String baseFilter,
36 31
            String filter
37 32
        ) {
38 33
        super(helper);
39
        this.dbName = dbName;
40
        this.schemaName = schemaName;
41
        this.tableName = tableName;
42
        this.subquery = subquery;
34
        this.table = table;
43 35
        this.baseFilter = baseFilter;
44 36
        this.filter = filter;
45 37
    }
46 38

  
47 39
    @Override
48 40
    public final Object perform(Connection conn) throws DataException {
49
        return this.tableIsEmpty(conn,
50
                dbName, schemaName, tableName, subquery, baseFilter, filter);
41
        return this.tableIsEmpty(conn, table, baseFilter, filter);
51 42
    }
52 43

  
53 44
    public boolean tableIsEmpty(Connection conn,
54
            String database,
55
            String schema,
56
            String table,
57
            String subquery,
45
            TableReference table,
58 46
            String baseFilter,
59
            String filter) throws DataException {
47
            String filter
48
        ) throws DataException {
60 49

  
61 50
        JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
62 51

  
63 52
        sqlbuilder.select().column().all();
64
        sqlbuilder.select().from().table().database(database).schema(schema).name(table);
65
        sqlbuilder.select().from().subquery(subquery);
53
        sqlbuilder.select().from().table()
54
                .database(this.table.getDatabase())
55
                .schema(this.table.getSchema())
56
                .name(this.table.getTable());
57
        sqlbuilder.select().from().subquery(this.table.getSubquery());
66 58
        if (!StringUtils.isEmpty(baseFilter)) {
67 59
            sqlbuilder.select().where().set( sqlbuilder.custom(baseFilter) );
68 60
        }
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/PerformChangesOperation.java
23 23
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCUpdateWithoutChangesException;
24 24
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
25 25
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
26
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
26 27
import org.gvsig.tools.dispose.Disposable;
27 28
import org.gvsig.tools.dispose.DisposeUtils;
28 29

  
29 30
public class PerformChangesOperation extends AbstractConnectionWritableOperation {
30 31

  
31
    protected String dbName;
32
    protected String schemaName;
33
    protected String tableName;
32
    protected TableReference table;
34 33
    protected FeatureType featureType;
35 34
    protected Iterator<FeatureReferenceProviderServices> deleteds;
36 35
    protected Iterator<FeatureStoreProvider.FeatureTypeChanged> featureTypesChanged;
......
40 39
    protected boolean typeChanged = false;
41 40
    
42 41
    public PerformChangesOperation(JDBCHelper helper) {
43
        this(helper, null, null, null, null, null, null, null, null);
42
        this(helper, null, null, null, null, null, null);
44 43
    }
45 44

  
46 45
    public PerformChangesOperation(JDBCHelper helper,
47
            String dbName,
48
            String schemaName,
49
            String tableName,
46
            TableReference table,
50 47
            FeatureType featureType,
51 48
            Iterator<FeatureReferenceProviderServices> deleteds,
52 49
            Iterator<FeatureProvider> inserteds,
53 50
            Iterator<FeatureProvider> updateds,
54 51
            Iterator<FeatureStoreProvider.FeatureTypeChanged> featureTypesChanged) {
55 52
        super(helper);
56
        this.dbName = dbName;
57 53
        this.deleteds = deleteds;
58 54
        this.inserteds = inserteds;
59 55
        this.updateds = updateds;
60
        this.schemaName = schemaName;
61
        this.tableName = tableName;
56
        this.table = table;
62 57
        this.featureType = featureType;
63 58
        this.featureTypesChanged = featureTypesChanged;
64 59
    }
......
71 66
    public Object perform(Connection conn) throws DataException {
72 67
        if (featureTypesChanged.hasNext()) {
73 68
            FeatureStoreProvider.FeatureTypeChanged item = featureTypesChanged.next();
74
            this.performUpdateTable(conn, dbName, schemaName, tableName, item.getSource(), item.getTarget());
69
            this.performUpdateTable(conn, table, item.getSource(), item.getTarget());
75 70
            typeChanged = true;
76 71
        } else {
77 72
            typeChanged = false;
78 73
        }
79 74
        if (deleteds.hasNext()) {
80
            performDeletes(conn, dbName, schemaName, tableName, featureType, deleteds);
75
            performDeletes(conn, table, featureType, deleteds);
81 76
        }
82 77
        if (updateds.hasNext()) {
83
            performUpdates(conn, dbName, schemaName, tableName, featureType, updateds);
78
            performUpdates(conn, table, featureType, updateds);
84 79
        }
85 80
        if (inserteds.hasNext()) {
86
            performInserts(conn, dbName, schemaName, tableName, featureType, inserteds);
81
            performInserts(conn, table, featureType, inserteds);
87 82
        }
88 83
        return true;
89 84
    }
90 85
    
91 86
    protected JDBCSQLBuilderBase buildDeleteSQL(
92
            String database,
93
            String schema,
94
            String table,
87
            TableReference table,
95 88
            FeatureType type
96 89
        ) {
97 90
        JDBCSQLBuilderBase sqlbuilder = createSQLBuilder();
98
        sqlbuilder.delete().table().database(database).schema(schema).name(table);
91
        sqlbuilder.delete().table()
92
                .database(this.table.getDatabase())
93
                .schema(this.table.getSchema())
94
                .name(this.table.getTable());
99 95
        for (FeatureAttributeDescriptor attr : type) {
100 96
            if (attr.isPrimaryKey()) {
101 97
                sqlbuilder.delete().where().and(
......
113 109
    }
114 110

  
115 111
    public void performDeletes(Connection conn,
116
            String database,
117
            String schema,
118
            String table,
112
            TableReference table,
119 113
            FeatureType type,
120 114
            Iterator<FeatureReferenceProviderServices> deleteds) throws DataException {
121 115

  
122
        JDBCSQLBuilderBase sqlbuilder = buildDeleteSQL(database, schema, table, type);
116
        JDBCSQLBuilderBase sqlbuilder = buildDeleteSQL(table, type);
123 117

  
124 118
        PreparedStatement st = null;
125 119
        Disposable paramsDisposer = null;
......
137 131
                    );
138 132
                }
139 133
                if (nAffected > 1) {
140
                    logger.warn("Remove statement affectst to {} rows ( {} )",
134
                    LOGGER.warn("Remove statement affectst to {} rows ( {} )",
141 135
                            nAffected, sql
142 136
                    );
143 137
                }
......
151 145
    }
152 146
    
153 147
    protected JDBCSQLBuilderBase buildInsertSQL(
154
            String database,
155
            String schema,
156
            String table,
148
            TableReference table,
157 149
            FeatureType type
158 150
        ) {
159 151
        JDBCSQLBuilderBase sqlbuilder = createSQLBuilder();
160 152

  
161
        sqlbuilder.insert().table().database(database).schema(schema).name(table);
153
        sqlbuilder.insert().table()
154
                .database(this.table.getDatabase())
155
                .schema(this.table.getSchema())
156
                .name(this.table.getTable());
162 157
        for (FeatureAttributeDescriptor attr : type) {
163 158
            if( attr.isAutomatic() ) {
164 159
                continue;
......
179 174
    }
180 175

  
181 176
    public void performInserts(Connection conn,
182
            String database,
183
            String schema,
184
            String table,
177
            TableReference table,
185 178
            FeatureType type,
186 179
            Iterator<FeatureProvider> inserteds) throws DataException {
187
        JDBCSQLBuilderBase sqlbuilder = buildInsertSQL(database, schema, table, type);
180
        JDBCSQLBuilderBase sqlbuilder = buildInsertSQL(table, type);
188 181

  
189 182
        PreparedStatement st;
190 183
        Disposable paramsDisposer;
......
213 206
    }
214 207

  
215 208
    protected JDBCSQLBuilderBase buildUpdateSQL(
216
            String database,
217
            String schema,
218
            String table,
209
            TableReference table,
219 210
            FeatureType type
220 211
        ) {
221 212
        JDBCSQLBuilderBase sqlbuilder = createSQLBuilder();
222 213

  
223
        sqlbuilder.update().table().database(database).schema(schema).name(table);
214
        sqlbuilder.update().table()
215
                .database(this.table.getDatabase())
216
                .schema(this.table.getSchema())
217
                .name(this.table.getTable());
224 218
        for (FeatureAttributeDescriptor attr : type) {
225 219
            if (attr.isPrimaryKey()) {
226 220
                sqlbuilder.update().where().and(
......
250 244
    }
251 245
    
252 246
    public void performUpdates(Connection conn,
253
            String database,
254
            String schema,
255
            String table,
247
            TableReference table,
256 248
            FeatureType type,
257 249
            Iterator<FeatureProvider> updateds) throws DataException {
258 250

  
259
        JDBCSQLBuilderBase sqlbuilder = buildUpdateSQL(database, schema, table, type);
251
        JDBCSQLBuilderBase sqlbuilder = buildUpdateSQL(table, type);
260 252
        
261 253
        PreparedStatement st = null;
262 254
        Disposable paramsDisposer = null;
......
279 271
    }
280 272

  
281 273
    protected List<String> buildUpdateTableSQL(
282
            String database,
283
            String schema,
284
            String table,
274
            TableReference table,
285 275
            FeatureType original,
286 276
            FeatureType target
287 277
        ) {
288 278
        JDBCSQLBuilderBase sqlbuilder = createSQLBuilder();
289
        sqlbuilder.alter_table().table().database(database).schema(schema).name(table);
279
        sqlbuilder.alter_table().table()
280
                .database(this.table.getDatabase())
281
                .schema(this.table.getSchema())
282
                .name(this.table.getTable());
290 283

  
291 284
        for (FeatureAttributeDescriptor attrOrgiginal : original) {
292 285
            FeatureAttributeDescriptor attrTarget = target.getAttributeDescriptor(
......
387 380
    }
388 381

  
389 382
    protected List<String> buildCreateIndexSQL(
390
            String database,
391
            String schema,
392
            String table,
383
            TableReference table,
393 384
            FeatureType original,
394 385
            FeatureType target
395 386
        ) {
......
417 408
                sqlbuilder.create_index().if_not_exist();
418 409
                sqlbuilder.create_index().name("idx_" + table + "_" + attrTarget.getName());
419 410
                sqlbuilder.create_index().column(attrTarget.getName());
420
                sqlbuilder.create_index().table().database(database).schema(schema).name(table);
411
                sqlbuilder.create_index().table()
412
                    .database(this.table.getDatabase())
413
                    .schema(this.table.getSchema())
414
                    .name(this.table.getTable());
421 415
                sqls.addAll(sqlbuilder.create_index().toStrings());
422 416
            }
423 417
        }
......
425 419
    }
426 420
    
427 421
    public void performUpdateTable(Connection conn,
428
            String database,
429
            String schema,
430
            String table,
422
            TableReference table,
431 423
            FeatureType original,
432 424
            FeatureType target) throws DataException {
433 425
        
434 426
        ArrayList<String> sqls = new ArrayList<>();
435 427
        
436
        sqls.addAll(buildUpdateTableSQL(database, schema, table, original, target));
437
        sqls.addAll(buildCreateIndexSQL(database, schema, table, original, target));
428
        sqls.addAll(buildUpdateTableSQL(table, original, target));
429
        sqls.addAll(buildCreateIndexSQL(table, original, target));
438 430

  
439 431
        if( !CollectionUtils.isEmpty(sqls) ) {
440 432
            Statement st = null;
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
9 9
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
10 10
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException;
11 11
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
12
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
12 13

  
13 14
public class UpdateTableStatisticsOperation extends AbstractConnectionWritableOperation {
14 15

  
15
    private final String schemaName;
16
    private final String tableName;
17
    private final String dbName;
16
    private final TableReference table;
18 17

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

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

  
37 32
    @Override
38 33
    public final Object perform(Connection conn) throws DataException {
39
        this.updateTableStatistics(conn, dbName, schemaName, tableName);
34
        this.updateTableStatistics(conn, table);
40 35
        return true;
41 36
    }
42 37

  
43 38
    public void updateTableStatistics(
44 39
            Connection conn,
45
            String database,
46
            String schema,
47
            String table
40
            TableReference table
48 41
        ) throws DataException {
49 42

  
50 43
        JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
51
        sqlbuilder.update_table_statistics().table().database(database).schema(schema).name(table);
52

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

  
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/AppendOperation.java
13 13
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCPreparingSQLException;
14 14
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
15 15
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
16
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
17
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
16 18
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
17 19
import org.gvsig.tools.dispose.Disposable;
18 20
import org.gvsig.tools.dispose.DisposeUtils;
......
22 24

  
23 25
    protected Connection connection = null;
24 26
    protected final JDBCHelper helper;
25
    protected final String database;
26
    protected final String schema;
27
    protected final String table;
27
    protected final TableReference table;
28 28
    protected final FeatureType type;
29 29
    
30 30
    protected JDBCSQLBuilderBase sqlbuilder = null;
......
33 33
    
34 34
    public AppendOperation(
35 35
            JDBCHelper helper, 
36
            String database,
37
            String schema, 
38
            String table, 
36
            TableReference table, 
39 37
            FeatureType type
40 38
        ) {
41 39
        this.helper = helper;
42
        this.database = database;
43
        this.schema = schema;
44 40
        this.table = table;
45 41
        this.type = type;
46 42
    }
......
55 51
            
56 52
            this.sqlbuilder = this.helper.createSQLBuilder();
57 53

  
58
            this.sqlbuilder.insert().table().database(this.database).schema(this.schema).name(this.table);
54
            this.sqlbuilder.insert().table()
55
                    .database(this.table.getDatabase())
56
                    .schema(this.table.getSchema())
57
                    .name(this.table.getTable()
58
            );
59 59
            for (FeatureAttributeDescriptor attr : type) {
60 60
                if( attr.isAutomatic() ) {
61 61
                    continue;
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/FetchFeatureTypeOperation.java
18 18
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
19 19
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
20 20
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
21
import static org.gvsig.fmap.dal.store.jdbc2.spi.operations.AbstractConnectionOperation.logger;
21
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
22 22
import org.gvsig.fmap.geom.Geometry;
23 23
import org.gvsig.fmap.geom.GeometryLocator;
24 24
import org.gvsig.fmap.geom.type.GeometryType;
25
import static org.gvsig.fmap.dal.store.jdbc2.spi.operations.AbstractConnectionOperation.LOGGER;
25 26

  
26 27
public class FetchFeatureTypeOperation extends AbstractConnectionOperation {
27 28
    private final EditableFeatureType featureType;
28
    private final String dbname;
29
    private final String schema;
30
    private final String table;
29
    private final TableReference table;
31 30
    private final List<String> primaryKeys;
32 31
    private final String defaultGeometryColumn;
33 32
    private final IProjection crs;
......
35 34
    public FetchFeatureTypeOperation(
36 35
            JDBCHelper helper
37 36
        ) {
38
        this(helper, null, null, null, null, null, null, null);
37
        this(helper, null, null, null, null, null);
39 38
    }
40 39
    
41 40
    public FetchFeatureTypeOperation(
......
44 43
            String defaultGeometryColumn,
45 44
            IProjection crs
46 45
        ) {
47
        this(helper, featureType, null, null, null, null, defaultGeometryColumn, crs);
46
        this(helper, featureType, null, null, defaultGeometryColumn, crs);
48 47
    }
49 48

  
50 49
    public FetchFeatureTypeOperation(
51 50
            JDBCHelper helper,
52 51
            EditableFeatureType featureType,
53
            String dbname,
54
            String schema,
55
            String table,
52
            TableReference table,
56 53
            List<String> primaryKeys,
57 54
            String defaultGeometryColumn,
58 55
            IProjection crs
59 56
        ) {
60 57
        super(helper);
61 58
        this.featureType = featureType;
62
        this.dbname = dbname;
63
        this.schema = schema;
64 59
        this.table = table;
65 60
        this.primaryKeys = primaryKeys;
66 61
        this.defaultGeometryColumn = defaultGeometryColumn;
......
69 64
    
70 65
    @Override
71 66
    public final Object perform(Connection conn) throws DataException {
72
        this.fetch(featureType, conn, dbname, schema, table, 
67
        this.fetch(featureType, conn, table, 
73 68
                primaryKeys, defaultGeometryColumn, crs
74 69
        );
75 70
        return true;
76 71
    }
77 72
    
78
    protected String getDatabase() {
79
        return this.dbname;
80
    }
81
    
82
    protected String getSchema() {
83
        return this.schema;
84
    }
85
    
86
    protected String getTablename() {
73
    protected TableReference getTable() {
87 74
        return this.table;
88 75
    }
89 76
    
90 77
    public void fetch(
91 78
            EditableFeatureType featureType,
92 79
            Connection conn,
93
            String database,
94
            String schema,
95
            String table,
80
            TableReference table,
96 81
            List<String> pks,
97 82
            String defaultGeometryColumn,
98 83
            IProjection crs
......
102 87
        ResultSet rs = null;
103 88
        try {
104 89
            if (CollectionUtils.isEmpty(pks)) {
105
                if (!StringUtils.isEmpty(table)) {
106
                    pks = this.getPrimaryKeysFromMetadata(conn, null, schema, table);
90
                if (!table.hasSubquery()) {
91
                    pks = this.getPrimaryKeysFromMetadata(conn, null, table.getSchema(), table.getTable());
107 92
                    if (CollectionUtils.isEmpty(pks)) {
108
                        pks = getPrimaryKeysFromInformationSchema(conn, null, schema, table);
93
                        pks = getPrimaryKeysFromInformationSchema(conn, null, table.getSchema(), table.getTable());
109 94
                    }
110 95
                }
111 96
            }
112 97

  
113 98
            JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
114 99
            sqlbuilder.select().column().all();
115
            sqlbuilder.select().from().table().database(database).schema(schema).name(table);
100
            sqlbuilder.select().from().table()
101
                .database(this.table.getDatabase())
102
                .schema(this.table.getSchema())
103
                .name(this.table.getTable());
104
            sqlbuilder.select().from().subquery(this.table.getSubquery());
116 105
            sqlbuilder.select().limit(1);
117 106

  
118 107
            st = conn.createStatement();
......
236 225
            String schema,
237 226
            String table) throws SQLException {
238 227

  
228
        String sql = getSQLToRetrievePrimaryKeysFromInformationSchema(catalog, schema, table);
229

  
230
        Statement st = null;
231
        ResultSet rs = null;
232
        List<String> pks = new ArrayList();
233
        try {
234
            st = conn.createStatement();
235
            rs = JDBCUtils.executeQuery(st, sql);
236
            while (rs.next()) {
237
                pks.add(rs.getString(1));
238
            }
239
            if (pks.isEmpty()) {
240
                return null;
241
            }
242
            return pks;
243

  
244
        } catch (Exception ex) {
245
            return pks;
246
            
247
        } finally {
248
            JDBCUtils.closeQuietly(rs);
249
            JDBCUtils.closeQuietly(st);
250
        }
251
    }
252

  
253
    protected String getSQLToRetrievePrimaryKeysFromInformationSchema(
254
            String catalog,
255
            String schema,
256
            String table
257
        ) throws SQLException {
239 258
        JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
240 259

  
241 260
        sqlbuilder.select().column().name("COLUMN_NAME");
......
276 295
                        sqlbuilder.constant("PRIMARY KEY")
277 296
                )
278 297
        );
279

  
280
        Statement st = null;
281
        ResultSet rs = null;
282
        List<String> pks = new ArrayList();
283
        try {
284
            st = conn.createStatement();
285
            rs = JDBCUtils.executeQuery(st, sqlbuilder.toString());
286
            while (rs.next()) {
287
                pks.add(rs.getString(1));
288
            }
289
            if (pks.isEmpty()) {
290
                return null;
291
            }
292
            return pks;
293

  
294
        } catch (Exception ex) {
295
            return pks;
296
            
297
        } finally {
298
            JDBCUtils.closeQuietly(rs);
299
            JDBCUtils.closeQuietly(st);
300
        }
298
        return sqlbuilder.toString();
301 299
    }
302

  
300
    
301
    
303 302
    protected EditableFeatureAttributeDescriptor getAttributeFromMetadata(
304 303
            EditableFeatureType type,
305 304
            Connection conn,
......
420 419
            attr.setGeometryType(geomType);
421 420
            attr.setSRS(null);
422 421
        } catch (Exception ex) {
423
            logger.warn("Can't get default geometry type.",ex);
422
            LOGGER.warn("Can't get default geometry type.",ex);
424 423
        }
425 424
    }
426 425
    
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/CreateTableOperation.java
5 5
import java.sql.Statement;
6 6
import java.util.ArrayList;
7 7
import java.util.List;
8
import org.apache.commons.collections.CollectionUtils;
9 8
import org.apache.commons.lang3.tuple.Pair;
10 9
import org.gvsig.fmap.dal.exception.DataException;
11 10
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
......
15 14
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
16 15
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException;
17 16
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
17
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
18 18
import org.gvsig.fmap.geom.DataTypes;
19 19

  
20 20
public class CreateTableOperation extends AbstractConnectionWritableOperation {
21 21

  
22
    private final String schemaName;
23
    private final String tableName;
22
    private final TableReference table;
24 23
    private final FeatureType type;
25 24
    private final List<Pair<String, SQLBuilder.Privilege>> userAndPrivileges;
26 25
    private final List<String> additionalSQLs;
27
    private final String dbName;
28 26

  
29 27
    public CreateTableOperation(
30 28
            JDBCHelper helper
31 29
        ) {
32
        this(helper, null, null, null, null, null, null);
30
        this(helper, null, null, null, null);
33 31
    }
34 32
    
35 33
    public CreateTableOperation(
36 34
            JDBCHelper helper,
37
            String dbName,
38
            String schemaName,
39
            String tableName,
35
            TableReference table,
40 36
            FeatureType type,
41 37
            List<Pair<String, SQLBuilder.Privilege>> userAndPrivileges,
42 38
            List<String> additionalSQLs
43 39
        ) {
44 40
        super(helper);
45
        this.dbName = dbName;
46
        this.schemaName = schemaName;
47
        this.tableName = tableName;
41
        this.table = table;
48 42
        this.type = type;
49 43
        this.userAndPrivileges = userAndPrivileges;
50 44
        this.additionalSQLs = additionalSQLs;
......
53 47
    @Override
54 48
    public final Object perform(Connection conn) throws DataException {
55 49
        return this.performCreateTable(conn, 
56
                dbName, schemaName, tableName,
57
                type, userAndPrivileges, additionalSQLs);
50
                table, type, userAndPrivileges, additionalSQLs);
58 51
    }
59 52

  
60 53
    protected List<String> buildCreateIndexesSQL(
61
            String database,
62
            String schema,
63
            String table,
54
            TableReference table,
64 55
            FeatureType type
65 56
        ) {
66 57
        ArrayList<String> sqls = new ArrayList<>();
......
74 65
                sqlbuilder.create_index().if_not_exist();
75 66
                sqlbuilder.create_index().name("idx_" + table + "_" + attr.getName());
76 67
                sqlbuilder.create_index().column(attr.getName());
77
                sqlbuilder.create_index().table().database(database).schema(schema).name(table);
68
                sqlbuilder.create_index().table()
69
                        .database(this.table.getDatabase())
70
                        .schema(this.table.getSchema())
71
                        .name(this.table.getTable()
72
                );
78 73
                sqls.addAll(sqlbuilder.create_index().toStrings());
79 74
            }
80 75
        }
......
82 77
    }
83 78
    
84 79
    public boolean performCreateTable(Connection conn,
85
            String dbName, 
86
            String schemaName,
87
            String tableName,
80
            TableReference table,
88 81
            FeatureType type,
89 82
            List<Pair<String, SQLBuilder.Privilege>> rolesAndPrivileges,
90 83
            List<String> additionalSQLs) throws DataException {
91 84

  
92 85
        JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
93
        sqlbuilder.create_table().table().database(dbName).schema(schemaName).name(tableName);
86
        sqlbuilder.create_table().table()
87
                .database(this.table.getDatabase())
88
                .schema(this.table.getSchema())
89
                .name(this.table.getTable());
94 90
        for (FeatureAttributeDescriptor attr : type) {
95 91
            if( attr.getType()==DataTypes.GEOMETRY ) {
96 92
                sqlbuilder.create_table().add_geometry_column(
......
121 117

  
122 118
        List<String> sqls;
123 119
        sqls = sqlbuilder.create_table().toStrings();
124
        sqls.addAll(buildCreateIndexesSQL(dbName, schemaName, tableName, type));
120
        sqls.addAll(buildCreateIndexesSQL(this.table,type));
125 121
        sqls.addAll(sqlbuilder.grant().toStrings());
126 122
        sqls.addAll(additionalSQLs);
127 123

  
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
8 8
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
9 9
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException;
10 10
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
11
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
11 12

  
12 13
public class DropTableOperation extends AbstractConnectionWritableOperation {
13 14

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

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

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

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

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

  
47 40
        JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
48
        sqlbuilder.drop_table().table().database(dbName).schema(schemaName).name(tableName);
41
        sqlbuilder.drop_table().table()
42
                .database(this.table.getDatabase())
43
                .schema(this.table.getSchema())
44
                .name(this.table.getTable());
49 45

  
50 46
        Statement st = null;
51 47
        try {
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/CanModifyTableOperation.java
3 3
import java.sql.Connection;
4 4
import org.gvsig.fmap.dal.exception.DataException;
5 5
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
6
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
6 7

  
7 8
public class CanModifyTableOperation extends AbstractConnectionOperation {
8 9

  
9
    private final String schemaName;
10
    private final String tableName;
11
    private final String dbName;
10
    private final TableReference table;
12 11

  
13 12
    public CanModifyTableOperation(
14 13
            JDBCHelper helper
15 14
        ) {
16
        this(helper, null, null, null);
15
        this(helper, null);
17 16
    }
18 17

  
19 18
    public CanModifyTableOperation(
20 19
            JDBCHelper helper,
21
            String dbName,
22
            String schemaName,
23
            String tableName
20
            TableReference table
24 21
        ) {
25 22
        super(helper);
26
        this.dbName = dbName;
27
        this.schemaName = schemaName;
28
        this.tableName = tableName;
23
        this.table = table;
29 24
    }
30 25

  
31 26
    @Override
32 27
    public Object perform(Connection conn) throws DataException {
33
        return this.canModifyTable(conn,
34
                dbName, schemaName, tableName);
28
        return this.canModifyTable(conn,table);
35 29
    }
36 30

  
37
    public boolean canModifyTable(Connection conn,
38
            String dbName,
39
            String schemaName,
40
            String tableName
41
        ) throws DataException {
42

  
31
    public boolean canModifyTable(Connection conn,TableReference table) throws DataException {
43 32
        return true;
44 33
    }
45 34

  
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/AbstractConnectionOperation.java
11 11

  
12 12
public abstract class AbstractConnectionOperation implements ConnectionOperation {
13 13

  
14
    final static protected Logger logger = LoggerFactory.getLogger(AbstractConnectionOperation.class);
14
    final static protected Logger LOGGER = LoggerFactory.getLogger(AbstractConnectionOperation.class);
15 15

  
16 16
    final protected JDBCHelper helper;
17 17
    
......
55 55
    
56 56
    protected Object perform_operation() throws Exception {
57 57
        Object result = null;
58
        logger.debug("preparing execution of "+this.getClass().getSimpleName()+".");
58
        LOGGER.debug("preparing execution of "+this.getClass().getSimpleName()+".");
59 59
        if( needTransaction() ) {
60 60
            try {
61 61
                // XXX OJO esta condicion NO ES FIABLE
......
66 66
                }
67 67
                this.getConnection().setAutoCommit(false);
68 68
                try {
69
                    logger.debug("Excuting operation {}.", this.getClass().getSimpleName());
69
                    LOGGER.debug("Excuting operation {}.", this.getClass().getSimpleName());
70 70
                    result = perform(this.getConnection());
71 71
                } catch (Exception ex) {
72 72
                    try {
......
83 83
            }
84 84
        } else {
85 85
            try {
86
                logger.debug("Excuting operation {}.", this.getClass().getSimpleName());
86
                LOGGER.debug("Excuting operation {}.", this.getClass().getSimpleName());
87 87
                result = perform(this.getConnection());
88 88
            } catch (Exception ex) {
89 89
                throw new RuntimeException("Can't perform operation '"+this.getClass().getSimpleName()+"'.",ex);
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/OperationsFactoryBase.java
2 2

  
3 3
import java.util.Iterator;
4 4
import java.util.List;
5
import org.apache.commons.lang3.StringUtils;
5 6
import org.apache.commons.lang3.tuple.Pair;
6 7
import org.cresques.cts.IProjection;
7 8
import org.gvsig.fmap.dal.exception.DataException;
......
10 11
import org.gvsig.fmap.dal.feature.FeatureType;
11 12
import org.gvsig.fmap.dal.SQLBuilder;
12 13
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices;
14
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters;
15
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
13 16
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
14 17
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
15 18
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
......
17 20

  
18 21
public class OperationsFactoryBase implements OperationsFactory {
19 22

  
23
    protected class DefaultTableReference implements TableReference {
24

  
25
        private final String database;
26
        private final String schema;
27
        private final String table;
28
        private final String subquery;
29

  
30
        public DefaultTableReference(String database, String schema, String table, String subquery) {
31
            this.database = StringUtils.defaultIfBlank(database, null);
32
            this.schema = StringUtils.defaultIfBlank(schema, null);
33
            this.table = StringUtils.defaultIfBlank(table, null);
34
            this.subquery = StringUtils.defaultIfBlank(subquery, null);
35
        }
36
        
37
        @Override
38
        public String getDatabase() {
39
            return this.database;
40
        }
41

  
42
        @Override
43
        public String getSchema() {
44
            return this.schema;
45
        }
46

  
47
        @Override
48
        public String getTable() {
49
            return this.table;
50
        }
51

  
52
        @Override
53
        public String getSubquery() {
54
            return this.subquery;
55
        }
56

  
57
        @Override
58
        public boolean hasDatabase() {
59
            return this.database != null;
60
        }
61
        
62
        @Override
63
        public boolean hasSchema() {
64
            return this.schema != null;
65
        }
66
        
67
        @Override
68
        public boolean hasTable() {
69
            return this.table != null;
70
        }
71
        
72
        @Override
73
        public boolean hasSubquery() {
74
            return this.subquery != null;
75
        }
76
        
77
    }
78
    
20 79
    protected final JDBCHelper helper;
21 80

  
22 81
    public OperationsFactoryBase(JDBCHelper helper) {
......
24 83
    }
25 84

  
26 85
    @Override
86
    public TableReference createTableReference(JDBCStoreParameters params) {
87
        TableReference t = new DefaultTableReference(
88
                params.getDBName(),
89
                params.getSchema(),
90
                params.getTable(),
91
                params.getSQL()
92
        );
93
        return t;
94
    }
95

  
96
    @Override
97
    public TableReference createTableReference(JDBCNewStoreParameters params) {
98
        TableReference t = new DefaultTableReference(
99
                params.getDBName(),
100
                params.getSchema(),
101
                params.getTable(),
102
                null
103
        );
104
        return t;
105
    }
106

  
107
    @Override
108
    public TableReference createTableReference(String database, String schema, String table, String subquery) {
109
        TableReference t = new DefaultTableReference(database, schema, table, subquery);
110
        return t;
111
    }
112

  
113
    
114
    @Override
27 115
    public FetchFeatureTypeOperation createFetchFeatureType(
28 116
            EditableFeatureType type, 
29
            String database,
30
            String schema, 
31
            String table, 
117
            TableReference table, 
32 118
            List<String> primaryKeys, 
33 119
            String defaultGeometryField, 
34 120
            IProjection crs
35 121
        ) {
36
        return new FetchFeatureTypeOperation(helper, type, database, schema, table, 
122
        return new FetchFeatureTypeOperation(helper, type, table, 
37 123
                primaryKeys, defaultGeometryField, crs);
38 124
    }
39 125
    
40
//    @Override
41
//    public FetchFeatureTypeOperation createFetchFeatureType(
42
//            EditableFeatureType type, 
43
//            String defaultGeometryField, 
44
//            IProjection crs
45
//        ) {
46
//        return new FetchFeatureTypeOperation(helper, type, defaultGeometryField, crs);
47
//    }
48

  
49 126
    @Override
50 127
    public FetchFeatureProviderByReferenceOperation createFetchFeatureProviderByReference(
51 128
            FeatureReferenceProviderServices reference, 
52 129
            FeatureType featureType, 
53
            String database,
54
            String schema, 
55
            String table
130
            TableReference table
56 131
        ) {
57 132
        return new FetchFeatureProviderByReferenceOperation(helper, reference, 
58
                featureType, database, schema, table);
133
                featureType, table);
59 134
    }
60 135

  
61 136
    @Override
62 137
    public CalculateEnvelopeOfColumnOperation createCalculateEnvelopeOfColumn(
63
            String subquery, 
64
            String database,
65
            String schema, 
66
            String table, 
138
            TableReference table, 
67 139
            String columnName, 
68 140
            String baseFilter, 
69 141
            Envelope workingArea, 
70 142
            IProjection crs
71 143
        ) {
72
        return new CalculateEnvelopeOfColumnOperation(helper, subquery, database, schema, 
144
        return new CalculateEnvelopeOfColumnOperation(helper, 
73 145
                table, columnName, baseFilter, workingArea, crs);
74 146
    }
75 147

  
76 148
    @Override
77 149
    public PerformChangesOperation createPerformChanges(
78
            String database,
79
            String schema, 
80
            String table, 
150
            TableReference table, 
81 151
            FeatureType type, 
82 152
            Iterator deleteds, 
83 153
            Iterator inserteds, 
84 154
            Iterator updateds, 
85 155
            Iterator featureTypesChanged
86 156
        ) {
87
        return new PerformChangesOperation(helper, database,schema, table, type, 
157
        return new PerformChangesOperation(helper, table, type, 
88 158
                deleteds, inserteds, updateds, featureTypesChanged);
89 159
    }
90 160

  
91 161
    @Override
92 162
    public AppendOperation createAppend(
93
            String database,
94
            String schema, 
95
            String table, 
163
            TableReference table, 
96 164
            FeatureType type
97 165
        ) {
98
        return new AppendOperation(helper, database,schema, table, type);
166
        return new AppendOperation(helper, table, type);
99 167
    }
100 168

  
101 169
    @Override
102 170
    public CountOperation createCount(
103
            String database,
104
            String schema, 
105
            String table, 
106
            String sql, 
171
            TableReference table, 
107 172
            String baseFilter, 
108 173
            String filter
109 174
        ) {
110
        return new CountOperation(helper, database, schema, table, sql, 
111
                baseFilter, filter);
175
        return new CountOperation(helper, table, baseFilter, filter);
112 176
    }
113 177

  
114 178
    @Override
115 179
    public TableIsEmptyOperation createTableIsEmpty(
116
            String database,
117
            String schema, 
118
            String table,
119
            String sql, 
180
            TableReference table,
120 181
            String baseFilter, 
121 182
            String filter
122 183
        ) {
123
        return new TableIsEmptyOperation(helper, database, schema, table, sql, 
124
                baseFilter, filter);
184
        return new TableIsEmptyOperation(helper, table, baseFilter, filter);
125 185
    }
126 186

  
127 187
    @Override
128 188
    public ResultSetForSetProviderOperation createResultSetForSetProvider(
129
            String database,
130
            String schema, 
131
            String table, 
132
            String subquery, 
189
            TableReference table, 
133 190
            String baseFilter, 
134 191
            String baseOrder, 
135 192
            FeatureQuery query, 
......
139 196
            long offset, 
140 197
            int fetchSize
141 198
        ) {
142
        return new ResultSetForSetProviderOperation(helper, database, schema, table, 
143
                subquery, baseFilter, baseOrder, query, storeType, setType, 
199
        return new ResultSetForSetProviderOperation(helper, table, 
200
                baseFilter, baseOrder, query, storeType, setType, 
144 201
                limit, offset, fetchSize);
145 202
    }
146 203

  
......
156 213
    
157 214
    @Override
158 215
    public DropTableOperation createDropTable( 
159
            String dbName,
160
            String schemaName,
161
            String tableName            
216
            TableReference tableName            
162 217
        ) {
163
        return new DropTableOperation(helper, dbName, schemaName, tableName);
218
        return new DropTableOperation(helper, tableName);
164 219
    }
165 220
    
166 221
    @Override
167 222
    public CreateTableOperation createTable(
168
            String dbName,
169
            String schemaName, 
170
            String tableName, 
223
            TableReference table, 
171 224
            FeatureType type, 
172 225
            List<Pair<String, SQLBuilder.Privilege>> userAndPrivileges, 
173 226
            List<String> additionalSQLs
174 227
        ) throws DataException {
175 228
        return new CreateTableOperation(
176
                helper, dbName, schemaName, tableName, type, 
229
                helper, table, type, 
177 230
                userAndPrivileges, additionalSQLs
178 231
        );
179 232
    }
......
185 238

  
186 239
    @Override
187 240
    public UpdateTableStatisticsOperation createUpdateTableStatistics(
188
            String dbName,
189
            String schemaName, 
190
            String tableName
241
            TableReference table
191 242
        ) {
192
        return new UpdateTableStatisticsOperation(helper, dbName, schemaName, tableName);
243
        return new UpdateTableStatisticsOperation(helper, table);
193 244
    }
194 245
    
195 246
    @Override
196 247
    public CanModifyTableOperation createCanModifyTableOperation(
197
            String dbName,
198
            String schemaName, 
199
            String tableName
248
            TableReference table
200 249
        ) {
201
        return new CanModifyTableOperation(helper, dbName, schemaName, tableName);
250
        return new CanModifyTableOperation(helper, table);
202 251
    }
203 252
    
204 253
    @Override
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/CountOperation.java
10 10
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
11 11
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException;
12 12
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
13
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
13 14

  
14 15
public class CountOperation extends AbstractConnectionOperation {
15 16

  
16
    private final String schemaName;
17
    private final String tableName;
18
    private final String subquery;
17
    private final TableReference table;
19 18
    private final String baseFilter;
20 19
    private final String filter;
21
    private final String dbName;
22 20

  
23 21
    public CountOperation(
24 22
            JDBCHelper helper
25 23
        ) {
26
        this(helper, null, null, null, null, null, null);
24
        this(helper, null, null, null);
27 25
    }
28 26

  
29 27
    public CountOperation(
30 28
            JDBCHelper helper,
31
            String dbName,
32
            String schemaName,
33
            String tableName,
34
            String subquery,
29
            TableReference table,
35 30
            String baseFilter,
36 31
            String filter
37 32
        ) {
38 33
        super(helper);
39
        this.dbName = dbName;
40
        this.schemaName = schemaName;
41
        this.tableName = tableName;
42
        this.subquery = subquery;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff