svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / main / java / org / gvsig / expressionevaluator / impl / DefaultDALExpressionBuilder.java @ 46517
History | View | Annotate | Download (6.46 KB)
1 |
package org.gvsig.expressionevaluator.impl; |
---|---|
2 |
|
3 |
import java.util.UUID; |
4 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
5 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
6 |
import org.gvsig.expressionevaluator.Formatter; |
7 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
8 |
import org.gvsig.expressionevaluator.GeometryExpressionUtils; |
9 |
import org.gvsig.expressionevaluator.impl.expressionbuilder.formatters.DALFormatter; |
10 |
import static org.gvsig.fmap.dal.DataManager.FUNCTION_CURRENT_ROW; |
11 |
import static org.gvsig.fmap.dal.DataManager.FUNCTION_CURRENT_STORE; |
12 |
import static org.gvsig.fmap.dal.DataManager.FUNCTION_EXISTS; |
13 |
import static org.gvsig.fmap.dal.DataManager.FUNCTION_FOREING_VALUE; |
14 |
import static org.gvsig.fmap.dal.DataManager.FUNCTION_GEOMETRY; |
15 |
import static org.gvsig.fmap.dal.DataManager.FUNCTION_ISSELECTED_CURRENT_ROW; |
16 |
import static org.gvsig.fmap.dal.DataManager.FUNCTION_SELECT; |
17 |
import static org.gvsig.fmap.dal.DataManager.FUNCTION_SELECT_COUNT; |
18 |
import org.gvsig.fmap.dal.SQLBuilder.SelectBuilder; |
19 |
import org.gvsig.fmap.dal.expressionevaluator.DALExpressionBuilder; |
20 |
import org.gvsig.fmap.dal.feature.spi.SQLBuilderBase; |
21 |
|
22 |
/**
|
23 |
*
|
24 |
* @author jjdelcerro
|
25 |
*/
|
26 |
public class DefaultDALExpressionBuilder implements DALExpressionBuilder { |
27 |
|
28 |
private final SQLBuilderBase sqlbuilder; |
29 |
|
30 |
public DefaultDALExpressionBuilder() {
|
31 |
this.sqlbuilder = new SQLBuilderBase(); |
32 |
} |
33 |
|
34 |
|
35 |
|
36 |
// private class DefaultSelectBuilder implements SelectBuilder {
|
37 |
//
|
38 |
// private Value columns;
|
39 |
// private String tableName;
|
40 |
// private Value where;
|
41 |
// private Long limit;
|
42 |
// private final ExpressionBuilder.Function order;
|
43 |
// private final ExpressionBuilder.Function order_mode;
|
44 |
//
|
45 |
// public DefaultSelectBuilder() {
|
46 |
// this.columns = expression().tuple(); // ALL === empty tuple
|
47 |
// this.where = null;
|
48 |
// this.order = expression().tuple();
|
49 |
// this.order_mode = expression().tuple();
|
50 |
// this.limit = null;
|
51 |
// }
|
52 |
//
|
53 |
// @Override
|
54 |
// public SelectBuilder column(String name) {
|
55 |
// ((ExpressionBuilder.Function)columns).parameter(expression().column(name));
|
56 |
// return this;
|
57 |
// }
|
58 |
//
|
59 |
// @Override
|
60 |
// public SelectBuilder column_all() {
|
61 |
// this.columns = expression().tuple(); // ALL === empty tuple
|
62 |
// return this;
|
63 |
// }
|
64 |
//
|
65 |
// @Override
|
66 |
// public SelectBuilder from(String tableName) {
|
67 |
// this.tableName = tableName;
|
68 |
// return this;
|
69 |
// }
|
70 |
//
|
71 |
// @Override
|
72 |
// public SelectBuilder where(ExpressionBuilder.Value where) {
|
73 |
// this.where = where;
|
74 |
// return this;
|
75 |
// }
|
76 |
//
|
77 |
// @Override
|
78 |
// public SelectBuilder order(String columnName, boolean asc) {
|
79 |
// this.order.parameter(expression().variable(columnName));
|
80 |
// this.order_mode.parameter(expression().constant(asc));
|
81 |
// return this;
|
82 |
// }
|
83 |
//
|
84 |
// @Override
|
85 |
// public SelectBuilder limit(long limit) {
|
86 |
// this.limit = limit;
|
87 |
// return this;
|
88 |
// }
|
89 |
//
|
90 |
// @Override
|
91 |
// public ExpressionBuilder.Value toValue() {
|
92 |
// ExpressionBuilder.Function select = expression().function(FUNCTION_SELECT);
|
93 |
//
|
94 |
// select.parameter(columns);
|
95 |
// select.parameter(expression().variable(tableName));
|
96 |
// select.parameter(where);
|
97 |
// select.parameter(order);
|
98 |
// select.parameter(order_mode);
|
99 |
// select.parameter(expression().constant(limit));
|
100 |
//
|
101 |
// return select;
|
102 |
// }
|
103 |
//
|
104 |
// @Override
|
105 |
// public String toString() {
|
106 |
// return this.toString(formatter());
|
107 |
// }
|
108 |
//
|
109 |
// @Override
|
110 |
// public String toString(Formatter<Value> formatter) {
|
111 |
// return this.toValue().toString(formatter);
|
112 |
// }
|
113 |
//
|
114 |
// }
|
115 |
|
116 |
|
117 |
private class DefaultSelectCountBuilder implements SelectCountBuilder { |
118 |
|
119 |
private String tableName; |
120 |
private Value where;
|
121 |
|
122 |
public DefaultSelectCountBuilder() {
|
123 |
} |
124 |
|
125 |
@Override
|
126 |
public SelectCountBuilder table(String tableName) { |
127 |
this.tableName = tableName;
|
128 |
return this; |
129 |
} |
130 |
|
131 |
@Override
|
132 |
public SelectCountBuilder where(ExpressionBuilder.Value where) {
|
133 |
this.where = where;
|
134 |
return this; |
135 |
} |
136 |
|
137 |
@Override
|
138 |
public ExpressionBuilder.Value toValue() {
|
139 |
ExpressionBuilder.Function select = expression().function(FUNCTION_SELECT_COUNT); |
140 |
|
141 |
select.parameter(expression().variable(tableName)); |
142 |
if( where != null ) { |
143 |
select.parameter(where); |
144 |
} |
145 |
return select;
|
146 |
} |
147 |
|
148 |
@Override
|
149 |
public String toString() { |
150 |
return this.toValue().toString(); |
151 |
} |
152 |
|
153 |
} |
154 |
|
155 |
private GeometryExpressionBuilder expressionBuilder;
|
156 |
|
157 |
@Override
|
158 |
public GeometryExpressionBuilder expression() {
|
159 |
if( this.expressionBuilder == null ) { |
160 |
this.expressionBuilder = GeometryExpressionUtils.createExpressionBuilder();
|
161 |
} |
162 |
return this.expressionBuilder; |
163 |
} |
164 |
|
165 |
@Override
|
166 |
public Formatter<Value> formatter() { |
167 |
return this.formatter(null); |
168 |
} |
169 |
|
170 |
@Override
|
171 |
public Formatter<Value> formatter(Formatter<Value> formatter) { |
172 |
return new DALFormatter(formatter); |
173 |
} |
174 |
|
175 |
@Override
|
176 |
public SelectBuilder select() {
|
177 |
return this.sqlbuilder.select(); |
178 |
} |
179 |
|
180 |
@Override
|
181 |
public SelectCountBuilder select_count() {
|
182 |
return new DefaultSelectCountBuilder(); |
183 |
} |
184 |
|
185 |
@Override
|
186 |
public ExpressionBuilder.Function exists(Value list) {
|
187 |
return exists(list, null); |
188 |
} |
189 |
|
190 |
@Override
|
191 |
public ExpressionBuilder.Function exists(Value list, String exists_id) { |
192 |
if( exists_id==null ) { |
193 |
exists_id = "EXISTS"+UUID.randomUUID().toString().replaceAll("-", ""); |
194 |
} |
195 |
ExpressionBuilder.Function exists = expression().function( |
196 |
FUNCTION_EXISTS, |
197 |
list, |
198 |
expression().constant(exists_id) |
199 |
); |
200 |
return exists;
|
201 |
} |
202 |
|
203 |
@Override
|
204 |
public ExpressionBuilder.Function foreing_value(String attrlocal, String attrforeing) { |
205 |
ExpressionBuilder.Function foreing_value = expression().function( |
206 |
FUNCTION_FOREING_VALUE, |
207 |
expression().constant(attrlocal+"."+attrforeing)
|
208 |
); |
209 |
return foreing_value;
|
210 |
} |
211 |
|
212 |
@Override
|
213 |
public ExpressionBuilder.Function current_row() {
|
214 |
return expression().function(FUNCTION_CURRENT_ROW);
|
215 |
} |
216 |
|
217 |
@Override
|
218 |
public ExpressionBuilder.Function current_table() {
|
219 |
return expression().function(FUNCTION_CURRENT_STORE);
|
220 |
} |
221 |
|
222 |
@Override
|
223 |
public ExpressionBuilder.Function isselected_current_row() {
|
224 |
return expression().function(FUNCTION_ISSELECTED_CURRENT_ROW);
|
225 |
} |
226 |
|
227 |
// @Override
|
228 |
// public ExpressionBuilder.Function geometry() {
|
229 |
// return this.expression().function(FUNCTION_GEOMETRY);
|
230 |
// }
|
231 |
|
232 |
} |