Statistics
| Revision:

svn-gvsig-desktop / 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 @ 45162

History | View | Annotate | Download (13.2 KB)

1
package org.gvsig.fmap.dal;
2

    
3
import java.util.List;
4
import org.cresques.cts.IProjection;
5
import org.gvsig.expressionevaluator.ExpressionBuilder.Parameter;
6
import org.gvsig.expressionevaluator.ExpressionBuilder.Value;
7
import org.gvsig.expressionevaluator.ExpressionBuilder.Variable;
8
import org.gvsig.expressionevaluator.Formatter;
9
import org.gvsig.expressionevaluator.GeometryExpressionBuilder;
10
import org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometrySupportType;
11
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
12
import org.gvsig.fmap.geom.Geometry;
13

    
14
public interface SQLBuilder {
15

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

    
18
    public enum Privilege {
19
        SELECT,
20
        INSERT,
21
        UPDATE,
22
        DELETE,
23
        TRUNCATE,
24
        REFERENCE,
25
        TRIGGER,
26
        ALL
27
    };
28

    
29
    public interface ColumnDescriptor {
30

    
31
        public String getName();
32

    
33
        public int getType();
34

    
35
        public int getSize();
36

    
37
        public int getPrecision();
38

    
39
        public int getScale();
40

    
41
        public boolean isPrimaryKey();
42

    
43
        public boolean isIndexed();
44

    
45
        public boolean isAutomatic();
46

    
47
        boolean allowNulls();
48

    
49
        public Object getDefaultValue();
50

    
51
        public int getGeometryType();
52

    
53
        public int getGeometrySubtype();
54

    
55
        public Object getGeometrySRSId();
56

    
57
        public boolean isGeometry();
58

    
59
        public DataStoreParameters getStoreParameters();
60

    
61
        public void setName(String name);
62

    
63
        public void setType(int type);
64

    
65
        public void setSize(int size);
66

    
67
        public void setPrecision(int precision);
68

    
69
        public void setScale(int scale);
70

    
71
        public void setIsPrimaryKey(boolean isPk);
72

    
73
        public void setIsAutomatic(boolean isAutomatic);
74

    
75
        public void setAllowNulls(boolean allowNulls);
76

    
77
        public void setDefaultValue(Object defaultValue);
78

    
79
        public void setGeometryType(int geom_type);
80

    
81
        public void setGeometrySubtype(int geom_subtype);
82

    
83
        public void setGeometrySRSId(Object geom_srsid);
84
    }
85

    
86
    public interface StatementPart extends Value {
87

    
88
    }
89

    
90
    public interface Statement extends StatementPart {
91

    
92
    }
93
    
94
    public interface Column extends Variable {
95
        public TableNameBuilder table();
96
        public TableNameBuilder table(TableNameBuilder table);
97
    }
98

    
99
    public interface TableNameBuilder extends StatementPart {
100

    
101
        public TableNameBuilder database(String name);
102

    
103
        public TableNameBuilder schema(String name);
104

    
105
        public TableNameBuilder name(String name);
106

    
107
        public String getDatabase();
108

    
109
        public String getSchema();
110

    
111
        public String getName();
112

    
113
        public boolean has_database();
114

    
115
        public boolean has_schema();
116
    }
117

    
118
    public interface CountBuilder extends StatementPart {
119

    
120
        public CountBuilder all();
121

    
122
        public CountBuilder column(Value value);
123

    
124
        public CountBuilder distinct();
125
    }
126

    
127
    public interface SelectColumnBuilder extends StatementPart {
128

    
129
        public SelectColumnBuilder name(String name);
130

    
131
        public SelectColumnBuilder name(TableNameBuilder table, String name);
132

    
133
        public SelectColumnBuilder value(Value value);
134

    
135
        public SelectColumnBuilder as(String alias);
136

    
137
        public SelectColumnBuilder as_geometry();
138

    
139
        public SelectColumnBuilder all();
140

    
141
        public String getName();
142

    
143
        public String getAlias();
144

    
145
        public String getValue();
146
        
147
        public boolean isGeometry();
148
        
149
        public TableNameBuilder getTable();
150
    }
151

    
152
    public interface InsertColumnBuilder extends StatementPart {
153

    
154
        public InsertColumnBuilder name(String name);
155

    
156
        public InsertColumnBuilder with_value(Value value);
157

    
158
        public String getName();
159

    
160
        public Value getValue();
161
    }
162

    
163
    public interface UpdateColumnBuilder extends InsertColumnBuilder {
164

    
165
        @Override
166
        public UpdateColumnBuilder name(String name);
167

    
168
        @Override
169
        public UpdateColumnBuilder with_value(Value value);
170

    
171
        @Override
172
        public String getName();
173

    
174
        @Override
175
        public Value getValue();
176
    }
177

    
178
    public interface FromBuilder extends StatementPart {
179

    
180
        public TableNameBuilder table();
181

    
182
        public FromBuilder subquery(String subquery);
183

    
184
        public FromBuilder custom(String passthrough);
185
        
186
        public FromBuilder left_join(TableNameBuilder table, Value expression);
187
    }
188

    
189
    public interface OrderByBuilder extends StatementPart {
190

    
191
        public OrderByBuilder column(String name);
192
        
193
        public OrderByBuilder column(Value name);
194

    
195
        public OrderByBuilder ascending(boolean asc);
196

    
197
        public OrderByBuilder ascending();
198

    
199
        public OrderByBuilder descending();
200

    
201
        public OrderByBuilder custom(String order);
202
    }
203

    
204
    public interface SelectBuilder extends Statement {
205

    
206
        public SelectColumnBuilder column();
207
        
208
        public SelectBuilder remove_all_columns();
209

    
210
        public FromBuilder from();
211

    
212
        public GeometryExpressionBuilder where();
213

    
214
        public OrderByBuilder order_by();
215

    
216
        public SelectBuilder group_by(Value... column);
217

    
218
        public SelectBuilder distinct();
219

    
220
        public SelectBuilder limit(long limit);
221

    
222
        public SelectBuilder limit(Long limit);
223

    
224
        /**
225
         * Specifies an offset to be applied to the SQL statement. Only an
226
         * offset can be applied if an order has been specified. Otherwise an
227
         * IllegalStateException exception will be thrown when constructing the
228
         * SQL statement invoking the toString method.
229
         *
230
         * @param offset
231
         * @return this SelectBuilder
232
         */
233
        public SelectBuilder offset(long offset);
234

    
235
        public boolean has_column(String name);
236

    
237
        public boolean has_where();
238

    
239
        public boolean has_from();
240

    
241
        public boolean has_order_by();
242

    
243
        public boolean has_group_by();
244

    
245
        public boolean has_limit();
246

    
247
        public boolean has_offset();
248
        
249
        public void disable_check_order_and_offset();
250

    
251
        /**
252
         * Constructs the SQL statement. If the values associated with the SQL
253
         * statement are not valid an IllegalStateException exception is thrown.
254
         *
255
         * @return the SQL select statement.
256
         * @throws IllegalStateException if the values of select statement are
257
         * not valids.
258
         */
259
        @Override
260
        public String toString();
261
        
262
        public List<Value> getGroups();
263

    
264
    }
265

    
266
    public interface UpdateBuilder extends Statement {
267

    
268
        public TableNameBuilder table();
269

    
270
        public UpdateColumnBuilder column();
271

    
272
        public GeometryExpressionBuilder where();
273

    
274
        public boolean has_where();
275
    }
276

    
277
    public interface InsertBuilder extends Statement {
278

    
279
        public TableNameBuilder table();
280

    
281
        public InsertColumnBuilder column();
282
    }
283

    
284
    public interface DeleteBuilder extends Statement {
285

    
286
        public TableNameBuilder table();
287

    
288
        public GeometryExpressionBuilder where();
289

    
290
        public boolean has_where();
291
    }
292

    
293
    public interface AlterTableBuilder extends Statement {
294

    
295
        public TableNameBuilder table();
296

    
297
        public AlterTableBuilder drop_column(String columnName);
298

    
299
        public AlterTableBuilder add_column(FeatureAttributeDescriptor fad);
300

    
301
        public AlterTableBuilder add_column(String columnName, int type, int size, int precision, int scale, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue);
302

    
303
        public AlterTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls);
304

    
305
        public AlterTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, Object srsdbcode, boolean isIndexed, boolean allowNulls);
