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

History | View | Annotate | Download (11.9 KB)

1
package org.gvsig.fmap.dal;
2

    
3
import java.util.List;
4
import org.cresques.cts.IProjection;
5

    
6
public interface SQLBuilder extends ExpressionBuilder {
7
    
8
    public enum Privilege {
9
        SELECT,
10
        INSERT,
11
        UPDATE,
12
        DELETE,
13
        TRUNCATE,
14
        REFERENCE,
15
        TRIGGER,
16
        ALL
17
    };
18

    
19
    public interface Statement extends Visitable {
20
        
21
    }
22
    
23
    public interface SQLConfig extends Config {
24
        public final static String default_schema = "default_schema";
25
        
26
        public final static String allowAutomaticValues = "allowAutomaticValues";
27
        
28
        public final static String ST_ExtentAggregate = "ST_ExtentAggregate";
29
        public final static String ST_UnionAggregate = "ST_UnionAggregate";
30
        public final static String count = "count";
31
        public final static String count_distinct = "count_distinct";
32

    
33
        public final static String type_boolean = "type_boolean";
34
        public final static String type_byte = "type_byte";
35
        public final static String type_bytearray = "type_bytearray";
36
        public final static String type_geometry = "type_geometry";
37
        public final static String type_char = "type_char";
38
        public final static String type_date = "type_date";
39
        public final static String type_double = "type_double";
40
        public final static String type_numeric_p = "type_numeric_p";
41
        public final static String type_numeric_ps = "type_numeric_ps";
42
        public final static String type_bigdecimal = "type_bigdecimal";
43
        public final static String type_float = "type_float";
44
        public final static String type_int = "type_int";
45
        public final static String type_long = "type_long";
46
        public final static String type_string = "type_string";
47
        public final static String type_string_p = "type_string_p";
48
        public final static String type_time = "type_time";
49
        public final static String type_timestamp = "type_timestamp";
50
        public final static String type_version = "type_version";
51
        public final static String type_URI = "type_URI";
52
        public final static String type_URL = "type_URL";
53
        public final static String type_FILE = "type_FILE";
54
        public final static String type_FOLDER = "type_FOLDER";
55
     
56
        public final static String DELETE_FROM_table_WHERE_expresion = "DELETE_FROM_table_WHERE_expresion";
57
        public final static String DELETE_FROM_table = "DELETE_FROM_table";
58
        public final static String INSERT_INTO_table_columns_VALUES_values = "INSERT_INTO_table_columns_VALUES_values";
59
        public final static String UPDATE_TABLE_STATISTICS_table = "UPDATE_TABLE_STATISTICS_table";        
60
        public final static String DROP_TABLE_table = "DROP_TABLE_table";
61
        public final static String DELETE_GEOMETRY_COLUMN_FROM_TABLE_schema_table = "DELETE_GEOMETRY_COLUMN_FROM_TABLE_schema_table";
62
        public final static String DELETE_GEOMETRY_COLUMN_FROM_TABLE_table = "DELETE_GEOMETRY_COLUMN_FROM_TABLE_table";
63
        public final static String UPDATE_table_SET_columnsAndValues_WHERE_expresion = "UPDATE_table_SET_columnsAndValues_WHERE_expresion";
64
        public final static String UPDATE_table_SET_columnsAndValues = "UPDATE_table_SET_columnsAndValues";
65
        public final static String GRANT_privileges_ON_table_TO_role = "GRANT_privileges_ON_table_TO_role";
66
        public final static String CREATE_INDEX_name_ON_table_column = "CREATE_INDEX_name_ON_table_column";
67
        public final static String CREATE_INDEX_name_ON_table_USING_GIST_column = "CREATE_INDEX_name_ON_table_USING_GIST_column";
68
   
69
    }
70
    
71
    public interface TableNameBuilder extends Visitable {
72
        public TableNameBuilder database(String name);
73
        public TableNameBuilder schema(String name);
74
        public TableNameBuilder name(String name);
75
        public String getDatabase();
76
        public String getSchema();
77
        public String getName();
78
        public boolean has_database();
79
        public boolean has_schema();
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 int 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(int geom_srsid);
108
    }
109

    
110
    public interface CountBuilder extends Value {
111
        public CountBuilder all();
112
        public CountBuilder column(Value value);
113
        public CountBuilder distinct();
114
    }
115
    
116
    public interface SelectColumnBuilder extends Visitable {
117
        public SelectColumnBuilder name(String name);
118
        public SelectColumnBuilder value(Value value);
119
        public SelectColumnBuilder as(String alias);
120
        public SelectColumnBuilder as_geometry();
121
        public SelectColumnBuilder all();
122
        public String getName();
123
        public String getAlias();
124
        public String getValue();
125
    }
126
    
127
    public interface InsertColumnBuilder extends Visitable {
128
        public InsertColumnBuilder name(String name);
129
        public InsertColumnBuilder with_value(Value value);
130
        public String getName();
131
        public Value getValue();
132
    }
133
    
134
    public interface UpdateColumnBuilder extends InsertColumnBuilder {
135
        @Override
136
        public UpdateColumnBuilder name(String name);
137
        @Override
138
        public UpdateColumnBuilder with_value(Value value);
139
        @Override
140
        public String getName();
141
        @Override
142
        public Value getValue();
143
    }
144
        
145
    public interface FromBuilder extends Visitable {
146
        public TableNameBuilder table();
147
        public FromBuilder subquery(String subquery);
148
        public FromBuilder custom(String passthrough);
149
    }
150

    
151
    public interface OrderByBuilder extends Visitable {
152
        public OrderByBuilder column(String name);
153
        public OrderByBuilder ascending(boolean asc);
154
        public OrderByBuilder ascending();
155
        public OrderByBuilder descending();
156
        public OrderByBuilder custom(String order);
157
    }
158
    
159
    public interface SelectBuilder extends Statement {
160
        public SelectColumnBuilder column();
161
        public FromBuilder from();
162
        public ExpressionBuilder where();
163
        public OrderByBuilder order_by();
164
        public SelectBuilder distinct();
165
        public SelectBuilder limit(long limit);
166
        
167
        /**
168
         * Specifies an offset to be applied to the SQL statement.
169
         * Only an offset can be applied if an order has been specified. 
170
         * Otherwise an IllegalStateException exception will be thrown when 
171
         * constructing the SQL statement invoking the toString method.
172
         * 
173
         * @param offset
174
         * @return this SelectBuilder
175
         */
176
        public SelectBuilder offset(long offset);
177
        
178
        public boolean has_column(String name);
179
        public boolean has_where();
180
        public boolean has_from();
181
        public boolean has_order_by();
182
        public boolean has_limit();
183
        public boolean has_offset();
184

    
185
        /**
186
         * Constructs the SQL statement.
187
         * If the values associated with the SQL statement are not valid 
188
         * an IllegalStateException exception is thrown.
189
         * 
190
         * @return the SQL select statement.
191
         * @throws IllegalStateException if the values of select statement are not valids.
192
         */
193
        @Override
194
        public String toString();
195
        
196
    }
197
    
198
    public interface UpdateBuilder extends Statement {
199
        public TableNameBuilder table();
200
        public UpdateColumnBuilder column();
201
        public ExpressionBuilder where();
202
        public boolean has_where();
203
    }
204
    
205
    public interface InsertBuilder extends Statement {
206
        public TableNameBuilder table();
207
        public InsertColumnBuilder column();
208
    }
209
    
210
    public interface DeleteBuilder extends Statement {
211
        public TableNameBuilder table();
212
        public ExpressionBuilder where();
213
        public boolean has_where();
214
    }
215
    
216
    public interface AlterTableBuilder extends Statement {
217
        public TableNameBuilder table();
218
        public AlterTableBuilder drop_column(String columnName);
219
        public AlterTableBuilder add_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue);
220
        public AlterTableBuilder alter_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue);
