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 @ 44198
History | View | Annotate | Download (13.3 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 distinct();
|
227 |
|
228 |
public SelectBuilder limit(long limit); |
229 |
|
230 |
public SelectBuilder limit(Long limit); |
231 |
|
232 |
/**
|
233 |
* Specifies an offset to be applied to the SQL statement. Only an
|
234 |
* offset can be applied if an order has been specified. Otherwise an
|
235 |
* IllegalStateException exception will be thrown when constructing the
|
236 |
* SQL statement invoking the toString method.
|
237 |
*
|
238 |
* @param offset
|
239 |
* @return this SelectBuilder
|
240 |
*/
|
241 |
public SelectBuilder offset(long offset); |
242 |
|
243 |
public boolean has_column(String name); |
244 |
|
245 |
public boolean has_where(); |
246 |
|
247 |
public boolean has_from(); |
248 |
|
249 |
public boolean has_order_by(); |
250 |
|
251 |
public boolean has_limit(); |
252 |
|
253 |
public boolean has_offset(); |
254 |
|
255 |
/**
|
256 |
* Constructs the SQL statement. If the values associated with the SQL
|
257 |
* statement are not valid an IllegalStateException exception is thrown.
|
258 |
*
|
259 |
* @return the SQL select statement.
|
260 |
* @throws IllegalStateException if the values of select statement are
|
261 |
* not valids.
|
262 |
*/
|
263 |
@Override
|
264 |
public String toString(); |
265 |
|
266 |
} |
267 |
|
268 |
public interface UpdateBuilder extends Statement { |
269 |
|
270 |
public TableNameBuilder table();
|
271 |
|
272 |
public UpdateColumnBuilder column();
|
273 |
|
274 |
public ExpressionBuilder where();
|
275 |
|
276 |
public boolean has_where(); |
277 |
} |
278 |
|
279 |
public interface InsertBuilder extends Statement { |
280 |
|
281 |
public TableNameBuilder table();
|
282 |
|
283 |
public InsertColumnBuilder column();
|
284 |
} |
285 |
|
286 |
public interface DeleteBuilder extends Statement { |
287 |
|
288 |
public TableNameBuilder table();
|
289 |
|
290 |
public ExpressionBuilder where();
|
291 |
|
292 |
public boolean has_where(); |
293 |
} |
294 |
|
295 |
public interface AlterTableBuilder extends Statement { |
296 |
|
297 |
public TableNameBuilder table();
|
298 |
|
299 |
public AlterTableBuilder drop_column(String columnName); |
300 |
|
301 |
public AlterTableBuilder add_column(FeatureAttributeDescriptor fad);
|
302 |
|
303 |
public AlterTableBuilder add_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue); |
304 |
|
305 |
public AlterTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls); |
306 |
|
307 |
public AlterTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, Object srsdbcode, boolean isIndexed, boolean allowNulls); |
308 |
|
309 |
public AlterTableBuilder alter_column(FeatureAttributeDescriptor fad);
|
310 |
|
311 |
public AlterTableBuilder alter_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue); |
312 |
|
313 |
public AlterTableBuilder alter_geometry_column(String columnName, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls); |
314 |
|
315 |
public AlterTableBuilder alter_geometry_column(String columnName, int geom_type, int geom_subtype, Object srsdbcode, boolean isIndexed, boolean allowNulls); |
316 |
|
317 |
public AlterTableBuilder rename_column(String source, String target); |
318 |
|
319 |
public boolean isEmpty(); |
320 |
|
321 |
public List<String> toStrings(); |
322 |
|
323 |
public List<String> toStrings(Formatter formatter); |
324 |
} |
325 |
|
326 |
public interface CreateTableBuilder extends Statement { |
327 |
|
328 |
public TableNameBuilder table();
|
329 |
|
330 |
public CreateTableBuilder add_column(FeatureAttributeDescriptor fad);
|
331 |
|
332 |
public CreateTableBuilder add_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue); |
333 |
|
334 |
public CreateTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls); |
335 |
|
336 |
public CreateTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, Object srsdbcode, boolean isIndexed, boolean allowNulls); |
337 |
|
338 |
public ColumnDescriptor getColumnDescriptor(String columnName); |
339 |
|
340 |
public List<String> toStrings(); |
341 |
|
342 |
public List<String> toStrings(Formatter formatter); |
343 |
} |
344 |
|
345 |
public interface UpdateTableStatisticsBuilder extends Statement { |
346 |
|
347 |
public TableNameBuilder table();
|
348 |
|
349 |
public List<String> toStrings(); |
350 |
|
351 |
public List<String> toStrings(Formatter formatter); |
352 |
} |
353 |
|
354 |
public interface GrantRoleBuilder extends StatementPart { |
355 |
|
356 |
public GrantRoleBuilder privilege(Privilege privilege);
|
357 |
|
358 |
public GrantRoleBuilder select();
|
359 |
|
360 |
public GrantRoleBuilder insert();
|
361 |
|
362 |
public GrantRoleBuilder delete();
|
363 |
|
364 |
public GrantRoleBuilder truncate();
|
365 |
|
366 |
public GrantRoleBuilder reference();
|
367 |
|
368 |
public GrantRoleBuilder update();
|
369 |
|
370 |
public GrantRoleBuilder trigger();
|
371 |
|
372 |
public GrantRoleBuilder all();
|
373 |
} |
374 |
|
375 |
public interface GrantBuilder extends Statement { |
376 |
|
377 |
public TableNameBuilder table();
|
378 |
|
379 |
public GrantRoleBuilder role(String name); |
380 |
|
381 |
public List<String> toStrings(); |
382 |
|
383 |
public List<String> toStrings(Formatter formatter); |
384 |
} |
385 |
|
386 |
public interface DropTableBuilder extends Statement { |
387 |
|
388 |
public TableNameBuilder table();
|
389 |
|
390 |
public List<String> toStrings(); |
391 |
|
392 |
public List<String> toStrings(Formatter formatter); |
393 |
} |
394 |
|
395 |
public interface CreateIndexBuilder extends Statement { |
396 |
|
397 |
public CreateIndexBuilder if_not_exist();
|
398 |
|
399 |
public CreateIndexBuilder unique();
|
400 |
|
401 |
public CreateIndexBuilder name(String name); |
402 |
|
403 |
public CreateIndexBuilder spatial();
|
404 |
|
405 |
public CreateIndexBuilder column(String name); |
406 |
|
407 |
public TableNameBuilder table();
|
408 |
|
409 |
public List<String> toStrings(); |
410 |
|
411 |
public List<String> toStrings(Formatter formatter); |
412 |
} |
413 |
|
414 |
public String default_schema(); |
415 |
|
416 |
public boolean support_schemas(); |
417 |
|
418 |
public boolean has_spatial_functions(); |
419 |
|
420 |
public GeometrySupportType geometry_support_type();
|
421 |
|
422 |
public String sqltype(int dataType, int p, int s, int geomType, int geomSubtype); |
423 |
|
424 |
public Object sqlgeometrytype(int type, int subtype); |
425 |
|
426 |
public Object sqlgeometrydimension(int type, int subtype); |
427 |
|
428 |
public Object srs_id(IProjection projection); |
429 |
|
430 |
public String toString(Formatter formatter); |
431 |
|
432 |
public List<Variable> variables(); |
433 |
|
434 |
public List<String> variables_names(); |
435 |
|
436 |
public List<Parameter> parameters(); |
437 |
|
438 |
public List<String> parameters_names(); |
439 |
|
440 |
public SelectBuilder select();
|
441 |
|
442 |
public UpdateBuilder update();
|
443 |
|
444 |
public InsertBuilder insert();
|
445 |
|
446 |
public DeleteBuilder delete();
|
447 |
|
448 |
public AlterTableBuilder alter_table();
|
449 |
|
450 |
public CreateTableBuilder create_table();
|
451 |
|
452 |
public CreateIndexBuilder create_index();
|
453 |
|
454 |
public GrantBuilder grant();
|
455 |
|
456 |
public DropTableBuilder drop_table();
|
457 |
|
458 |
public UpdateTableStatisticsBuilder update_table_statistics();
|
459 |
|
460 |
public CountBuilder count();
|
461 |
|
462 |
public ExpressionBuilder expression();
|
463 |
|
464 |
public String as_identifier(String id); |
465 |
|
466 |
public String as_string(String s); |
467 |
|
468 |
public String as_string(byte[] s); |
469 |
|
470 |
public String as_string(boolean value); |
471 |
|
472 |
public String as_string(Number value); |
473 |
|
474 |
public String as_string(Object value); |
475 |
|
476 |
public void setProperties(Class classToApply, Object... values); |
477 |
|
478 |
} |