306

    
307
        public AlterTableBuilder alter_column(FeatureAttributeDescriptor fad);
308

    
309
        public AlterTableBuilder alter_column(String columnName, int type, int size, int precision, int scale, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue);
310

    
311
        public AlterTableBuilder alter_geometry_column(String columnName, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls);
312

    
313
        public AlterTableBuilder alter_geometry_column(String columnName, int geom_type, int geom_subtype, Object srsdbcode, boolean isIndexed, boolean allowNulls);
314

    
315
        public AlterTableBuilder rename_column(String source, String target);
316

    
317
        public boolean isEmpty();
318

    
319
        public List<String> toStrings();
320

    
321
        public List<String> toStrings(Formatter formatter);
322
    }
323

    
324
    public interface CreateTableBuilder extends Statement {
325

    
326
        public TableNameBuilder table();
327

    
328
        public CreateTableBuilder add_column(FeatureAttributeDescriptor fad);
329

    
330
        public CreateTableBuilder add_column(String columnName, int type, int size, int precision, int scale, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue);
331

    
332
        public CreateTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls);
333

    
334
        public CreateTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, Object srsdbcode, boolean isIndexed, boolean allowNulls);
335

    
336
        public ColumnDescriptor getColumnDescriptor(String columnName);
337

    
338
        public List<String> toStrings();
