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

History | View | Annotate | Download (13 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

    
13
public interface SQLBuilder {
14

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

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

    
28
    public interface ColumnDescriptor {
29

    
30
        public String getName();
31

    
32
        public int getType();
33

    
34
        public int getSize();
35

    
36
        public int getPrecision();
37

    
38
        public int getScale();
39

    
40
        public boolean isPrimaryKey();
41

    
42
        public boolean isIndexed();
43

    
44
        public boolean isAutomatic();
45

    
46
        boolean allowNulls();
47

    
48
        public Object getDefaultValue();
49

    
50
        public int getGeometryType();
51

    
52
        public int getGeometrySubtype();
53

    
54
        public Object getGeometrySRSId();
55

    
56
        public boolean isGeometry();
57

    
58
        public DataStoreParameters getStoreParameters();
59

    
60
        public void setName(String name);
61

    
62
        public void setType(int type);
63

    
64
        public void setSize(int size);
65

    
66
        public void setPrecision(int precision);
67

    
68
        public void setScale(int scale);
69

    
70
        public void setIsPrimaryKey(boolean isPk);
71

    
72
        public void setIsAutomatic(boolean isAutomatic);
73

    
74
        public void setAllowNulls(boolean allowNulls);
75

    
76
        public void setDefaultValue(Object defaultValue);
77

    
78
        public void setGeometryType(int geom_type);
79

    
80
        public void setGeometrySubtype(int geom_subtype);
81

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

    
85
    public interface StatementPart extends Value {
86

    
87
    }
88

    
89
    public interface Statement extends StatementPart {
90

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

    
98
    public interface TableNameBuilder extends StatementPart {
99

    
100
        public TableNameBuilder database(String name);
101

    
102
        public TableNameBuilder schema(String name);
103

    
104
        public TableNameBuilder name(String name);
105

    
106
        public String getDatabase();
107

    
108
        public String getSchema();
109

    
110
        public String getName();
111

    
112
        public boolean has_database();
113

    
114
        public boolean has_schema();
115
    }
116

    
117
    public interface CountBuilder extends StatementPart {
118

    
119
        public CountBuilder all();
120

    
121
        public CountBuilder column(Value value);
122

    
123
        public CountBuilder distinct();
124
    }
125

    
126
    public interface SelectColumnBuilder extends StatementPart {
127

    
128
        public SelectColumnBuilder name(String name);
129

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

    
132
        public SelectColumnBuilder value(Value value);
133

    
134
        public SelectColumnBuilder as(String alias);
135

    
136
        public SelectColumnBuilder as_geometry();
137

    
138
        public SelectColumnBuilder all();
139

    
140
        public String getName();
141

    
142
        public String getAlias();
143

    
144
        public String getValue();
145
    }
146

    
147
    public interface InsertColumnBuilder extends StatementPart {
148

    
149
        public InsertColumnBuilder name(String name);
150

    
151
        public InsertColumnBuilder with_value(Value value);
152

    
153
        public String getName();
154

    
155
        public Value getValue();
156
    }
157

    
158
    public interface UpdateColumnBuilder extends InsertColumnBuilder {
159

    
160
        @Override
161
        public UpdateColumnBuilder name(String name);
162

    
163
        @Override
164
        public UpdateColumnBuilder with_value(Value value);
165

    
166
        @Override
167
        public String getName();
168

    
169
        @Override
170
        public Value getValue();
171
    }
172

    
173
    public interface FromBuilder extends StatementPart {
174

    
175
        public TableNameBuilder table();
176

    
177
        public FromBuilder subquery(String subquery);
178

    
179
        public FromBuilder custom(String passthrough);
180
        
181
        public FromBuilder left_join(TableNameBuilder table, Value expression);
182
    }
183

    
184
    public interface OrderByBuilder extends StatementPart {
185

    
186
        public OrderByBuilder column(String name);
187

    
188
        public OrderByBuilder ascending(boolean asc);
189

    
190
        public OrderByBuilder ascending();
191

    
192
        public OrderByBuilder descending();
193

    
194
        public OrderByBuilder custom(String order);
195
    }
196

    
197
    public interface SelectBuilder extends Statement {
198

    
199
        public SelectColumnBuilder column();
200
        
201
        public SelectBuilder remove_all_columns();
202

    
203
        public FromBuilder from();
204

    
205
        public GeometryExpressionBuilder where();
206

    
207
        public OrderByBuilder order_by();
208

    
209
        public SelectBuilder group_by(Variable... column);
210

    
211
        public SelectBuilder distinct();
212

    
213
        public SelectBuilder limit(long limit);
214

    
215
        public SelectBuilder limit(Long limit);
216

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

    
228
        public boolean has_column(String name);
229

    
230
        public boolean has_where();
231

    
232
        public boolean has_from();
233

    
234
        public boolean has_order_by();
235

    
236
        public boolean has_group_by();
237

    
238
        public boolean has_limit();
239

    
240
        public boolean has_offset();
241
        
242
        public void disable_check_order_and_offset();
243

    
244
        /**
245
         * Constructs the SQL statement. If the values associated with the SQL
246
         * statement are not valid an IllegalStateException exception is thrown.
247
         *
248
         * @return the SQL select statement.
249
         * @throws IllegalStateException if the values of select statement are
250
         * not valids.
251
         */
252
        @Override
253
        public String toString();
254

    
255
    }
256

    
257
    public interface UpdateBuilder extends Statement {
258

    
259
        public TableNameBuilder table();
260

    
261
        public UpdateColumnBuilder column();
262

    
263
        public GeometryExpressionBuilder where();
264

    
265
        public boolean has_where();
266
    }
267

    
268
    public interface InsertBuilder extends Statement {
269

    
270
        public TableNameBuilder table();
271

    
272
        public InsertColumnBuilder column();
273
    }
274

    
275
    public interface DeleteBuilder extends Statement {
276

    
277
        public TableNameBuilder table();
278

    
279
        public GeometryExpressionBuilder where();
280

    
281
        public boolean has_where();
282
    }
283

    
284
    public interface AlterTableBuilder extends Statement {
285

    
286
        public TableNameBuilder table();
287

    
288
        public AlterTableBuilder drop_column(String columnName);
289

    
290
        public AlterTableBuilder add_column(FeatureAttributeDescriptor fad);
291

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

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

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

    
298
        public AlterTableBuilder alter_column(FeatureAttributeDescriptor fad);
299

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

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

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

    
306
        public AlterTableBuilder rename_column(String source, String target);
307

    
308
        public boolean isEmpty();
309

    
310
        public List<String> toStrings();
311

    
312
        public List<String> toStrings(Formatter formatter);
313
    }
314

    
315
    public interface CreateTableBuilder extends Statement {
316

    
317
        public TableNameBuilder table();
318

    
319
        public CreateTableBuilder add_column(FeatureAttributeDescriptor fad);
320

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

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

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

    
327
        public ColumnDescriptor getColumnDescriptor(String columnName);
328

    
329
        public List<String> toStrings();
330

    
331
        public List<String> toStrings(Formatter formatter);
332
    }
333

    
334
    public interface UpdateTableStatisticsBuilder extends Statement {
335

    
336
        public TableNameBuilder table();
337

    
338
        public List<String> toStrings();
339

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

    
343
    public interface GrantRoleBuilder extends StatementPart {
344

    
345
        public GrantRoleBuilder privilege(Privilege privilege);
346

    
347
        public GrantRoleBuilder select();
348

    
349
        public GrantRoleBuilder insert();
350

    
351
        public GrantRoleBuilder delete();
352

    
353
        public GrantRoleBuilder truncate();
354

    
355
        public GrantRoleBuilder reference();
356

    
357
        public GrantRoleBuilder update();
358

    
359
        public GrantRoleBuilder trigger();
360

    
361
        public GrantRoleBuilder all();
362
    }
363

    
364
    public interface GrantBuilder extends Statement {
365

    
366
        public TableNameBuilder table();
367

    
368
        public GrantRoleBuilder role(String name);
369

    
370
        public List<String> toStrings();
371

    
372
        public List<String> toStrings(Formatter formatter);
373
    }
374

    
375
    public interface DropTableBuilder extends Statement {
376

    
377
        public TableNameBuilder table();
378

    
379
        public List<String> toStrings();
380

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

    
384
    public interface CreateIndexBuilder extends Statement {
385

    
386
        public CreateIndexBuilder if_not_exist();
387

    
388
        public CreateIndexBuilder unique();
389

    
390
        public CreateIndexBuilder name(String name);
391

    
392
        public CreateIndexBuilder spatial();
393

    
394
        public CreateIndexBuilder column(String name);
395

    
396
        public TableNameBuilder table();
397

    
398
        public List<String> toStrings();
399

    
400
        public List<String> toStrings(Formatter formatter);
401
    }
402

    
403
    public String default_schema();
404

    
405
    public boolean support_schemas();
406

    
407
    public boolean has_spatial_functions();
408

    
409
    public GeometrySupportType geometry_support_type();
410

    
411
    public String sqltype(int dataType, int size, int precision, int scale, int geomType, int geomSubtype);
412

    
413
    public Object sqlgeometrytype(int type, int subtype);
414

    
415
    public Object sqlgeometrydimension(int type, int subtype);
416

    
417
    public Object srs_id(IProjection projection);
418

    
419
    public String toString(Formatter formatter);
420

    
421
    public List<Variable> variables();
422

    
423
    public List<String> variables_names();
424

    
425
    public List<Parameter> parameters();
426

    
427
    public List<String> parameters_names();
428

    
429
    public TableNameBuilder table_name();
430

    
431
    public TableNameBuilder createTableNameBuilder();
432

    
433
    public SelectBuilder select();
434

    
435
    public UpdateBuilder update();
436

    
437
    public InsertBuilder insert();
438

    
439
    public DeleteBuilder delete();
440

    
441
    public AlterTableBuilder alter_table();
442

    
443
    public CreateTableBuilder create_table();
444

    
445
    public CreateIndexBuilder create_index();
446

    
447
    public GrantBuilder grant();
448

    
449
    public DropTableBuilder drop_table();
450

    
451
    public UpdateTableStatisticsBuilder update_table_statistics();
452

    
453
    public CountBuilder count();
454

    
455
    public GeometryExpressionBuilder expression();
456

    
457
    public String as_identifier(String id);
458

    
459
    public String as_string(String s);
460

    
461
    public String as_string(byte[] s);
462

    
463
    public String as_string(boolean value);
464

    
465
    public String as_string(Number value);
466

    
467
    public String as_string(Object value);
468
    
469
    public Column column(String name);
470

    
471
    public Column column(TableNameBuilder table, String name);
472
    
473
    public void setProperties(Class classToApply, Object... values);
474

    
475
}