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