339

    
340
        public List<String> toStrings(Formatter formatter);
341
    }
342

    
343
    public interface UpdateTableStatisticsBuilder extends Statement {
344

    
345
        public TableNameBuilder table();
346

    
347
        public List<String> toStrings();
348

    
349
        public List<String> toStrings(Formatter formatter);
350
    }
351

    
352
    public interface GrantRoleBuilder extends StatementPart {
353

    
354
        public GrantRoleBuilder privilege(Privilege privilege);
355

    
356
        public GrantRoleBuilder select();
357

    
358
        public GrantRoleBuilder insert();
359

    
360
        public GrantRoleBuilder delete();
361

    
362
        public GrantRoleBuilder truncate();
363

    
364
        public GrantRoleBuilder reference();
365

    
366
        public GrantRoleBuilder update();
367

    
368
        public GrantRoleBuilder trigger();
369

    
370
        public GrantRoleBuilder all();
371
    }
372

    
373
    public interface GrantBuilder extends Statement {
374

    
375
        public TableNameBuilder table();
376

    
377
        public GrantRoleBuilder role(String name);
378

    
379
        public List<String> toStrings();
380

    
381
        public List<String> toStrings(Formatter formatter);
382
    }
383

    
384
    public interface DropTableBuilder extends Statement {
385

    
386
        public TableNameBuilder table();
387

    
388
        public List<String> toStrings();
389

    
390
        public List<String> toStrings(Formatter formatter);
391
    }
392

    
393
    public interface CreateIndexBuilder extends Statement {
394

    
395
        public CreateIndexBuilder if_not_exist();
396

    
397
        public CreateIndexBuilder unique();
398

    
399
        public CreateIndexBuilder name(String name);
400

    
401
        public CreateIndexBuilder spatial();
402

    
403
        public CreateIndexBuilder column(String name);
404

    
405
        public TableNameBuilder table();
406

    
407
        public List<String> toStrings();
408

    
409
        public List<String> toStrings(Formatter formatter);
410
    }
411

    
412
    public String default_schema();
413

    
414
    public boolean support_schemas();
415

    
416
    public boolean has_spatial_functions();
417

    
418
    public GeometrySupportType geometry_support_type();
419

    
420
    public String sqltype(int dataType, int size, int precision, int scale, int geomType, int geomSubtype);
421

    
422
    public Object sqlgeometrytype(int type, int subtype);
423

    
424
    public Object sqlgeometrydimension(int type, int subtype);
425

    
426
    public Object srs_id(IProjection projection);
427

    
428
    public String toString(Formatter formatter);
429

    
430
    public List<Variable> variables();
431

    
432
    public List<String> variables_names();
433

    
434
    public List<Parameter> parameters();
435

    
436
    public List<String> parameters_names();
437

    
438
    public TableNameBuilder table_name();
439

    
440
    public TableNameBuilder createTableNameBuilder();
441

    
442
    public SelectBuilder select();
443

    
444
    public UpdateBuilder update();
445

    
446
    public InsertBuilder insert();
447

    
448
    public DeleteBuilder delete();
449

    
450
    public AlterTableBuilder alter_table();
451

    
452
    public CreateTableBuilder create_table();
453

    
454
    public CreateIndexBuilder create_index();
455

    
456
    public GrantBuilder grant();
457

    
458
    public DropTableBuilder drop_table();
459

    
460
    public UpdateTableStatisticsBuilder update_table_statistics();
461

    
462
    public CountBuilder count();
463

    
464
    public GeometryExpressionBuilder expression();
465

    
466
    public String as_identifier(String id);
467

    
468
    public String as_string(String s);
469

    
470
    public String as_string(byte[] s);
471

    
472
    public String as_string(boolean value);
473

    
474
    public String as_string(Number value);
475

    
476
    public String as_string(Object value);
477
    
478
    public Column column(String name);
479

    
480
    public Column column(TableNameBuilder table, String name);
481
    
482
    public void setProperties(Class classToApply, Object... values);
483

    
484
}