Revision 46050 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.h2spatial/org.gvsig.h2spatial.h2gis132/org.gvsig.h2spatial.h2gis132.provider/src/test/java/org/gvsig/fmap/dal/store/h2/operations/sql/TestResultSetForSetProvider.java
TestResultSetForSetProvider.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.util.List; |
4 | 4 |
import junit.framework.TestCase; |
5 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
|
6 |
import org.gvsig.fmap.dal.DataTypes; |
|
7 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
|
8 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
5 | 9 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
6 | 10 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
7 | 11 |
import org.gvsig.fmap.dal.feature.FeatureType; |
12 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureAttributeEmulatorExpression; |
|
8 | 13 |
import org.gvsig.fmap.dal.store.h2.TestUtils; |
9 | 14 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
10 | 15 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
... | ... | |
65 | 70 |
String sql = resultSetForSetProvider.getSQL(); |
66 | 71 |
assertEquals("ResultSetForSetProvider SQL", expectedSQLs.get(0), sql); |
67 | 72 |
} |
73 |
public void testComputedAttribute() throws Exception { |
|
74 |
try { |
|
75 |
JDBCHelper helper = TestUtils.createJDBCHelper(); |
|
76 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
77 |
OperationsFactory operations = helper.getOperations(); |
|
68 | 78 |
|
79 |
List<String> expectedSQLs = TestUtils.getSQLs("resultSetForSetProvider.sql"); |
|
80 |
|
|
81 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
82 |
|
|
83 |
TableReference table = operations.createTableReference( |
|
84 |
"dbtest", |
|
85 |
sqlbuilder.default_schema(), |
|
86 |
"test", |
|
87 |
null |
|
88 |
); |
|
89 |
FeatureType featureType = sourceStore.getDefaultFeatureType(); |
|
90 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
|
91 |
eFeatureType.add("Compu1", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("ID*2"))); |
|
92 |
|
|
93 |
ResultSetForSetProviderOperation resultSetForSetProvider = operations.createResultSetForSetProvider( |
|
94 |
table, |
|
95 |
null, |
|
96 |
null, |
|
97 |
null, |
|
98 |
eFeatureType, |
|
99 |
eFeatureType, |
|
100 |
0, |
|
101 |
0, |
|
102 |
0 |
|
103 |
); |
|
104 |
String sql = resultSetForSetProvider.getSQL(); |
|
105 |
assertEquals("ResultSetForSetProvider SQL", expectedSQLs.get(5), sql); |
|
106 |
} catch (Exception ex) { |
|
107 |
ex.printStackTrace(); |
|
108 |
throw ex; |
|
109 |
} |
|
110 |
} |
|
111 |
|
|
112 |
public void testComputedAttribute2() throws Exception { |
|
113 |
try { |
|
114 |
JDBCHelper helper = TestUtils.createJDBCHelper(); |
|
115 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
116 |
OperationsFactory operations = helper.getOperations(); |
|
117 |
|
|
118 |
List<String> expectedSQLs = TestUtils.getSQLs("resultSetForSetProvider.sql"); |
|
119 |
|
|
120 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
121 |
|
|
122 |
TableReference table = operations.createTableReference( |
|
123 |
"dbtest", |
|
124 |
sqlbuilder.default_schema(), |
|
125 |
"test", |
|
126 |
null |
|
127 |
); |
|
128 |
FeatureType featureType = sourceStore.getDefaultFeatureType(); |
|
129 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
|
130 |
eFeatureType.add("Compu1", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("ID*2"))); |
|
131 |
eFeatureType.add("Compu2", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("Long+10+Compu1"))); |
|
132 |
|
|
133 |
ResultSetForSetProviderOperation resultSetForSetProvider = operations.createResultSetForSetProvider( |
|
134 |
table, |
|
135 |
null, |
|
136 |
null, |
|
137 |
null, |
|
138 |
eFeatureType, |
|
139 |
eFeatureType, |
|
140 |
0, |
|
141 |
0, |
|
142 |
0 |
|
143 |
); |
|
144 |
String sql = resultSetForSetProvider.getSQL(); |
|
145 |
assertEquals("ResultSetForSetProvider SQL", expectedSQLs.get(6), sql); |
|
146 |
} catch (Exception ex) { |
|
147 |
ex.printStackTrace(); |
|
148 |
throw ex; |
|
149 |
} |
|
150 |
} |
|
151 |
|
|
152 |
public void testComputedExtraColumn() throws Exception { |
|
153 |
try { |
|
154 |
JDBCHelper helper = TestUtils.createJDBCHelper(); |
|
155 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
156 |
OperationsFactory operations = helper.getOperations(); |
|
157 |
|
|
158 |
List<String> expectedSQLs = TestUtils.getSQLs("resultSetForSetProvider.sql"); |
|
159 |
|
|
160 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
161 |
|
|
162 |
TableReference table = operations.createTableReference( |
|
163 |
"dbtest", |
|
164 |
sqlbuilder.default_schema(), |
|
165 |
"test", |
|
166 |
null |
|
167 |
); |
|
168 |
FeatureType featureType = sourceStore.getDefaultFeatureType(); |
|
169 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
|
170 |
eFeatureType.add("Compu1", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("ID*2"))); |
|
171 |
|
|
172 |
FeatureQuery query = sourceStore.createFeatureQuery(); |
|
173 |
EditableFeatureAttributeDescriptor extraColumn1 = query.getExtraColumn().add("Extra1", DataTypes.INTEGER); |
|
174 |
extraColumn1.setFeatureAttributeEmulator(new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("Long+10+Compu1"))); |
|
175 |
|
|
176 |
ResultSetForSetProviderOperation resultSetForSetProvider = operations.createResultSetForSetProvider( |
|
177 |
table, |
|
178 |
null, |
|
179 |
null, |
|
180 |
query, |
|
181 |
eFeatureType, |
|
182 |
eFeatureType, |
|
183 |
0, |
|
184 |
0, |
|
185 |
0 |
|
186 |
); |
|
187 |
String sql = resultSetForSetProvider.getSQL(); |
|
188 |
assertEquals("ResultSetForSetProvider SQL", expectedSQLs.get(7), sql); |
|
189 |
} catch (Exception ex) { |
|
190 |
ex.printStackTrace(); |
|
191 |
throw ex; |
|
192 |
} |
|
193 |
} |
|
194 |
|
|
195 |
public void testComputedExtraColumn2() throws Exception { |
|
196 |
try { |
|
197 |
JDBCHelper helper = TestUtils.createJDBCHelper(); |
|
198 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
199 |
OperationsFactory operations = helper.getOperations(); |
|
200 |
|
|
201 |
List<String> expectedSQLs = TestUtils.getSQLs("resultSetForSetProvider.sql"); |
|
202 |
|
|
203 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
204 |
|
|
205 |
TableReference table = operations.createTableReference( |
|
206 |
"dbtest", |
|
207 |
sqlbuilder.default_schema(), |
|
208 |
"test", |
|
209 |
null |
|
210 |
); |
|
211 |
FeatureType featureType = sourceStore.getDefaultFeatureType(); |
|
212 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
|
213 |
|
|
214 |
FeatureQuery query = sourceStore.createFeatureQuery(); |
|
215 |
EditableFeatureAttributeDescriptor extraColumn1 = query.getExtraColumn().add("Extra1", DataTypes.INTEGER); |
|
216 |
extraColumn1.setFeatureAttributeEmulator(new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("ID*2"))); |
|
217 |
EditableFeatureAttributeDescriptor extraColumn2 = query.getExtraColumn().add("Extra2", DataTypes.INTEGER); |
|
218 |
extraColumn2.setFeatureAttributeEmulator(new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("Long+10+Extra1"))); |
|
219 |
|
|
220 |
ResultSetForSetProviderOperation resultSetForSetProvider = operations.createResultSetForSetProvider( |
|
221 |
table, |
|
222 |
null, |
|
223 |
null, |
|
224 |
query, |
|
225 |
eFeatureType, |
|
226 |
eFeatureType, |
|
227 |
0, |
|
228 |
0, |
|
229 |
0 |
|
230 |
); |
|
231 |
String sql = resultSetForSetProvider.getSQL(); |
|
232 |
assertEquals("ResultSetForSetProvider SQL", expectedSQLs.get(8), sql); |
|
233 |
} catch (Exception ex) { |
|
234 |
ex.printStackTrace(); |
|
235 |
throw ex; |
|
236 |
} |
|
237 |
} |
|
238 |
|
|
239 |
public void testComputedExtraColumnWithWhere() throws Exception { |
|
240 |
try { |
|
241 |
JDBCHelper helper = TestUtils.createJDBCHelper(); |
|
242 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
243 |
OperationsFactory operations = helper.getOperations(); |
|
244 |
|
|
245 |
List<String> expectedSQLs = TestUtils.getSQLs("resultSetForSetProvider.sql"); |
|
246 |
|
|
247 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
248 |
|
|
249 |
TableReference table = operations.createTableReference( |
|
250 |
"dbtest", |
|
251 |
sqlbuilder.default_schema(), |
|
252 |
"test", |
|
253 |
null |
|
254 |
); |
|
255 |
|
|
256 |
StringBuilder filter = new StringBuilder(); |
|
257 |
filter.append("Extra1 > 10"); |
|
258 |
|
|
259 |
FeatureType featureType = sourceStore.getDefaultFeatureType(); |
|
260 |
|
|
261 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
|
262 |
eFeatureType.add("Compu1", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("ID*2"))); |
|
263 |
|
|
264 |
FeatureQuery query = sourceStore.createFeatureQuery(); |
|
265 |
EditableFeatureAttributeDescriptor extraColumn1 = query.getExtraColumn().add("Extra1", DataTypes.INTEGER); |
|
266 |
extraColumn1.setFeatureAttributeEmulator(new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("Long+10+Compu1"))); |
|
267 |
query.addFilter(filter.toString()); |
|
268 |
query.getOrder().add("Extra1"); |
|
269 |
|
|
270 |
ResultSetForSetProviderOperation resultSetForSetProvider = operations.createResultSetForSetProvider( |
|
271 |
table, |
|
272 |
null, |
|
273 |
null, |
|
274 |
query, |
|
275 |
eFeatureType, |
|
276 |
eFeatureType, |
|
277 |
0, |
|
278 |
0, |
|
279 |
0 |
|
280 |
); |
|
281 |
String sql = resultSetForSetProvider.getSQL(); |
|
282 |
assertEquals("ResultSetForSetProvider SQL", expectedSQLs.get(9), sql); |
|
283 |
} catch (Exception ex) { |
|
284 |
ex.printStackTrace(); |
|
285 |
throw ex; |
|
286 |
} |
|
287 |
} |
|
288 |
|
|
69 | 289 |
public void testSimpleGroup() throws Exception { |
70 | 290 |
try { |
71 | 291 |
JDBCHelper helper = TestUtils.createJDBCHelper(); |
... | ... | |
108 | 328 |
throw th; |
109 | 329 |
} |
110 | 330 |
} |
331 |
|
|
332 |
public void testGroupByComputed() throws Exception { |
|
333 |
try { |
|
334 |
JDBCHelper helper = TestUtils.createJDBCHelper(); |
|
335 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
336 |
OperationsFactory operations = helper.getOperations(); |
|
111 | 337 |
|
338 |
List<String> expectedSQLs = TestUtils.getSQLs("resultSetForSetProvider.sql"); |
|
339 |
|
|
340 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
341 |
|
|
342 |
TableReference table = operations.createTableReference( |
|
343 |
"dbtest", |
|
344 |
sqlbuilder.default_schema(), |
|
345 |
"test", |
|
346 |
null |
|
347 |
); |
|
348 |
FeatureType featureType = sourceStore.getDefaultFeatureType(); |
|
349 |
FeatureQuery query = sourceStore.createFeatureQuery(); |
|
350 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
|
351 |
eFeatureType.add("Compu1", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("ID*2"))); |
|
352 |
eFeatureType.add("Compu2", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("Long+300"))); |
|
353 |
EditableFeatureAttributeDescriptor extraColumn1 = query.getExtraColumn().add("Extra1", DataTypes.INTEGER); |
|
354 |
EditableFeatureAttributeDescriptor extraColumn2 = query.getExtraColumn().add("Extra2", DataTypes.INTEGER); |
|
355 |
extraColumn1.setFeatureAttributeEmulator(new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("Long+10+Compu1"))); |
|
356 |
extraColumn2.setFeatureAttributeEmulator(new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("20+Byte+Compu1"))); |
|
357 |
query.getGroupByColumns().add("Long"); |
|
358 |
query.getGroupByColumns().add("Extra1"); |
|
359 |
query.getGroupByColumns().add("Compu1"); |
|
360 |
query.getAggregateFunctions().put("ID", "MIN"); |
|
361 |
query.getAggregateFunctions().put("Byte", "MAX"); |
|
362 |
query.getAggregateFunctions().put("Double", "SUM"); |
|
363 |
query.getAggregateFunctions().put("Extra2", "SUM"); |
|
364 |
query.getAggregateFunctions().put("Compu2", "SUM"); |
|
365 |
ResultSetForSetProviderOperation resultSetForSetProvider = operations.createResultSetForSetProvider( |
|
366 |
table, |
|
367 |
null, |
|
368 |
null, |
|
369 |
query, |
|
370 |
eFeatureType, |
|
371 |
eFeatureType, |
|
372 |
0, |
|
373 |
0, |
|
374 |
0 |
|
375 |
); |
|
376 |
String sql = resultSetForSetProvider.getSQL(); |
|
377 |
System.out.println("###### SQL:" + sql); |
|
378 |
System.out.println("###### EXP:" + expectedSQLs.get(10)); |
|
379 |
|
|
380 |
assertEquals("ResultSetForSetProvider SQL", expectedSQLs.get(10), sql); |
|
381 |
} catch (Throwable th) { |
|
382 |
throw th; |
|
383 |
} |
|
384 |
} |
|
385 |
|
|
112 | 386 |
public void testSubselect() throws Exception { |
113 | 387 |
JDBCHelper helper = TestUtils.createJDBCHelper(); |
114 | 388 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
Also available in: Unified diff