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 @ 44058
History | View | Annotate | Download (15.6 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.Config; |
7 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
8 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
9 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Visitable; |
10 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
11 |
|
12 |
public interface SQLBuilder extends ExpressionBuilder { |
13 |
|
14 |
public enum Privilege { |
15 |
SELECT, |
16 |
INSERT, |
17 |
UPDATE, |
18 |
DELETE, |
19 |
TRUNCATE, |
20 |
REFERENCE, |
21 |
TRIGGER, |
22 |
ALL |
23 |
}; |
24 |
|
25 |
public interface Statement extends Visitable { |
26 |
|
27 |
} |
28 |
|
29 |
public interface SQLConfig extends Config { |
30 |
public final static String default_schema = "default_schema"; |
31 |
|
32 |
public final static String allowAutomaticValues = "allowAutomaticValues"; |
33 |
|
34 |
public final static String Find_SRID = "Find_SRID"; |
35 |
public final static String ST_ExtentAggregate = "ST_ExtentAggregate"; |
36 |
public final static String ST_UnionAggregate = "ST_UnionAggregate"; |
37 |
public final static String count = "count"; |
38 |
public final static String count_distinct = "count_distinct"; |
39 |
|
40 |
public final static String type_boolean = "type_boolean"; |
41 |
public final static String type_byte = "type_byte"; |
42 |
public final static String type_bytearray = "type_bytearray"; |
43 |
public final static String type_geometry = "type_geometry"; |
44 |
public final static String type_char = "type_char"; |
45 |
public final static String type_date = "type_date"; |
46 |
public final static String type_double = "type_double"; |
47 |
public final static String type_numeric_p = "type_numeric_p"; |
48 |
public final static String type_numeric_ps = "type_numeric_ps"; |
49 |
public final static String type_bigdecimal = "type_bigdecimal"; |
50 |
public final static String type_float = "type_float"; |
51 |
public final static String type_int = "type_int"; |
52 |
public final static String type_long = "type_long"; |
53 |
public final static String type_string = "type_string"; |
54 |
public final static String type_string_p = "type_string_p"; |
55 |
public final static String type_time = "type_time"; |
56 |
public final static String type_timestamp = "type_timestamp"; |
57 |
public final static String type_version = "type_version"; |
58 |
public final static String type_URI = "type_URI"; |
59 |
public final static String type_URL = "type_URL"; |
60 |
public final static String type_FILE = "type_FILE"; |
61 |
public final static String type_FOLDER = "type_FOLDER"; |
62 |
|
63 |
public final static String DELETE_FROM_table_WHERE_expresion = "DELETE_FROM_table_WHERE_expresion"; |
64 |
public final static String DELETE_FROM_table = "DELETE_FROM_table"; |
65 |
public final static String INSERT_INTO_table_columns_VALUES_values = "INSERT_INTO_table_columns_VALUES_values"; |
66 |
public final static String UPDATE_TABLE_STATISTICS_table = "UPDATE_TABLE_STATISTICS_table"; |
67 |
public final static String DROP_TABLE_table = "DROP_TABLE_table"; |
68 |
public final static String DELETE_GEOMETRY_COLUMN_FROM_TABLE_schema_table = "DELETE_GEOMETRY_COLUMN_FROM_TABLE_schema_table"; |
69 |
public final static String DELETE_GEOMETRY_COLUMN_FROM_TABLE_table = "DELETE_GEOMETRY_COLUMN_FROM_TABLE_table"; |
70 |
public final static String UPDATE_table_SET_columnsAndValues_WHERE_expresion = "UPDATE_table_SET_columnsAndValues_WHERE_expresion"; |
71 |
public final static String UPDATE_table_SET_columnsAndValues = "UPDATE_table_SET_columnsAndValues"; |
72 |
public final static String GRANT_privileges_ON_table_TO_role = "GRANT_privileges_ON_table_TO_role"; |
73 |
// public final static String CREATE_INDEX_name_ON_table_column = "CREATE_INDEX_name_ON_table_column";
|
74 |
// public final static String CREATE_INDEX_name_ON_table_USING_GIST_column = "CREATE_INDEX_name_ON_table_USING_GIST_column";
|
75 |
|
76 |
} |
77 |
|
78 |
public interface ColumnDescriptor { |
79 |
public String getName(); |
80 |
public int getType(); |
81 |
public int getSize(); |
82 |
public int getPrecision(); |
83 |
public boolean isPrimaryKey(); |
84 |
public boolean isIndexed(); |
85 |
public boolean isAutomatic(); |
86 |
boolean allowNulls();
|
87 |
public Object getDefaultValue(); |
88 |
public int getGeometryType(); |
89 |
public int getGeometrySubtype(); |
90 |
public Object getGeometrySRSId(); |
91 |
public boolean isGeometry(); |
92 |
|
93 |
public DataStoreParameters getStoreParameters();
|
94 |
|
95 |
public void setName(String name); |
96 |
public void setType(int type); |
97 |
public void setSize(int size); |
98 |
public void setPrecision(int precision); |
99 |
public void setIsPrimaryKey(boolean isPk); |
100 |
public void setIsAutomatic(boolean isAutomatic); |
101 |
public void setAllowNulls(boolean allowNulls); |
102 |
public void setDefaultValue(Object defaultValue); |
103 |
public void setGeometryType(int geom_type); |
104 |
public void setGeometrySubtype(int geom_subtype); |
105 |
public void setGeometrySRSId(Object geom_srsid); |
106 |
} |
107 |
|
108 |
public interface Column extends Variable { |
109 |
public ColumnDescriptor getDescriptor();
|
110 |
} |
111 |
|
112 |
public interface TableNameBuilder extends Visitable { |
113 |
public TableNameBuilder database(String name); |
114 |
public TableNameBuilder schema(String name); |
115 |
public TableNameBuilder name(String name); |
116 |
public String getDatabase(); |
117 |
public String getSchema(); |
118 |
public String getName(); |
119 |
public boolean has_database(); |
120 |
public boolean has_schema(); |
121 |
} |
122 |
|
123 |
public interface ColumnDescriptorBuilder { |
124 |
public String getName(); |
125 |
public int getType(); |
126 |
public int getSize(); |
127 |
public int getPrecision(); |
128 |
public boolean isPrimaryKey(); |
129 |
public boolean isIndexed(); |
130 |
public boolean isAutomatic(); |
131 |
boolean allowNulls();
|
132 |
public Object getDefaultValue(); |
133 |
public int getGeometryType(); |
134 |
public int getGeometrySubtype(); |
135 |
public Object getGeometrySRSId(); |
136 |
public boolean isGeometry(); |
137 |
|
138 |
public void setName(String name); |
139 |
public void setType(int type); |
140 |
public void setSize(int size); |
141 |
public void setPrecision(int precision); |
142 |
public void setIsPrimaryKey(boolean isPk); |
143 |
public void setIsAutomatic(boolean isAutomatic); |
144 |
public void setAllowNulls(boolean allowNulls); |
145 |
public void setDefaultValue(Object defaultValue); |
146 |
public void setGeometryType(int geom_type); |
147 |
public void setGeometrySubtype(int geom_subtype); |
148 |
public void setGeometrySRSId(Object geom_srsid); |
149 |
} |
150 |
|
151 |
public interface CountBuilder extends Value { |
152 |
public CountBuilder all();
|
153 |
public CountBuilder column(Value value);
|
154 |
public CountBuilder distinct();
|
155 |
} |
156 |
|
157 |
public interface SelectColumnBuilder extends Visitable { |
158 |
public SelectColumnBuilder name(String name); |
159 |
public SelectColumnBuilder value(Value value);
|
160 |
public SelectColumnBuilder as(String alias); |
161 |
public SelectColumnBuilder as_geometry();
|
162 |
public SelectColumnBuilder all();
|
163 |
public String getName(); |
164 |
public String getAlias(); |
165 |
public String getValue(); |
166 |
} |
167 |
|
168 |
public interface InsertColumnBuilder extends Visitable { |
169 |
public InsertColumnBuilder name(String name); |
170 |
public InsertColumnBuilder with_value(Value value);
|
171 |
public String getName(); |
172 |
public Value getValue();
|
173 |
} |
174 |
|
175 |
public interface UpdateColumnBuilder extends InsertColumnBuilder { |
176 |
@Override
|
177 |
public UpdateColumnBuilder name(String name); |
178 |
@Override
|
179 |
public UpdateColumnBuilder with_value(Value value);
|
180 |
@Override
|
181 |
public String getName(); |
182 |
@Override
|
183 |
public Value getValue();
|
184 |
} |
185 |
|
186 |
public interface FromBuilder extends Visitable { |
187 |
public TableNameBuilder table();
|
188 |
public FromBuilder subquery(String subquery); |
189 |
public FromBuilder custom(String passthrough); |
190 |
} |
191 |
|
192 |
public interface OrderByBuilder extends Visitable { |
193 |
public OrderByBuilder column(String name); |
194 |
public OrderByBuilder ascending(boolean asc); |
195 |
public OrderByBuilder ascending();
|
196 |
public OrderByBuilder descending();
|
197 |
public OrderByBuilder custom(String order); |
198 |
} |
199 |
|
200 |
public interface SelectBuilder extends Statement { |
201 |
public SelectColumnBuilder column();
|
202 |
public FromBuilder from();
|
203 |
public ExpressionBuilder where();
|
204 |
public OrderByBuilder order_by();
|
205 |
public SelectBuilder distinct();
|
206 |
public SelectBuilder limit(long limit); |
207 |
public SelectBuilder limit(Long limit); |
208 |
|
209 |
/**
|
210 |
* Specifies an offset to be applied to the SQL statement.
|
211 |
* Only an offset can be applied if an order has been specified.
|
212 |
* Otherwise an IllegalStateException exception will be thrown when
|
213 |
* constructing the SQL statement invoking the toString method.
|
214 |
*
|
215 |
* @param offset
|
216 |
* @return this SelectBuilder
|
217 |
*/
|
218 |
public SelectBuilder offset(long offset); |
219 |
|
220 |
public boolean has_column(String name); |
221 |
public boolean has_where(); |
222 |
public boolean has_from(); |
223 |
public boolean has_order_by(); |
224 |
public boolean has_limit(); |
225 |
public boolean has_offset(); |
226 |
|
227 |
/**
|
228 |
* Constructs the SQL statement.
|
229 |
* If the values associated with the SQL statement are not valid
|
230 |
* an IllegalStateException exception is thrown.
|
231 |
*
|
232 |
* @return the SQL select statement.
|
233 |
* @throws IllegalStateException if the values of select statement are not valids.
|
234 |
*/
|
235 |
@Override
|
236 |
public String toString(); |
237 |
|
238 |
} |
239 |
|
240 |
public interface UpdateBuilder extends Statement { |
241 |
public TableNameBuilder table();
|
242 |
public UpdateColumnBuilder column();
|
243 |
public ExpressionBuilder where();
|
244 |
public boolean has_where(); |
245 |
} |
246 |
|
247 |
public interface InsertBuilder extends Statement { |
248 |
public TableNameBuilder table();
|
249 |
public InsertColumnBuilder column();
|
250 |
} |
251 |
|
252 |
public interface DeleteBuilder extends Statement { |
253 |
public TableNameBuilder table();
|
254 |
public ExpressionBuilder where();
|
255 |
public boolean has_where(); |
256 |
} |
257 |
|
258 |
public interface AlterTableBuilder extends Statement { |
259 |
public TableNameBuilder table();
|
260 |
public AlterTableBuilder drop_column(String columnName); |
261 |
public AlterTableBuilder add_column(FeatureAttributeDescriptor fad);
|
262 |
public AlterTableBuilder add_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue); |
263 |
public AlterTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls); |
264 |
public AlterTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, Object srsdbcode, boolean isIndexed, boolean allowNulls); |
265 |
public AlterTableBuilder alter_column(FeatureAttributeDescriptor fad);
|
266 |
public AlterTableBuilder alter_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue); |
267 |
public AlterTableBuilder alter_geometry_column(String columnName, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls); |
268 |
public AlterTableBuilder alter_geometry_column(String columnName, int geom_type, int geom_subtype, Object srsdbcode, boolean isIndexed, boolean allowNulls); |
269 |
public AlterTableBuilder rename_column(String source, String target); |
270 |
public boolean isEmpty(); |
271 |
public List<String> toStrings(); |
272 |
} |
273 |
|
274 |
public interface CreateTableBuilder extends Statement { |
275 |
public TableNameBuilder table();
|
276 |
public CreateTableBuilder add_column(FeatureAttributeDescriptor fad);
|
277 |
public CreateTableBuilder add_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue); |
278 |
public CreateTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls); |
279 |
public CreateTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, Object srsdbcode, boolean isIndexed, boolean allowNulls); |
280 |
public ColumnDescriptor getColumnDescriptor(String columnName); |
281 |
public List<String> toStrings(); |
282 |
} |
283 |
|
284 |
public interface UpdateTableStatisticsBuilder extends Statement { |
285 |
public TableNameBuilder table();
|
286 |
public List<String> toStrings(); |
287 |
} |
288 |
|
289 |
public interface GrantRoleBuilder { |
290 |
public GrantRoleBuilder privilege(Privilege privilege);
|
291 |
public GrantRoleBuilder select();
|
292 |
public GrantRoleBuilder insert();
|
293 |
public GrantRoleBuilder delete();
|
294 |
public GrantRoleBuilder truncate();
|
295 |
public GrantRoleBuilder reference();
|
296 |
public GrantRoleBuilder update();
|
297 |
public GrantRoleBuilder trigger();
|
298 |
public GrantRoleBuilder all();
|
299 |
} |
300 |
|
301 |
public interface GrantBuilder extends Statement { |
302 |
public TableNameBuilder table();
|
303 |
public GrantRoleBuilder role(String name); |
304 |
public List<String> toStrings(); |
305 |
} |
306 |
|
307 |
public interface DropTableBuilder extends Statement { |
308 |
public TableNameBuilder table();
|
309 |
public List<String> toStrings(); |
310 |
} |
311 |
|
312 |
public interface CreateIndexBuilder extends Statement { |
313 |
public CreateIndexBuilder if_not_exist();
|
314 |
public CreateIndexBuilder unique();
|
315 |
public CreateIndexBuilder name(String name); |
316 |
public CreateIndexBuilder spatial();
|
317 |
public CreateIndexBuilder column(String name); |
318 |
public TableNameBuilder table();
|
319 |
public List<String> toStrings(); |
320 |
} |
321 |
|
322 |
@Override
|
323 |
public Column column(String name); |
324 |
|
325 |
public Column column(FeatureAttributeDescriptor fad);
|
326 |
|
327 |
@Override
|
328 |
public List<Variable> getVariables(); |
329 |
|
330 |
public String default_schema(); |
331 |
|
332 |
public boolean supportSchemas(); |
333 |
|
334 |
@Deprecated
|
335 |
public String sqltype(int dataType, int p, int s); |
336 |
|
337 |
public String sqltype(int dataType, int p, int s, int geomType, int geomSubtype); |
338 |
|
339 |
public Object sqlgeometrytype(int type, int subtype); |
340 |
|
341 |
public Object sqlgeometrydimension(int type, int subtype); |
342 |
|
343 |
public SelectBuilder select();
|
344 |
|
345 |
public UpdateBuilder update();
|
346 |
|
347 |
public InsertBuilder insert();
|
348 |
|
349 |
public DeleteBuilder delete();
|
350 |
|
351 |
public AlterTableBuilder alter_table();
|
352 |
|
353 |
public CreateTableBuilder create_table();
|
354 |
|
355 |
public CreateIndexBuilder create_index();
|
356 |
|
357 |
public GrantBuilder grant();
|
358 |
|
359 |
public DropTableBuilder drop_table();
|
360 |
|
361 |
public UpdateTableStatisticsBuilder update_table_statistics();
|
362 |
|
363 |
public CountBuilder count();
|
364 |
|
365 |
public Function ST_ExtentAggregate(Value geom);
|
366 |
|
367 |
public Function ST_UnionAggregate(Value geom);
|
368 |
|
369 |
public Function Find_SRID(Value schema, Value table, Value column);
|
370 |
|
371 |
|
372 |
} |