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 / OperationsFactoryBase.java @ 45165

History | View | Annotate | Download (9.44 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2020 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.fmap.dal.store.jdbc2.spi.operations;
25

    
26
import java.util.Iterator;
27
import java.util.List;
28
import org.apache.commons.lang3.StringUtils;
29
import org.apache.commons.lang3.tuple.Pair;
30
import org.cresques.cts.IProjection;
31
import org.gvsig.fmap.dal.exception.DataException;
32
import org.gvsig.fmap.dal.feature.EditableFeatureType;
33
import org.gvsig.fmap.dal.feature.FeatureQuery;
34
import org.gvsig.fmap.dal.feature.FeatureType;
35
import org.gvsig.fmap.dal.SQLBuilder;
36
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices;
37
import org.gvsig.fmap.dal.store.jdbc.JDBCNewStoreParameters;
38
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorerParameters;
39
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters;
40
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
41
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory;
42
import org.gvsig.fmap.geom.primitive.Envelope;
43

    
44
public class OperationsFactoryBase implements OperationsFactory {
45

    
46
    public static class DefaultTableReference implements TableReference {
47

    
48
        private final String database;
49
        private final String schema;
50
        private final String table;
51
        private final String subquery;
52

    
53
        public DefaultTableReference(String database, String schema, String table, String subquery) {
54
            this.database = StringUtils.defaultIfBlank(database, null);
55
            this.schema = StringUtils.defaultIfBlank(schema, null);
56
            this.table = StringUtils.defaultIfBlank(table, null);
57
            this.subquery = StringUtils.defaultIfBlank(subquery, null);
58
        }
59
        
60
        @Override
61
        public String getDatabase() {
62
            return this.database;
63
        }
64

    
65
        @Override
66
        public String getSchema() {
67
            return this.schema;
68
        }
69

    
70
        @Override
71
        public String getTable() {
72
            return this.table;
73
        }
74

    
75
        @Override
76
        public String getSubquery() {
77
            return this.subquery;
78
        }
79

    
80
        @Override
81
        public boolean hasDatabase() {
82
            return this.database != null;
83
        }
84
        
85
        @Override
86
        public boolean hasSchema() {
87
            return this.schema != null;
88
        }
89
        
90
        @Override
91
        public boolean hasTable() {
92
            return this.table != null;
93
        }
94
        
95
        @Override
96
        public boolean hasSubquery() {
97
            return this.subquery != null;
98
        }
99

    
100
        @Override
101
        public String toString() {
102
            StringBuilder builder = new StringBuilder();
103
            if( this.hasDatabase() ) {
104
                builder.append(this.database);
105
                builder.append(".");
106
            }
107
            if( this.hasSchema()) {
108
                builder.append(this.schema);
109
                builder.append(".");
110
            }
111
            builder.append(this.table);
112
            if( this.hasSubquery() ) {
113
                builder.append("[");
114
                builder.append(this.subquery);
115
                builder.append("]");
116
            }
117
            return builder.toString();
118
        }
119
        
120
        
121
    }
122
    
123
    protected final JDBCHelper helper;
124

    
125
    public OperationsFactoryBase(JDBCHelper helper) {
126
        this.helper = helper;
127
    }
128

    
129
    @Override
130
    public TableReference createTableReference(JDBCStoreParameters params) {
131
        TableReference t = new DefaultTableReference(
132
                params.getDBName(),
133
                params.getSchema(),
134
                params.getTable(),
135
                params.getSQL()
136
        );
137
        return t;
138
    }
139

    
140
    @Override
141
    public TableReference createTableReference(JDBCNewStoreParameters params) {
142
        TableReference t = new DefaultTableReference(
143
                params.getDBName(),
144
                params.getSchema(),
145
                params.getTable(),
146
                null
147
        );
148
        return t;
149
    }
150

    
151
    @Override
152
    public TableReference createTableReference(String database, String schema, String table, String subquery) {
153
        TableReference t = new DefaultTableReference(database, schema, table, subquery);
154
        return t;
155
    }
156

    
157
    
158
    @Override
159
    public FetchFeatureTypeOperation createFetchFeatureType(
160
            EditableFeatureType type, 
161
            TableReference table, 
162
            List<String> primaryKeys, 
163
            String defaultGeometryField, 
164
            IProjection crs
165
        ) {
166
        return new FetchFeatureTypeOperation(helper, type, table, 
167
                primaryKeys, defaultGeometryField, crs);
168
    }
169
    
170
    @Override
171
    public FetchFeatureProviderByReferenceOperation createFetchFeatureProviderByReference(
172
            FeatureReferenceProviderServices reference, 
173
            FeatureType featureType, 
174
            TableReference table
175
        ) {
176
        return new FetchFeatureProviderByReferenceOperation(helper, reference, 
177
                featureType, table);
178
    }
179

    
180
    @Override
181
    public CalculateEnvelopeOfColumnOperation createCalculateEnvelopeOfColumn(
182
            FeatureType featureType,
183
            TableReference table, 
184
            String columnName, 
185
            String baseFilter, 
186
            Envelope workingArea, 
187
            IProjection crs
188
        ) {
189
        return new CalculateEnvelopeOfColumnOperation(helper, 
190
                featureType, table, columnName, baseFilter, workingArea, crs);
191
    }
192

    
193
    @Override
194
    public PerformChangesOperation createPerformChanges(
195
            TableReference table, 
196
            FeatureType type, 
197
            Iterator deleteds, 
198
            Iterator inserteds, 
199
            Iterator updateds, 
200
            Iterator featureTypesChanged
201
        ) {
202
        return new PerformChangesOperation(helper, table, type, 
203
                deleteds, inserteds, updateds, featureTypesChanged);
204
    }
205

    
206
    @Override
207
    public AppendOperation createAppend(
208
            TableReference table, 
209
            FeatureType type
210
        ) {
211
        return new AppendOperation(helper, table, type);
212
    }
213

    
214
    @Override
215
    public CountOperation createCount(
216
            FeatureType featureType,
217
            TableReference table, 
218
            String baseFilter, 
219
            FeatureQuery query
220
        ) {
221
        return new CountOperation(helper, featureType, table, baseFilter, query);
222
    }
223

    
224
    @Override
225
    public TableIsEmptyOperation createTableIsEmpty(
226
            FeatureType featureType,
227
            TableReference table,
228
            String baseFilter, 
229
            String filter
230
        ) {
231
        return new TableIsEmptyOperation(helper, featureType, table, baseFilter, filter);
232
    }
233

    
234
    @Override
235
    public ResultSetForSetProviderOperation createResultSetForSetProvider(
236
            TableReference table, 
237
            String baseFilter, 
238
            String baseOrder, 
239
            FeatureQuery query, 
240
            FeatureType storeType, 
241
            FeatureType setType, 
242
            long limit, 
243
            long offset, 
244
            int fetchSize
245
        ) {
246
        return new ResultSetForSetProviderOperation(helper, table, 
247
                baseFilter, baseOrder, query, storeType, setType, 
248
                limit, offset, fetchSize);
249
    }
250

    
251
    @Override
252
    public ListTablesOperation createListTables(
253
            int mode,
254
            JDBCServerExplorerParameters baseParameters, 
255
            boolean informationTables
256
        ) {
257
        return new ListTablesOperation(
258
                helper, mode, baseParameters, informationTables );
259
    }
260
    
261
    @Override
262
    public DropTableOperation createDropTable( 
263
            TableReference tableName            
264
        ) {
265
        return new DropTableOperation(helper, tableName);
266
    }
267
    
268
    @Override
269
    public CreateTableOperation createTable(
270
            TableReference table, 
271
            FeatureType type, 
272
            List<Pair<String, SQLBuilder.Privilege>> userAndPrivileges, 
273
            List<String> additionalSQLs
274
        ) throws DataException {
275
        return new CreateTableOperation(
276
                helper, table, type, 
277
                userAndPrivileges, additionalSQLs
278
        );
279
    }
280

    
281
    @Override
282
    public CanCreateTablesOperation createCanCreateTables() {
283
        return new CanCreateTablesOperation(helper);
284
    }
285

    
286
    @Override
287
    public UpdateTableStatisticsOperation createUpdateTableStatistics(
288
            TableReference table
289
        ) {
290
        return new UpdateTableStatisticsOperation(helper, table);
291
    }
292
    
293
    @Override
294
    public CanModifyTableOperation createCanModifyTableOperation(
295
            TableReference table
296
        ) {
297
        return new CanModifyTableOperation(helper, table);
298
    }
299
    
300
    @Override
301
    public ExecuteOperation createExecute(String sql) {
302
        return new ExecuteOperation(helper, sql);
303
    }
304
    
305
}