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 @ 46493
History | View | Annotate | Download (15 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 |
import org.gvsig.fmap.geom.primitive.Envelope; |
14 |
|
15 |
public interface SQLBuilder { |
16 |
|
17 |
public static final String FEATURE_ATTRIBUTE_DESCRIPTOR = "FeatureAttributeDescriptor"; |
18 |
|
19 |
public static final int DEFAULT_RECOMENDED_SQL_LENGTH = 2048; |
20 |
|
21 |
public enum Privilege { |
22 |
SELECT, |
23 |
INSERT, |
24 |
UPDATE, |
25 |
DELETE, |
26 |
TRUNCATE, |
27 |
REFERENCE, |
28 |
TRIGGER, |
29 |
ALL |
30 |
}; |
31 |
|
32 |
public interface ColumnDescriptor { |
33 |
|
34 |
public String getName(); |
35 |
|
36 |
public int getType(); |
37 |
|
38 |
public int getSize(); |
39 |
|
40 |
public int getPrecision(); |
41 |
|
42 |
public int getScale(); |
43 |
|
44 |
public boolean isPrimaryKey(); |
45 |
|
46 |
public boolean isIndexed(); |
47 |
|
48 |
public boolean isAutomatic(); |
49 |
|
50 |
boolean allowNulls();
|
51 |
|
52 |
public Object getDefaultValue(); |
53 |
|
54 |
public int getGeometryType(); |
55 |
|
56 |
public int getGeometrySubtype(); |
57 |
|
58 |
public Object getGeometrySRSId(); |
59 |
|
60 |
public boolean isGeometry(); |
61 |
|
62 |
public DataStoreParameters getStoreParameters();
|
63 |
|
64 |
public void setName(String name); |
65 |
|
66 |
public void setType(int type); |
67 |
|
68 |
public void setSize(int size); |
69 |
|
70 |
public void setPrecision(int precision); |
71 |
|
72 |
public void setScale(int scale); |
73 |
|
74 |
public void setIsPrimaryKey(boolean isPk); |
75 |
|
76 |
public void setIsAutomatic(boolean isAutomatic); |
77 |
|
78 |
public void setAllowNulls(boolean allowNulls); |
79 |
|
80 |
public void setDefaultValue(Object defaultValue); |
81 |
|
82 |
public void setGeometryType(int geom_type); |
83 |
|
84 |
public void setGeometrySubtype(int geom_subtype); |
85 |
|
86 |
public void setGeometrySRSId(Object geom_srsid); |
87 |
|
88 |
public Envelope getTableBBox();
|
89 |
|
90 |
public void setTableBBox(Envelope bbox); |
91 |
} |
92 |
|
93 |
public interface StatementPart extends Value { |
94 |
|
95 |
} |
96 |
|
97 |
public interface Statement extends StatementPart { |
98 |
|
99 |
} |
100 |
|
101 |
public interface Column extends Variable { |
102 |
public TableNameBuilder table();
|
103 |
public TableNameBuilder table(TableNameBuilder table);
|
104 |
} |
105 |
|
106 |
public interface TableNameBuilder extends StatementPart { |
107 |
|
108 |
public TableNameBuilder database(String name); |
109 |
|
110 |
public TableNameBuilder schema(String name); |
111 |
|
112 |
public TableNameBuilder name(String name); |
113 |
|
114 |
public String getDatabase(); |
115 |
|
116 |
public String getSchema(); |
117 |
|
118 |
public String getName(); |
119 |
|
120 |
public boolean has_database(); |
121 |
|
122 |
public boolean has_schema(); |
123 |
} |
124 |
|
125 |
public interface CountBuilder extends StatementPart { |
126 |
|
127 |
public CountBuilder all();
|
128 |
|
129 |
public CountBuilder column(Value value);
|
130 |
|
131 |
public CountBuilder distinct();
|
132 |
} |
133 |
|
134 |
public interface SelectColumnBuilder extends StatementPart { |
135 |
|
136 |
public SelectColumnBuilder name(String name); |
137 |
|
138 |
public SelectColumnBuilder name(TableNameBuilder table, String name); |
139 |
|
140 |
public SelectColumnBuilder value(Value value);
|
141 |
|
142 |
public SelectColumnBuilder as(String alias); |
143 |
|
144 |
public SelectColumnBuilder as_geometry();
|
145 |
|
146 |
public SelectColumnBuilder all();
|
147 |
|
148 |
public String getName(); |
149 |
|
150 |
public String getAlias(); |
151 |
|
152 |
public String getValue(); |
153 |
|
154 |
public boolean isGeometry(); |
155 |
|
156 |
public TableNameBuilder getTable();
|
157 |
|
158 |
public boolean isAggregateFunction(); |
159 |
} |
160 |
|
161 |
public interface InsertColumnBuilder extends StatementPart { |
162 |
|
163 |
public InsertColumnBuilder name(String name); |
164 |
|
165 |
public InsertColumnBuilder with_value(Value value);
|
166 |
|
167 |
public String getName(); |
168 |
|
169 |
public Value getValue();
|
170 |
} |
171 |
|
172 |
public interface UpdateColumnBuilder extends InsertColumnBuilder { |
173 |
|
174 |
@Override
|
175 |
public UpdateColumnBuilder name(String name); |
176 |
|
177 |
@Override
|
178 |
public UpdateColumnBuilder with_value(Value value);
|
179 |
|
180 |
@Override
|
181 |
public String getName(); |
182 |
|
183 |
@Override
|
184 |
public Value getValue();
|
185 |
} |
186 |
|
187 |
public interface FromBuilder extends StatementPart { |
188 |
|
189 |
public TableNameBuilder table();
|
190 |
|
191 |
public FromBuilder subquery(String subquery); |
192 |
|
193 |
public FromBuilder custom(String passthrough); |
194 |
|
195 |
public FromBuilder left_join(TableNameBuilder table, Value expression);
|
196 |
} |
197 |
|
198 |
public interface OrderByBuilder extends StatementPart { |
199 |
|
200 |
public static int MODE_NULLS_FIRST = 0; |
201 |
public static int MODE_NULLS_LAST = 1; |
202 |
public static int MODE_NULLS_NOT_SPECIFIED = 2; |
203 |
|
204 |
public OrderByBuilder column(String name); |
205 |
|
206 |
public boolean isColumn(String name); |
207 |
|
208 |
public boolean isColumn(Value value); |
209 |
|
210 |
// @Deprecated
|
211 |
// public OrderByBuilder column(Value name);
|
212 |
|
213 |
public OrderByBuilder value(Value expression);
|
214 |
|
215 |
public OrderByBuilder ascending(boolean asc); |
216 |
|
217 |
public OrderByBuilder ascending();
|
218 |
|
219 |
public OrderByBuilder descending();
|
220 |
|
221 |
public OrderByBuilder nulls(int mode); |
222 |
|
223 |
public OrderByBuilder custom(String order); |
224 |
|
225 |
public int getNullsMode(); |
226 |
} |
227 |
|
228 |
public interface SelectBuilder extends Statement { |
229 |
|
230 |
public SelectColumnBuilder column();
|
231 |
|
232 |
public SelectBuilder remove_all_columns();
|
233 |
|
234 |
public FromBuilder from();
|
235 |
|
236 |
public GeometryExpressionBuilder where();
|
237 |
|
238 |
public OrderByBuilder order_by();
|
239 |
|
240 |
public OrderByBuilder getOrderBy(String column); |
241 |
|
242 |
public OrderByBuilder getOrderBy(Value column);
|
243 |
|
244 |
public SelectBuilder group_by(Value... column);
|
245 |
|
246 |
public SelectBuilder distinct();
|
247 |
|
248 |
public SelectBuilder limit(long limit); |
249 |
|
250 |
public SelectBuilder limit(Long limit); |
251 |
|
252 |
/**
|
253 |
* Specifies an offset to be applied to the SQL statement. Only an
|
254 |
* offset can be applied if an order has been specified. Otherwise an
|
255 |
* IllegalStateException exception will be thrown when constructing the
|
256 |
* SQL statement invoking the toString method.
|
257 |
*
|
258 |
* @param offset
|
259 |
* @return this SelectBuilder
|
260 |
*/
|
261 |
public SelectBuilder offset(long offset); |
262 |
|
263 |
public boolean has_column(String name); |
264 |
|
265 |
public boolean has_where(); |
266 |
|
267 |
public boolean has_from(); |
268 |
|
269 |
public boolean has_order_by(); |
270 |
|
271 |
public boolean has_group_by(); |
272 |
|
273 |
public boolean has_aggregate_functions(); |
274 |
|
275 |
public boolean has_limit(); |
276 |
|
277 |
public boolean has_offset(); |
278 |
|
279 |
public void disable_check_order_and_offset(); |
280 |
|
281 |
/**
|
282 |
* Constructs the SQL statement. If the values associated with the SQL
|
283 |
* statement are not valid an IllegalStateException exception is thrown.
|
284 |
*
|
285 |
* @return the SQL select statement.
|
286 |
* @throws IllegalStateException if the values of select statement are
|
287 |
* not valids.
|
288 |
*/
|
289 |
@Override
|
290 |
public String toString(); |
291 |
|
292 |
public List<Value> getGroups(); |
293 |
|
294 |
public List<SelectColumnBuilder> getColumns(); |
295 |
|
296 |
public void remove_column(String columnName); |
297 |
|
298 |
} |
299 |
|
300 |
public interface UpdateBuilder extends Statement { |
301 |
|
302 |
public TableNameBuilder table();
|
303 |
|
304 |
public UpdateColumnBuilder column();
|
305 |
|
306 |
public GeometryExpressionBuilder where();
|
307 |
|
308 |
public boolean has_where(); |
309 |
} |
310 |
|
311 |
public interface InsertBuilder extends Statement { |
312 |
|
313 |
public TableNameBuilder table();
|
314 |
|
315 |
public InsertColumnBuilder column();
|
316 |
} |
317 |
|
318 |
public interface DeleteBuilder extends Statement { |
319 |
|
320 |
public TableNameBuilder table();
|
321 |
|
322 |
public GeometryExpressionBuilder where();
|
323 |
|
324 |
public boolean has_where(); |
325 |
} |
326 |
|
327 |
public interface AlterTableBuilder extends Statement { |
328 |
|
329 |
public TableNameBuilder table();
|
330 |
|
331 |
public AlterTableBuilder drop_column(String columnName); |
332 |
|
333 |
public AlterTableBuilder drop_primary_key(String columnName); |
334 |
|
335 |
public AlterTableBuilder add_column(FeatureAttributeDescriptor fad);
|
336 |
|
337 |
public AlterTableBuilder add_column(String columnName, int type, int size, int precision, int scale, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue); |
338 |
|
339 |
public AlterTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls); |
340 |
|
341 |
public AlterTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, Object srsdbcode, boolean isIndexed, boolean allowNulls); |
342 |
|
343 |
public AlterTableBuilder alter_column(FeatureAttributeDescriptor fad);
|
344 |
|
345 |
public AlterTableBuilder alter_column(String columnName, int type, int size, int precision, int scale, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue); |
346 |
|
347 |
public AlterTableBuilder alter_geometry_column(String columnName, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls); |
348 |
|
349 |
public AlterTableBuilder alter_geometry_column(String columnName, int geom_type, int geom_subtype, Object srsdbcode, boolean isIndexed, boolean allowNulls); |
350 |
|
351 |
public AlterTableBuilder rename_column(String source, String target); |
352 |
|
353 |
public boolean isEmpty(); |
354 |
|
355 |
public List<String> toStrings(); |
356 |
|
357 |
public List<String> toStrings(Formatter formatter); |
358 |
} |
359 |
|
360 |
public interface CreateTableBuilder extends Statement { |
361 |
|
362 |
public TableNameBuilder table();
|
363 |
|
364 |
public CreateTableBuilder add_column(FeatureAttributeDescriptor fad);
|
365 |
|
366 |
public CreateTableBuilder add_column(String columnName, int type, int size, int precision, int scale, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue); |
367 |
|
368 |
public CreateTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls); |
369 |
|
370 |
public CreateTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, Object srsdbcode, boolean isIndexed, boolean allowNulls); |
371 |
|
372 |
public ColumnDescriptor getColumnDescriptor(String columnName); |
373 |
|
374 |
public List<String> toStrings(); |
375 |
|
376 |
public List<String> toStrings(Formatter formatter); |
377 |
} |
378 |
|
379 |
public interface UpdateTableStatisticsBuilder extends Statement { |
380 |
|
381 |
public TableNameBuilder table();
|
382 |
|
383 |
public List<String> toStrings(); |
384 |
|
385 |
public List<String> toStrings(Formatter formatter); |
386 |
} |
387 |
|
388 |
public interface GrantRoleBuilder extends StatementPart { |
389 |
|
390 |
public GrantRoleBuilder privilege(Privilege privilege);
|
391 |
|
392 |
public GrantRoleBuilder select();
|
393 |
|
394 |
public GrantRoleBuilder insert();
|
395 |
|
396 |
public GrantRoleBuilder delete();
|
397 |
|
398 |
public GrantRoleBuilder truncate();
|
399 |
|
400 |
public GrantRoleBuilder reference();
|
401 |
|
402 |
public GrantRoleBuilder update();
|
403 |
|
404 |
public GrantRoleBuilder trigger();
|
405 |
|
406 |
public GrantRoleBuilder all();
|
407 |
} |
408 |
|
409 |
public interface GrantBuilder extends Statement { |
410 |
|
411 |
public TableNameBuilder table();
|
412 |
|
413 |
public GrantRoleBuilder role(String name); |
414 |
|
415 |
public List<String> toStrings(); |
416 |
|
417 |
public List<String> toStrings(Formatter formatter); |
418 |
} |
419 |
|
420 |
public interface DropTableBuilder extends Statement { |
421 |
|
422 |
public TableNameBuilder table();
|
423 |
|
424 |
public List<String> toStrings(); |
425 |
|
426 |
public List<String> toStrings(Formatter formatter); |
427 |
} |
428 |
|
429 |
public interface CreateIndexBuilder extends Statement { |
430 |
|
431 |
public CreateIndexBuilder if_not_exist();
|
432 |
|
433 |
public CreateIndexBuilder unique();
|
434 |
|
435 |
public CreateIndexBuilder name(String name); |
436 |
|
437 |
public CreateIndexBuilder name(String tableName, String columnName); |
438 |
|
439 |
public CreateIndexBuilder spatial();
|
440 |
|
441 |
public CreateIndexBuilder column(String name); |
442 |
|
443 |
public TableNameBuilder table();
|
444 |
|
445 |
public List<String> toStrings(); |
446 |
|
447 |
public List<String> toStrings(Formatter formatter); |
448 |
} |
449 |
|
450 |
public interface DropIndexBuilder extends Statement { |
451 |
|
452 |
public DropIndexBuilder if_not_exist();
|
453 |
|
454 |
public DropIndexBuilder name(String name); |
455 |
|
456 |
public DropIndexBuilder name(String tableName, String columnName); |
457 |
|
458 |
public List<String> toStrings(); |
459 |
|
460 |
public List<String> toStrings(Formatter formatter); |
461 |
} |
462 |
|
463 |
public String default_schema(); |
464 |
|
465 |
public boolean support_schemas(); |
466 |
|
467 |
public boolean has_spatial_functions(); |
468 |
|
469 |
public GeometrySupportType geometry_support_type();
|
470 |
|
471 |
public String sqltype(int dataType, int size, int precision, int scale, int geomType, int geomSubtype); |
472 |
|
473 |
public Object sqlgeometrytype(int type, int subtype); |
474 |
|
475 |
public Object sqlgeometrydimension(int type, int subtype); |
476 |
|
477 |
public Object srs_id(IProjection projection); |
478 |
|
479 |
public String toString(Formatter formatter); |
480 |
|
481 |
public List<Variable> variables(); |
482 |
|
483 |
public List<String> variables_names(); |
484 |
|
485 |
public List<Parameter> parameters(); |
486 |
|
487 |
public List<String> parameters_names(); |
488 |
|
489 |
public TableNameBuilder table_name();
|
490 |
|
491 |
public TableNameBuilder createTableNameBuilder();
|
492 |
|
493 |
public SelectBuilder select();
|
494 |
|
495 |
public UpdateBuilder update();
|
496 |
|
497 |
public InsertBuilder insert();
|
498 |
|
499 |
public DeleteBuilder delete();
|
500 |
|
501 |
public AlterTableBuilder alter_table();
|
502 |
|
503 |
public CreateTableBuilder create_table();
|
504 |
|
505 |
public CreateIndexBuilder create_index();
|
506 |
|
507 |
public DropIndexBuilder drop_index();
|
508 |
|
509 |
public GrantBuilder grant();
|
510 |
|
511 |
public DropTableBuilder drop_table();
|
512 |
|
513 |
public UpdateTableStatisticsBuilder update_table_statistics();
|
514 |
|
515 |
public CountBuilder count();
|
516 |
|
517 |
public GeometryExpressionBuilder expression();
|
518 |
|
519 |
public String as_identifier(String id); |
520 |
|
521 |
public String as_string(String s); |
522 |
|
523 |
public String as_string(byte[] s); |
524 |
|
525 |
public String as_string(boolean value); |
526 |
|
527 |
public String as_string(Number value); |
528 |
|
529 |
public String as_string(Object value); |
530 |
|
531 |
public Column column(String name); |
532 |
|
533 |
public Column column(TableNameBuilder table, String name); |
534 |
|
535 |
public void setProperties(Class classToApply, Object... values); |
536 |
|
537 |
public Formatter formatter(); |
538 |
|
539 |
public boolean isAggregateFunction(String funcname); |
540 |
|
541 |
public int getMaxRecomendedSQLLength(); |
542 |
} |