221
        public AlterTableBuilder rename_column(String source, String target);
222
        public List<String> toStrings();
223
    }
224
    
225
    public interface CreateTableBuilder extends Statement {
226
        public TableNameBuilder table();
227
        public CreateTableBuilder add_column(String columnName, int type, int type_p, int type_s, boolean isPk, boolean isIndexed, boolean allowNulls, boolean isAutomatic, Object defaultValue);
228
        public CreateTableBuilder add_geometry_column(String columnName, int geom_type, int geom_subtype, IProjection proj, boolean isIndexed, boolean allowNulls);
229
        public ColumnDescriptorBuilder getColumnDescriptor(String columnName);
230
        public List<String> toStrings();
231
    }
232
    
233
    public interface UpdateTableStatisticsBuilder extends Statement {
234
        public TableNameBuilder table();
235
        public List<String> toStrings();
236
    }
237
        
238
    public interface GrantRoleBuilder {
239
        public GrantRoleBuilder privilege(Privilege privilege);
240
        public GrantRoleBuilder select();
241
        public GrantRoleBuilder insert();
242
        public GrantRoleBuilder delete();
243
        public GrantRoleBuilder truncate();
244
        public GrantRoleBuilder reference();
245
        public GrantRoleBuilder update();
246
        public GrantRoleBuilder trigger();
247
        public GrantRoleBuilder all();
248
    }
249
    
250
    public interface GrantBuilder extends Statement {
251
        public TableNameBuilder table();
252
        public GrantRoleBuilder role(String name);        
253
        public List<String> toStrings();
254
    }
255
        
256
    public interface DropTableBuilder extends Statement {
257
        public TableNameBuilder table();
258
        public List<String> toStrings();
259
    }
260

    
261
    public String default_schema();
262
    
263
    public boolean supportSchemas();
264

    
265
    public String sqltype(int dataType, int p, int s);
266
    
267
    public Object sqlgeometrytype(int type, int subtype);
268

    
269
    public Object sqlgeometrydimension(int type, int subtype);
270
    
271
    public SelectBuilder select();
272
    
273
    public UpdateBuilder update();
274

    
275
    public InsertBuilder insert();
276
    
277
    public DeleteBuilder delete();
278
    
279
    public AlterTableBuilder alter_table();
280

    
281
    public CreateTableBuilder create_table();
282

    
283
    public GrantBuilder grant();
284

    
285
    public DropTableBuilder drop_table();
286

    
287
    public UpdateTableStatisticsBuilder update_table_statistics();
288

    
289
    public CountBuilder count();
290
    
291
    public Function ST_ExtentAggregate(Value geom);
292

    
293
    public Function ST_UnionAggregate(Value geom);
294
            
295
}