Revision 47579 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.sqlite/org.gvsig.sqlite.provider/src/test/java/org/gvsig/sqlite/dal/TestCreate.java
TestCreate.java | ||
---|---|---|
53 | 53 |
// public void testHello() {} |
54 | 54 |
|
55 | 55 |
protected String getProviderName() { |
56 |
return DataStore.H2SPATIAL_PROVIDER_NAME;
|
|
56 |
return SQLiteLibrary.NAME;
|
|
57 | 57 |
} |
58 | 58 |
|
59 | 59 |
protected String getTargetName() { |
... | ... | |
281 | 281 |
} |
282 | 282 |
|
283 | 283 |
public void testFilterByDate() throws Exception { |
284 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
285 |
JDBCServerExplorer explorer = TestUtils.openServerExplorer(DBNAME); |
|
286 |
|
|
287 |
createFrom(explorer, sourceStore); |
|
288 |
copyFrom(explorer, sourceStore, FeatureStore.MODE_APPEND); |
|
289 |
|
|
290 |
FeatureStore h2Store = openTargetStore1(explorer); |
|
291 |
ExpressionBuilder expbuilder = ExpressionUtils.createExpressionBuilder(); |
|
284 |
try { |
|
285 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
286 |
JDBCServerExplorer explorer = TestUtils.openServerExplorer(DBNAME); |
|
292 | 287 |
|
293 |
String filter = expbuilder.or( |
|
294 |
expbuilder.and( |
|
295 |
expbuilder.gt( |
|
296 |
expbuilder.column("Time"), |
|
297 |
expbuilder.time("01:02:03") |
|
298 |
), |
|
299 |
expbuilder.lt( |
|
300 |
expbuilder.column("Time"), |
|
301 |
expbuilder.time(new Date()) |
|
302 |
) |
|
303 |
), |
|
304 |
expbuilder.and( |
|
305 |
expbuilder.gt( |
|
306 |
expbuilder.column("Date"), |
|
307 |
expbuilder.date("2019-02-17") |
|
308 |
), |
|
309 |
expbuilder.lt( |
|
310 |
expbuilder.column("Date"), |
|
311 |
expbuilder.date(new Date()) |
|
312 |
) |
|
313 |
) |
|
314 |
).toString(); |
|
315 |
FeatureQuery query = sourceStore.createFeatureQuery(); |
|
316 |
query.addFilter(filter); |
|
317 |
List<Feature> features = h2Store.getFeatures(query); |
|
318 |
int sz = features.size(); |
|
288 |
createFrom(explorer, sourceStore); |
|
289 |
copyFrom(explorer, sourceStore, FeatureStore.MODE_APPEND); |
|
290 |
|
|
291 |
FeatureStore dbStore = openTargetStore1(explorer); |
|
292 |
ExpressionBuilder expbuilder = ExpressionUtils.createExpressionBuilder(); |
|
293 |
|
|
294 |
String filter = expbuilder.or( |
|
295 |
expbuilder.and( |
|
296 |
expbuilder.gt( |
|
297 |
expbuilder.column("Time"), |
|
298 |
expbuilder.time("01:02:03") |
|
299 |
), |
|
300 |
expbuilder.lt( |
|
301 |
expbuilder.column("Time"), |
|
302 |
expbuilder.time(new Date()) |
|
303 |
) |
|
304 |
), |
|
305 |
expbuilder.and( |
|
306 |
expbuilder.gt( |
|
307 |
expbuilder.column("Date"), |
|
308 |
expbuilder.date("2019-02-17") |
|
309 |
), |
|
310 |
expbuilder.lt( |
|
311 |
expbuilder.column("Date"), |
|
312 |
expbuilder.date(new Date()) |
|
313 |
) |
|
314 |
) |
|
315 |
).toString(); |
|
316 |
FeatureQuery query = sourceStore.createFeatureQuery(); |
|
317 |
query.addFilter(filter); |
|
318 |
List<Feature> features = dbStore.getFeatures(query); |
|
319 |
int sz = features.size(); |
|
320 |
if(sz > 0) { |
|
321 |
features.get(0); |
|
322 |
} |
|
323 |
} catch(Throwable t) { |
|
324 |
LOGGER.warn("",t); |
|
325 |
throw t; |
|
326 |
} |
|
327 |
|
|
319 | 328 |
} |
320 | 329 |
|
321 | 330 |
public void testComputed1() throws Exception { |
322 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
323 |
JDBCServerExplorer explorer = TestUtils.openServerExplorer(DBNAME); |
|
324 |
|
|
325 |
createFrom(explorer, sourceStore); |
|
326 |
copyFrom(explorer, sourceStore, FeatureStore.MODE_APPEND); |
|
327 |
|
|
328 |
FeatureStore h2Store = openTargetStore1(explorer); |
|
329 |
h2Store.edit(); |
|
330 |
FeatureType featureType = h2Store.getDefaultFeatureType(); |
|
331 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
|
332 |
eFeatureType.add("Compu1", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("ID*2"))); |
|
333 |
eFeatureType.add("Compu2", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("Long+10+Compu1"))); |
|
334 |
h2Store.update(eFeatureType); |
|
335 |
h2Store.finishEditing(); |
|
336 |
List<Feature> features = h2Store.getFeatures(); |
|
337 |
for (int i = 0; i < features.size(); i++) { |
|
338 |
Feature feature = features.get(i); |
|
339 |
assertEquals("Compu1 "+i, feature.getInt("ID") * 2, feature.getInt("Compu1")); |
|
340 |
if(feature.get("Long")==null) { |
|
341 |
assertEquals("Compu2 "+i, null, feature.get("Compu2")); |
|
342 |
} else { |
|
343 |
assertEquals("Compu2 "+i, feature.getInt("Long") + 10 + feature.getInt("Compu1"), feature.getInt("Compu2")); |
|
331 |
try { |
|
332 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
333 |
JDBCServerExplorer explorer = TestUtils.openServerExplorer(DBNAME); |
|
334 |
|
|
335 |
createFrom(explorer, sourceStore); |
|
336 |
copyFrom(explorer, sourceStore, FeatureStore.MODE_APPEND); |
|
337 |
|
|
338 |
FeatureStore h2Store = openTargetStore1(explorer); |
|
339 |
h2Store.edit(); |
|
340 |
FeatureType featureType = h2Store.getDefaultFeatureType(); |
|
341 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
|
342 |
eFeatureType.add("Compu1", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("ID*2"))); |
|
343 |
eFeatureType.add("Compu2", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("Long+10+Compu1"))); |
|
344 |
h2Store.update(eFeatureType); |
|
345 |
h2Store.finishEditing(); |
|
346 |
List<Feature> features = h2Store.getFeatures(); |
|
347 |
for (int i = 0; i < features.size(); i++) { |
|
348 |
Feature feature = features.get(i); |
|
349 |
assertEquals("Compu1 "+i, feature.getInt("ID") * 2, feature.getInt("Compu1")); |
|
350 |
if(feature.get("Long")==null) { |
|
351 |
assertEquals("Compu2 "+i, null, feature.get("Compu2")); |
|
352 |
} else { |
|
353 |
assertEquals("Compu2 "+i, feature.getInt("Long") + 10 + feature.getInt("Compu1"), feature.getInt("Compu2")); |
|
354 |
} |
|
344 | 355 |
} |
356 |
DisposeUtils.dispose(h2Store); |
|
357 |
} catch(Throwable t) { |
|
358 |
LOGGER.warn("",t); |
|
359 |
throw t; |
|
345 | 360 |
} |
346 |
DisposeUtils.dispose(h2Store); |
|
347 | 361 |
} |
348 | 362 |
|
349 | 363 |
public void testComputed2() throws Exception { |
364 |
try { |
|
350 | 365 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
351 | 366 |
JDBCServerExplorer explorer = TestUtils.openServerExplorer(DBNAME); |
352 | 367 |
|
... | ... | |
389 | 404 |
features.add(feature.getCopy()); |
390 | 405 |
} |
391 | 406 |
features0 = null; |
392 |
features.get(1).get("Compu1"); |
|
393 |
features.get(1).get("Compu2"); |
|
407 |
Feature feature = features.get(1); |
|
408 |
feature.get("Compu1"); |
|
409 |
feature.get("Compu2"); |
|
410 |
assertEquals("Compu2", 3602, feature.getInt("Compu2")); |
|
411 |
assertEquals("Compu1", 1, feature.getInt("Compu1")); |
|
412 |
|
|
394 | 413 |
// assertEquals("Long0",null,features.get(0).get("Long")); |
395 | 414 |
// assertEquals("Long1",null,features.get(1).get("Long")); |
396 | 415 |
// assertEquals("Long2",1000L,features.get(2).getLong("Long")); |
... | ... | |
417 | 436 |
// assertEquals("Compu2", feature.getInt("Long") + 10 + feature.getInt("Compu1"), feature.getInt("Compu2")); |
418 | 437 |
// } |
419 | 438 |
DisposeUtils.dispose(h2Store); |
439 |
} catch(Throwable t) { |
|
440 |
LOGGER.warn("",t); |
|
441 |
throw t; |
|
442 |
} |
|
420 | 443 |
} |
421 | 444 |
|
422 | 445 |
|
Also available in: Unified diff