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 @ 45008

History | View | Annotate | Download (13.1 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 ascending(boolean asc);
194

    
195
        public OrderByBuilder ascending();
196

    
197
        public OrderByBuilder descending();
198

    
199
        public OrderByBuilder custom(String order);
200
    }
201

    
202
    public interface SelectBuilder extends Statement {
203

    
204
        public SelectColumnBuilder column();
205
        
206
        public SelectBuilder remove_all_columns();
207

    
208
        public FromBuilder from();
209

    
210
        public GeometryExpressionBuilder where();
211

    
212
        public OrderByBuilder order_by();
213

    
214
        public SelectBuilder group_by(Variable... column);
215

    
216
        public SelectBuilder distinct();
217

    
218
        public SelectBuilder limit(long limit);
219

    
220
        public SelectBuilder limit(Long limit);
221

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

    
233
        public boolean has_column(String name);
234

    
235
        public boolean has_where();
236

    
237
        public boolean has_from();
238

    
239
        public boolean has_order_by();
240

    
241
        public boolean has_group_by();
242

    
243
        public boolean has_limit();
244

    
245
        public boolean has_offset();
246
        
247
        public void disable_check_order_and_offset();
248

    
249
        /**
250
         * Constructs the SQL statement. If the values associated with the SQL
251
         * statement are not valid an IllegalStateException exception is thrown.
252
         *
253
         * @return the SQL select statement.
254
         * @throws IllegalStateException if the values of select statement are
255
         * not valids.
256
         */
257
        @Override
258
        public String toString();
259

    
260
    }
261

    
262
    public interface UpdateBuilder extends Statement {
263

    
264
        public TableNameBuilder table();
265

    
266
        public UpdateColumnBuilder column();
267

    
268
        public GeometryExpressionBuilder where();
269

    
270
        public boolean has_where();
271
    }
272

    
273
    public interface InsertBuilder extends Statement {
274

    
275
        public TableNameBuilder table();
276

    
277
        public InsertColumnBuilder column();
278
    }
279

    
280
    public interface DeleteBuilder extends Statement {
281

    
282
        public TableNameBuilder table();
283

    
284
        public GeometryExpressionBuilder where();
285

    
286
        public boolean has_where();
287
    }
288

    
289
    public interface AlterTableBuilder extends Statement {
290

    
291
        public TableNameBuilder table();
292

    
293
        public AlterTableBuilder drop_column(String columnName);
294

    
295
        public AlterTableBuilder add_column(FeatureAttributeDescriptor fad);
296

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

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

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

    
303
        public AlterTableBuilder alter_column(FeatureAttributeDescriptor fad);
304

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

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

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

    
311
        public AlterTableBuilder rename_column(String source, String target);
312

    
313
        public boolean isEmpty();
314

    
315
        public List<String> toStrings();
316

    
317
        public List<String> toStrings(Formatter formatter);
318
    }
319

    
320
    public interface CreateTableBuilder extends Statement {
321

    
322
        public TableNameBuilder table();
323

    
324
        public CreateTableBuilder add_column(FeatureAttributeDescriptor fad);
325

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

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

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

    
332
        public ColumnDescriptor getColumnDescriptor(String columnName);
333

    
334
        public List<String> toStrings();
335

    
336
        public List<String> toStrings(Formatter formatter);
337
    }
338

    
339
    public interface UpdateTableStatisticsBuilder extends Statement {
340

    
341
        public TableNameBuilder table();
342

    
343
        public List<String> toStrings();
344

    
345
        public List<String> toStrings(Formatter formatter);
346
    }
347

    
348
    public interface GrantRoleBuilder extends StatementPart {
349

    
350
        public GrantRoleBuilder privilege(Privilege privilege);
351

    
352
        public GrantRoleBuilder select();
353

    
354
        public GrantRoleBuilder insert();
355

    
356
        public GrantRoleBuilder delete();
357

    
358
        public GrantRoleBuilder truncate();
359

    
360
        public GrantRoleBuilder reference();
361

    
362
        public GrantRoleBuilder update();
363

    
364
        public GrantRoleBuilder trigger();
365

    
366
        public GrantRoleBuilder all();
367
    }
368

    
369
    public interface GrantBuilder extends Statement {
370

    
371
        public TableNameBuilder table();
372

    
373
        public GrantRoleBuilder role(String name);
374

    
375
        public List<String> toStrings();
376

    
377
        public List<String> toStrings(Formatter formatter);
378
    }
379

    
380
    public interface DropTableBuilder extends Statement {
381

    
382
        public TableNameBuilder table();
383

    
384
        public List<String> toStrings();
385

    
386
        public List<String> toStrings(Formatter formatter);
387
    }
388

    
389
    public interface CreateIndexBuilder extends Statement {
390

    
391
        public CreateIndexBuilder if_not_exist();
392

    
393
        public CreateIndexBuilder unique();
394

    
395
        public CreateIndexBuilder name(String name);
396

    
397
        public CreateIndexBuilder spatial();
398

    
399
        public CreateIndexBuilder column(String name);
400

    
401
        public TableNameBuilder table();
402

    
403
        public List<String> toStrings();
404

    
405
        public List<String> toStrings(Formatter formatter);
406
    }
407

    
408
    public String default_schema();
409

    
410
    public boolean support_schemas();
411

    
412
    public boolean has_spatial_functions();
413

    
414
    public GeometrySupportType geometry_support_type();
415

    
416
    public String sqltype(int dataType, int size, int precision, int scale, int geomType, int geomSubtype);
417

    
418
    public Object sqlgeometrytype(int type, int subtype);
419

    
420
    public Object sqlgeometrydimension(int type, int subtype);
421

    
422
    public Object srs_id(IProjection projection);
423

    
424
    public String toString(Formatter formatter);
425

    
426
    public List<Variable> variables();
427

    
428
    public List<String> variables_names();
429

    
430
    public List<Parameter> parameters();
431

    
432
    public List<String> parameters_names();
433

    
434
    public TableNameBuilder table_name();
435

    
436
    public TableNameBuilder createTableNameBuilder();
437

    
438
    public SelectBuilder select();
439

    
440
    public UpdateBuilder update();
441

    
442
    public InsertBuilder insert();
443

    
444
    public DeleteBuilder delete();
445

    
446
    public AlterTableBuilder alter_table();
447

    
448
    public CreateTableBuilder create_table();
449

    
450
    public CreateIndexBuilder create_index();
451

    
452
    public GrantBuilder grant();
453

    
454
    public DropTableBuilder drop_table();
455

    
456
    public UpdateTableStatisticsBuilder update_table_statistics();
457

    
458
    public CountBuilder count();
459

    
460
    public GeometryExpressionBuilder expression();
461

    
462
    public String as_identifier(String id);
463

    
464
    public String as_string(String s);
465

    
466
    public String as_string(byte[] s);
467

    
468
    public String as_string(boolean value);
469

    
470
    public String as_string(Number value);
471

    
472
    public String as_string(Object value);
473
    
474
    public Column column(String name);
475

    
476
    public Column column(TableNameBuilder table, String name);
477
    
478
    public void setProperties(Class classToApply, Object... values);
479

    
480
}