Revision 44198 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.api/src/main/java/org/gvsig/fmap/dal/SQLBuilder.java

View differences:

SQLBuilder.java
3 3
import java.util.List;
4 4
import org.cresques.cts.IProjection;
5 5
import org.gvsig.expressionevaluator.ExpressionBuilder;
6
import org.gvsig.expressionevaluator.ExpressionBuilder.Config;
7
import org.gvsig.expressionevaluator.ExpressionBuilder.Function;
6
import org.gvsig.expressionevaluator.ExpressionBuilder.GeometrySupportType;
7
import org.gvsig.expressionevaluator.ExpressionBuilder.Parameter;
8 8
import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
9
import org.gvsig.expressionevaluator.ExpressionBuilder.Visitable;
9
import org.gvsig.expressionevaluator.ExpressionBuilder.Variable;
10
import org.gvsig.expressionevaluator.Formatter;
10 11
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
12
import org.gvsig.fmap.dal.feature.FeatureType;
11 13

  
12
public interface SQLBuilder extends ExpressionBuilder {
13
    
14
public interface SQLBuilder {
15

  
16
    public static final String FEATURE_ATTRIBUTE_DESCRIPTOR = "FeatureAttributeDescriptor";
17

  
14 18
    public enum Privilege {
15 19
        SELECT,
16 20
        INSERT,
......
22 26
        ALL
23 27
    };
24 28

  
25
    public interface Statement extends Visitable {
26
        
27
    }
28
    
29
    public interface SQLConfig extends Config {
30
        public final static String default_schema = "default_schema";
31
        
32
        public final static String allowAutomaticValues = "allowAutomaticValues";
33
        
34
        public final static String Find_SRID = "Find_SRID";
35
        public final static String ST_ExtentAggregate = "ST_ExtentAggregate";
36
        public final static String ST_UnionAggregate = "ST_UnionAggregate";
37
        public final static String count = "count";
38
        public final static String count_distinct = "count_distinct";
29
    public interface ColumnDescriptor {
39 30

  
40
        public final static String type_boolean = "type_boolean";
41
        public final static String type_byte = "type_byte";
42
        public final static String type_bytearray = "type_bytearray";
43
        public final static String type_geometry = "type_geometry";
44
        public final static String type_char = "type_char";
45
        public final static String type_date = "type_date";
46
        public final static String type_double = "type_double";
47
        public final static String type_numeric_p = "type_numeric_p";
48
        public final static String type_numeric_ps = "type_numeric_ps";
49
        public final static String type_bigdecimal = "type_bigdecimal";
50
        public final static String type_float = "type_float";
51
        public final static String type_int = "type_int";
52
        public final static String type_long = "type_long";
53
        public final static String type_string = "type_string";
54
        public final static String type_string_p = "type_string_p";
55
        public final static String type_time = "type_time";
56
        public final static String type_timestamp = "type_timestamp";
57
        public final static String type_version = "type_version";
58
        public final static String type_URI = "type_URI";
59
        public final static String type_URL = "type_URL";
60
        public final static String type_FILE = "type_FILE";
61
        public final static String type_FOLDER = "type_FOLDER";
62
     
63
        public final static String DELETE_FROM_table_WHERE_expresion = "DELETE_FROM_table_WHERE_expresion";
64
        public final static String DELETE_FROM_table = "DELETE_FROM_table";
65
        public final static String INSERT_INTO_table_columns_VALUES_values = "INSERT_INTO_table_columns_VALUES_values";
66
        public final static String UPDATE_TABLE_STATISTICS_table = "UPDATE_TABLE_STATISTICS_table";        
67
        public final static String DROP_TABLE_table = "DROP_TABLE_table";
68
        public final static String DELETE_GEOMETRY_COLUMN_FROM_TABLE_schema_table = "DELETE_GEOMETRY_COLUMN_FROM_TABLE_schema_table";
69
        public final static String DELETE_GEOMETRY_COLUMN_FROM_TABLE_table = "DELETE_GEOMETRY_COLUMN_FROM_TABLE_table";
70
        public final static String UPDATE_table_SET_columnsAndValues_WHERE_expresion = "UPDATE_table_SET_columnsAndValues_WHERE_expresion";
71
        public final static String UPDATE_table_SET_columnsAndValues = "UPDATE_table_SET_columnsAndValues";
72
        public final static String GRANT_privileges_ON_table_TO_role = "GRANT_privileges_ON_table_TO_role";
73
//        public final static String CREATE_INDEX_name_ON_table_column = "CREATE_INDEX_name_ON_table_column";
74
//        public final static String CREATE_INDEX_name_ON_table_USING_GIST_column = "CREATE_INDEX_name_ON_table_USING_GIST_column";
75
   
76
    }
77
    
78
    public interface ColumnDescriptor {
79 31
        public String getName();
32

  
80 33
        public int getType();
34

  
81 35
        public int getSize();
36

  
82 37
        public int getPrecision();
38

  
83 39
        public boolean isPrimaryKey();
40

  
84 41
        public boolean isIndexed();
42

  
85 43
        public boolean isAutomatic();
44

  
86 45
        boolean allowNulls();
46

  
87 47
        public Object getDefaultValue();
48

  
88 49
        public int getGeometryType();
50

  
89 51
        public int getGeometrySubtype();
52

  
90 53
        public Object getGeometrySRSId();
54

  
91 55
        public boolean isGeometry();
92
        
56

  
93 57
        public DataStoreParameters getStoreParameters();
94
        
58

  
95 59
        public void setName(String name);
60

  
96 61
        public void setType(int type);
62

  
97 63
        public void setSize(int size);
64

  
98 65
        public void setPrecision(int precision);
66

  
99 67
        public void setIsPrimaryKey(boolean isPk);
68

  
100 69
        public void setIsAutomatic(boolean isAutomatic);
70

  
101 71
        public void setAllowNulls(boolean allowNulls);
72

  
102 73
        public void setDefaultValue(Object defaultValue);
74

  
103 75
        public void setGeometryType(int geom_type);
76

  
104 77
        public void setGeometrySubtype(int geom_subtype);
78

  
105 79
        public void setGeometrySRSId(Object geom_srsid);
106 80
    }
107
    
108
    public interface Column extends Variable {
109
        public ColumnDescriptor getDescriptor();
81

  
82
//    public interface ColumnDescriptorBuilder {
83
//        public String getName();
84
//        public int getType();
85
//        public int getSize();
86
//        public int getPrecision();
87
//        public boolean isPrimaryKey();
88
//        public boolean isIndexed();
89
//        public boolean isAutomatic();
90
//        boolean allowNulls();
91
//        public Object getDefaultValue();
92
//        public int getGeometryType();
93
//        public int getGeometrySubtype();
94
//        public Object getGeometrySRSId();
95
//        public boolean isGeometry();
96
//        
97
//        public void setName(String name);
98
//        public void setType(int type);
99
//        public void setSize(int size);
100
//        public void setPrecision(int precision);
101
//        public void setIsPrimaryKey(boolean isPk);
102
//        public void setIsAutomatic(boolean isAutomatic);
103
//        public void setAllowNulls(boolean allowNulls);
104
//        public void setDefaultValue(Object defaultValue);
105
//        public void setGeometryType(int geom_type);
106
//        public void setGeometrySubtype(int geom_subtype);
107
//        public void setGeometrySRSId(Object geom_srsid);
108
//    }
109
//
110
//    public interface Column extends Variable {
111
//        public ColumnDescriptor getDescriptor();
112
//    }
113
    public interface StatementPart extends Value {
114

  
110 115
    }
111
    
112
    public interface TableNameBuilder extends Visitable {
116

  
117
    public interface Statement extends StatementPart {
118

  
119
    }
120

  
121
    public interface TableNameBuilder extends StatementPart {
122

  
113 123
        public TableNameBuilder database(String name);
124

  
114 125
        public TableNameBuilder schema(String name);
126

  
115 127
        public TableNameBuilder name(String name);
128

  
116 129
        public String getDatabase();
130

  
117 131
        public String getSchema();
132

  
118 133
        public String getName();
134

  
119 135
        public boolean has_database();
136

  
120 137
        public boolean has_schema();
121 138
    }
122
    
123
    public interface ColumnDescriptorBuilder {
124
        public String getName();
125
        public int getType();
126
        public int getSize();
127
        public int getPrecision();
128
        public boolean isPrimaryKey();
129
        public boolean isIndexed();
130
        public boolean isAutomatic();
131
        boolean allowNulls();
132
        public Object getDefaultValue();
133
        public int getGeometryType();
134
        public int getGeometrySubtype();
135
        public Object getGeometrySRSId();
136
        public boolean isGeometry();
137
        
138
        public void setName(String name);
139
        public void setType(int type);
140
        public void setSize(int size);
141
        public void setPrecision(int precision);
142
        public void setIsPrimaryKey(boolean isPk);
143
        public void setIsAutomatic(boolean isAutomatic);
144
        public void setAllowNulls(boolean allowNulls);
145
        public void setDefaultValue(Object defaultValue);
146
        public void setGeometryType(int geom_type);
147
        public void setGeometrySubtype(int geom_subtype);
148
        public void setGeometrySRSId(Object geom_srsid);
149
    }
150 139

  
151
    public interface CountBuilder extends Value {
140
    public interface CountBuilder extends StatementPart {
141

  
152 142
        public CountBuilder all();
143

  
153 144
        public CountBuilder column(Value value);
145

  
154 146
        public CountBuilder distinct();
155 147
    }
156
    
157
    public interface SelectColumnBuilder extends Visitable {
148

  
149
    public interface SelectColumnBuilder extends StatementPart {
150

  
158 151
        public SelectColumnBuilder name(String name);
152

  
159 153
        public SelectColumnBuilder value(Value value);
154

  
160 155
        public SelectColumnBuilder as(String alias);
156

  
161 157
        public SelectColumnBuilder as_geometry();
158

  
162 159
        public SelectColumnBuilder all();
160

  
163 161
        public String getName();
162

  
164 163
        public String getAlias();
164

  
165 165
        public String getValue();
166 166
    }
167
    
168
    public interface InsertColumnBuilder extends Visitable {
167

  
168
    public interface InsertColumnBuilder extends StatementPart {
169

  
169 170
        public InsertColumnBuilder name(String name);
171

  
170 172
        public InsertColumnBuilder with_value(Value value);
173

  
171 174
        public String getName();
175

  
172 176
        public Value getValue();
173 177
    }
174
    
178

  
175 179
    public interface UpdateColumnBuilder extends InsertColumnBuilder {
180

  
176 181
        @Override
177 182
        public UpdateColumnBuilder name(String name);
183

  
178 184
        @Override
179 185
        public UpdateColumnBuilder with_value(Value value);
186

  
180 187
        @Override
181 188
        public String getName();
189

  
182 190
        @Override
183 191
        public Value getValue();
184 192
    }
185
        
186
    public interface FromBuilder extends Visitable {
193

  
194
    public interface FromBuilder extends StatementPart {
195

  
187 196
        public TableNameBuilder table();
197

  
188 198
        public FromBuilder subquery(String subquery);
199

  
189 200
        public FromBuilder custom(String passthrough);
190 201
    }
191 202

  
192
    public interface OrderByBuilder extends Visitable {
203
    public interface OrderByBuilder extends StatementPart {
204

  
193 205
        public OrderByBuilder column(String name);
206

  
194 207
        public OrderByBuilder ascending(boolean asc);
208

  
195 209
        public OrderByBuilder ascending();
210

  
196 211
        public OrderByBuilder descending();
212

  
197 213
        public OrderByBuilder custom(String order);
198 214
    }
199
    
215

  
200 216
    public interface SelectBuilder extends Statement {
217

  
201 218
        public SelectColumnBuilder column();
219

  
202 220
        public FromBuilder from();
221

  
203 222
        public ExpressionBuilder where();
223

  
204 224
        public OrderByBuilder order_by();
225

  
205 226
        public SelectBuilder distinct();
227

  
206 228
        public SelectBuilder limit(long limit);
229

  
207 230
        public SelectBuilder limit(Long limit);
208
        
231

  
209 232
        /**
210
         * Specifies an offset to be applied to the SQL statement.
211
         * Only an offset can be applied if an order has been specified. 
212
         * Otherwise an IllegalStateException exception will be thrown when 
213
         * constructing the SQL statement invoking the toString method.
214
         * 
233
         * Specifies an offset to be applied to the SQL statement. Only an
234
         * offset can be applied if an order has been specified. Otherwise an
235
         * IllegalStateException exception will be thrown when constructing the
236
         * SQL statement invoking the toString method.
237
         *
215 238
         * @param offset
216 239
         * @return this SelectBuilder
217 240
         */
218 241
        public SelectBuilder offset(long offset);
219
        
242

  
220 243
        public boolean has_column(String name);
244

  
221 245
        public boolean has_where();
246

  
222 247
        public boolean has_from();
248

  
223 249
        public boolean has_order_by();
250

  
224 251
        public boolean has_limit();
252

  
225 253
        public boolean has_offset();
226 254

  
227 255
        /**
228
         * Constructs the SQL statement.
229
         * If the values associated with the SQL statement are not valid 
230
         * an IllegalStateException exception is thrown.
231
         * 
256
         * Constructs the SQL statement. If the values associated with the SQL
257
         * statement are not valid an IllegalStateException exception is thrown.
258
         *
232 259
         * @return the SQL select statement.
233
         * @throws IllegalStateException if the values of select statement are not valids.
260
         * @throws IllegalStateException if the values of select statement are
261
         * not valids.
234 262
         */
235 263
        @Override
236 264
        public String toString();
237
        
265

  
238 266
    }
239
    
267

  
240 268
    public interface UpdateBuilder extends Statement {
269

  
241 270
        public TableNameBuilder table();
271

  
242 272
        public UpdateColumnBuilder column();
273

  
243 274
        public ExpressionBuilder where();
275

  
244 276
        public boolean has_where();
245 277
    }
246
    
278

  
247 279
    public interface InsertBuilder extends Statement {
280

  
248 281
        public TableNameBuilder table();
282

  
249 283
        public InsertColumnBuilder column();
250 284
    }
251
    
285

  
252 286
    public interface DeleteBuilder extends Statement {
287

  
253 288
        public TableNameBuilder table();
289

  
254 290
        public ExpressionBuilder where();
291

  
255 292
        public boolean has_where();
256 293
    }
257
    
294

  
258 295
    public interface AlterTableBuilder extends Statement {
296

  
259 297
        public TableNameBuilder table();
298

  
260 299
        public AlterTableBuilder drop_column(String columnName);
300

  
261 301
        public AlterTableBuilder add_column(FeatureAttributeDescriptor fad);
262
        public AlterTableBuilder add_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue);    
302

  
303
        public AlterTableBuilder add_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue);
304

  
263 305
        public AlterTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls);
306

  
264 307
        public AlterTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, Object srsdbcode, boolean isIndexed, boolean allowNulls);
308

  
265 309
        public AlterTableBuilder alter_column(FeatureAttributeDescriptor fad);
310

  
266 311
        public AlterTableBuilder alter_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue);
312

  
267 313
        public AlterTableBuilder alter_geometry_column(String columnName, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls);
314

  
268 315
        public AlterTableBuilder alter_geometry_column(String columnName, int geom_type, int geom_subtype, Object srsdbcode, boolean isIndexed, boolean allowNulls);
316

  
269 317
        public AlterTableBuilder rename_column(String source, String target);
318

  
270 319
        public boolean isEmpty();
320

  
271 321
        public List<String> toStrings();
322

  
323
        public List<String> toStrings(Formatter formatter);
272 324
    }
273
    
325

  
274 326
    public interface CreateTableBuilder extends Statement {
327

  
275 328
        public TableNameBuilder table();
329

  
276 330
        public CreateTableBuilder add_column(FeatureAttributeDescriptor fad);
331

  
277 332
        public CreateTableBuilder add_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue);
333

  
278 334
        public CreateTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls);
335

  
279 336
        public CreateTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, Object srsdbcode, boolean isIndexed, boolean allowNulls);
337

  
280 338
        public ColumnDescriptor getColumnDescriptor(String columnName);
339

  
281 340
        public List<String> toStrings();
341

  
342
        public List<String> toStrings(Formatter formatter);
282 343
    }
283
    
344

  
284 345
    public interface UpdateTableStatisticsBuilder extends Statement {
346

  
285 347
        public TableNameBuilder table();
348

  
286 349
        public List<String> toStrings();
350

  
351
        public List<String> toStrings(Formatter formatter);
287 352
    }
288
        
289
    public interface GrantRoleBuilder {
353

  
354
    public interface GrantRoleBuilder extends StatementPart {
355

  
290 356
        public GrantRoleBuilder privilege(Privilege privilege);
357

  
291 358
        public GrantRoleBuilder select();
359

  
292 360
        public GrantRoleBuilder insert();
361

  
293 362
        public GrantRoleBuilder delete();
363

  
294 364
        public GrantRoleBuilder truncate();
365

  
295 366
        public GrantRoleBuilder reference();
367

  
296 368
        public GrantRoleBuilder update();
369

  
297 370
        public GrantRoleBuilder trigger();
371

  
298 372
        public GrantRoleBuilder all();
299 373
    }
300
    
374

  
301 375
    public interface GrantBuilder extends Statement {
376

  
302 377
        public TableNameBuilder table();
303
        public GrantRoleBuilder role(String name);        
378

  
379
        public GrantRoleBuilder role(String name);
380

  
304 381
        public List<String> toStrings();
382

  
383
        public List<String> toStrings(Formatter formatter);
305 384
    }
306
        
385

  
307 386
    public interface DropTableBuilder extends Statement {
387

  
308 388
        public TableNameBuilder table();
389

  
309 390
        public List<String> toStrings();
391

  
392
        public List<String> toStrings(Formatter formatter);
310 393
    }
311
    
394

  
312 395
    public interface CreateIndexBuilder extends Statement {
396

  
313 397
        public CreateIndexBuilder if_not_exist();
398

  
314 399
        public CreateIndexBuilder unique();
400

  
315 401
        public CreateIndexBuilder name(String name);
402

  
316 403
        public CreateIndexBuilder spatial();
404

  
317 405
        public CreateIndexBuilder column(String name);
406

  
318 407
        public TableNameBuilder table();
408

  
319 409
        public List<String> toStrings();
410

  
411
        public List<String> toStrings(Formatter formatter);
320 412
    }
321 413

  
322
    @Override
323
    public Column column(String name); 
414
    public String default_schema();
324 415

  
325
    public Column column(FeatureAttributeDescriptor fad); 
416
    public boolean support_schemas();
326 417

  
327
    @Override
328
    public List<Variable> getVariables();
329
    
330
    public String default_schema();
331
    
332
    public boolean supportSchemas();
418
    public boolean has_spatial_functions();
333 419

  
334
    @Deprecated
335
    public String sqltype(int dataType, int p, int s);
336
    
420
    public GeometrySupportType geometry_support_type();
421

  
337 422
    public String sqltype(int dataType, int p, int s, int geomType, int geomSubtype);
338
    
423

  
339 424
    public Object sqlgeometrytype(int type, int subtype);
340 425

  
341 426
    public Object sqlgeometrydimension(int type, int subtype);
342
    
427

  
428
    public Object srs_id(IProjection projection);
429

  
430
    public String toString(Formatter formatter);
431

  
432
    public List<Variable> variables();
433

  
434
    public List<String> variables_names();
435

  
436
    public List<Parameter> parameters();
437

  
438
    public List<String> parameters_names();
439

  
343 440
    public SelectBuilder select();
344
    
441

  
345 442
    public UpdateBuilder update();
346 443

  
347 444
    public InsertBuilder insert();
348
    
445

  
349 446
    public DeleteBuilder delete();
350
    
447

  
351 448
    public AlterTableBuilder alter_table();
352 449

  
353 450
    public CreateTableBuilder create_table();
354
    
451

  
355 452
    public CreateIndexBuilder create_index();
356 453

  
357 454
    public GrantBuilder grant();
......
361 458
    public UpdateTableStatisticsBuilder update_table_statistics();
362 459

  
363 460
    public CountBuilder count();
364
    
365
    public Function ST_ExtentAggregate(Value geom);
366 461

  
367
    public Function ST_UnionAggregate(Value geom);
462
    public ExpressionBuilder expression();
368 463

  
369
    public Function Find_SRID(Value schema, Value table, Value column);
370
    
371
    
464
    public String as_identifier(String id);
465

  
466
    public String as_string(String s);
467

  
468
    public String as_string(byte[] s);
469

  
470
    public String as_string(boolean value);
471

  
472
    public String as_string(Number value);
473

  
474
    public String as_string(Object value);
475

  
476
    public void setProperties(Class classToApply, Object... values);
477

  
372 478
}

Also available in: Unified diff