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

History | View | Annotate | Download (11.5 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
    
67
    }
68
    
69
    public interface TableNameBuilder extends Visitable {
70
        public TableNameBuilder database(String name);
71
        public TableNameBuilder schema(String name);
72
        public TableNameBuilder name(String name);
73
        public String getDatabase();
74
        public String getSchema();
75
        public String getName();
76
        public boolean has_database();
77
        public boolean has_schema();
78
    }
79
    
80
    public interface ColumnDescriptorBuilder {
81
        public String getName();
82
        public int getType();
83
        public int getSize();
84
        public int getPrecision();
85
        public boolean isPrimaryKey();
86
        public boolean isAutomatic();
87
        boolean allowNulls();
88
        public Object getDefaultValue();
89
        public int getGeometryType();
90
        public int getGeometrySubtype();
91
        public int getGeometrySRSId();
92
        public boolean isGeometry();
93
        
94
        public void setName(String name);
95
        public void setType(int type);
96
        public void setSize(int size);
97
        public void setPrecision(int precision);
98
        public void setIsPrimaryKey(boolean isPk);
99
        public void setIsAutomatic(boolean isAutomatic);
100
        public void setAllowNulls(boolean allowNulls);
101
        public void setDefaultValue(Object defaultValue);
102
        public void setGeometryType(int geom_type);
103
        public void setGeometrySubtype(int geom_subtype);
104
        public void setGeometrySRSId(int geom_srsid);
105
    }
106

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

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

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

    
258
    public String default_schema();
259

    
260
    public String sqltype(int dataType, int p, int s);
261
    
262
    public Object sqlgeometrytype(int type, int subtype);
263

    
264
    public Object sqlgeometrydimension(int type, int subtype);
265
    
266
    public SelectBuilder select();
267
    
268
    public UpdateBuilder update();
269

    
270
    public InsertBuilder insert();
271
    
272
    public DeleteBuilder delete();
273
    
274
    public AlterTableBuilder alter_table();
275

    
276
    public CreateTableBuilder create_table();
277

    
278
    public GrantBuilder grant();
279

    
280
    public DropTableBuilder drop_table();
281

    
282
    public UpdateTableStatisticsBuilder update_table_statistics();
283

    
284
    public CountBuilder count();
285
    
286
    public Function ST_ExtentAggregate(Value geom);
287

    
288
    public Function ST_UnionAggregate(Value geom);
289
            
290
}