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

History | View | Annotate | Download (12.9 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
        /**
243
         * Constructs the SQL statement. If the values associated with the SQL
244
         * statement are not valid an IllegalStateException exception is thrown.
245
         *
246
         * @return the SQL select statement.
247
         * @throws IllegalStateException if the values of select statement are
248
         * not valids.
249
         */
250
        @Override
251
        public String toString();
252

    
253
    }
254

    
255
    public interface UpdateBuilder extends Statement {
256

    
257
        public TableNameBuilder table();
258

    
259
        public UpdateColumnBuilder column();
260

    
261
        public GeometryExpressionBuilder where();
262

    
263
        public boolean has_where();
264
    }
265

    
266
    public interface InsertBuilder extends Statement {
267

    
268
        public TableNameBuilder table();
269

    
270
        public InsertColumnBuilder column();
271
    }
272

    
273
    public interface DeleteBuilder extends Statement {
274

    
275
        public TableNameBuilder table();
276

    
277
        public GeometryExpressionBuilder where();
278

    
279
        public boolean has_where();
280
    }
281

    
282
    public interface AlterTableBuilder extends Statement {
283

    
284
        public TableNameBuilder table();
285

    
286
        public AlterTableBuilder drop_column(String columnName);
287

    
288
        public AlterTableBuilder add_column(FeatureAttributeDescriptor fad);
289

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

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

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

    
296
        public AlterTableBuilder alter_column(FeatureAttributeDescriptor fad);
297

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

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

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

    
304
        public AlterTableBuilder rename_column(String source, String target);
305

    
306
        public boolean isEmpty();
307

    
308
        public List<String> toStrings();
309

    
310
        public List<String> toStrings(Formatter formatter);
311
    }
312

    
313
    public interface CreateTableBuilder extends Statement {
314

    
315
        public TableNameBuilder table();
316

    
317
        public CreateTableBuilder add_column(FeatureAttributeDescriptor fad);
318

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

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

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

    
325
        public ColumnDescriptor getColumnDescriptor(String columnName);
326

    
327
        public List<String> toStrings();
328

    
329
        public List<String> toStrings(Formatter formatter);
330
    }
331

    
332
    public interface UpdateTableStatisticsBuilder extends Statement {
333

    
334
        public TableNameBuilder table();
335

    
336
        public List<String> toStrings();
337

    
338
        public List<String> toStrings(Formatter formatter);
339
    }
340

    
341
    public interface GrantRoleBuilder extends StatementPart {
342

    
343
        public GrantRoleBuilder privilege(Privilege privilege);
344

    
345
        public GrantRoleBuilder select();
346

    
347
        public GrantRoleBuilder insert();
348

    
349
        public GrantRoleBuilder delete();
350

    
351
        public GrantRoleBuilder truncate();
352

    
353
        public GrantRoleBuilder reference();
354

    
355
        public GrantRoleBuilder update();
356

    
357
        public GrantRoleBuilder trigger();
358

    
359
        public GrantRoleBuilder all();
360
    }
361

    
362
    public interface GrantBuilder extends Statement {
363

    
364
        public TableNameBuilder table();
365

    
366
        public GrantRoleBuilder role(String name);
367

    
368
        public List<String> toStrings();
369

    
370
        public List<String> toStrings(Formatter formatter);
371
    }
372

    
373
    public interface DropTableBuilder extends Statement {
374

    
375
        public TableNameBuilder table();
376

    
377
        public List<String> toStrings();
378

    
379
        public List<String> toStrings(Formatter formatter);
380
    }
381

    
382
    public interface CreateIndexBuilder extends Statement {
383

    
384
        public CreateIndexBuilder if_not_exist();
385

    
386
        public CreateIndexBuilder unique();
387

    
388
        public CreateIndexBuilder name(String name);
389

    
390
        public CreateIndexBuilder spatial();
391

    
392
        public CreateIndexBuilder column(String name);
393

    
394
        public TableNameBuilder table();
395

    
396
        public List<String> toStrings();
397

    
398
        public List<String> toStrings(Formatter formatter);
399
    }
400

    
401
    public String default_schema();
402

    
403
    public boolean support_schemas();
404

    
405
    public boolean has_spatial_functions();
406

    
407
    public GeometrySupportType geometry_support_type();
408

    
409
    public String sqltype(int dataType, int size, int precision, int scale, int geomType, int geomSubtype);
410

    
411
    public Object sqlgeometrytype(int type, int subtype);
412

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

    
415
    public Object srs_id(IProjection projection);
416

    
417
    public String toString(Formatter formatter);
418

    
419
    public List<Variable> variables();
420

    
421
    public List<String> variables_names();
422

    
423
    public List<Parameter> parameters();
424

    
425
    public List<String> parameters_names();
426

    
427
    public TableNameBuilder table_name();
428

    
429
    public TableNameBuilder createTableNameBuilder();
430

    
431
    public SelectBuilder select();
432

    
433
    public UpdateBuilder update();
434

    
435
    public InsertBuilder insert();
436

    
437
    public DeleteBuilder delete();
438

    
439
    public AlterTableBuilder alter_table();
440

    
441
    public CreateTableBuilder create_table();
442

    
443
    public CreateIndexBuilder create_index();
444

    
445
    public GrantBuilder grant();
446

    
447
    public DropTableBuilder drop_table();
448

    
449
    public UpdateTableStatisticsBuilder update_table_statistics();
450

    
451
    public CountBuilder count();
452

    
453
    public GeometryExpressionBuilder expression();
454

    
455
    public String as_identifier(String id);
456

    
457
    public String as_string(String s);
458

    
459
    public String as_string(byte[] s);
460

    
461
    public String as_string(boolean value);
462

    
463
    public String as_string(Number value);
464

    
465
    public String as_string(Object value);
466
    
467
    public Column column(String name);
468

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

    
473
}