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/TestCreate.java
TestCreate.java | ||
---|---|---|
1 | 1 |
package org.gvsig.fmap.dal.store.h2; |
2 | 2 |
|
3 |
import java.util.ArrayList; |
|
3 | 4 |
import java.util.Date; |
4 | 5 |
import java.util.List; |
5 | 6 |
import junit.framework.TestCase; |
... | ... | |
12 | 13 |
import org.gvsig.fmap.dal.DataStore; |
13 | 14 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
14 | 15 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
16 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
|
15 | 17 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
16 | 18 |
import org.gvsig.fmap.dal.feature.Feature; |
17 | 19 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
... | ... | |
19 | 21 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
20 | 22 |
import org.gvsig.fmap.dal.feature.FeatureType; |
21 | 23 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
24 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureAttributeEmulatorExpression; |
|
22 | 25 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
23 | 26 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
27 |
import org.gvsig.tools.dispose.DisposeUtils; |
|
24 | 28 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
25 | 29 |
import org.slf4j.Logger; |
26 | 30 |
import org.slf4j.LoggerFactory; |
... | ... | |
307 | 311 |
List<Feature> features = h2Store.getFeatures(query); |
308 | 312 |
int sz = features.size(); |
309 | 313 |
} |
314 |
|
|
315 |
public void testComputed1() throws Exception { |
|
316 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
317 |
JDBCServerExplorer explorer = TestUtils.openServerExplorer(DBNAME); |
|
318 |
|
|
319 |
createFrom(explorer, sourceStore); |
|
320 |
copyFrom(explorer, sourceStore, FeatureStore.MODE_APPEND); |
|
321 |
|
|
322 |
FeatureStore h2Store = openTargetStore1(explorer); |
|
323 |
h2Store.edit(); |
|
324 |
FeatureType featureType = h2Store.getDefaultFeatureType(); |
|
325 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
|
326 |
eFeatureType.add("Compu1", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("ID*2"))); |
|
327 |
eFeatureType.add("Compu2", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("Long+10+Compu1"))); |
|
328 |
h2Store.update(eFeatureType); |
|
329 |
h2Store.finishEditing(); |
|
330 |
List<Feature> features = h2Store.getFeatures(); |
|
331 |
for (int i = 0; i < features.size(); i++) { |
|
332 |
Feature feature = features.get(i); |
|
333 |
assertEquals("Compu1 "+i, feature.getInt("ID") * 2, feature.getInt("Compu1")); |
|
334 |
if(feature.get("Long")==null) { |
|
335 |
assertEquals("Compu2 "+i, null, feature.get("Compu2")); |
|
336 |
} else { |
|
337 |
assertEquals("Compu2 "+i, feature.getInt("Long") + 10 + feature.getInt("Compu1"), feature.getInt("Compu2")); |
|
338 |
} |
|
339 |
} |
|
340 |
DisposeUtils.dispose(h2Store); |
|
341 |
} |
|
342 |
|
|
343 |
public void testComputed2() throws Exception { |
|
344 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
345 |
JDBCServerExplorer explorer = TestUtils.openServerExplorer(DBNAME); |
|
346 |
|
|
347 |
createFrom(explorer, sourceStore); |
|
348 |
copyFrom(explorer, sourceStore, FeatureStore.MODE_APPEND); |
|
349 |
|
|
350 |
FeatureStore h2Store = openTargetStore1(explorer); |
|
351 |
h2Store.edit(); |
|
352 |
FeatureType featureType = h2Store.getDefaultFeatureType(); |
|
353 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
|
354 |
FeatureQuery query = sourceStore.createFeatureQuery(); |
|
355 |
eFeatureType.add("Compu1", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("MOD(ID,10)"))); |
|
356 |
eFeatureType.add("Compu2", DataTypes.INTEGER, new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("Long+300"))); |
|
357 |
EditableFeatureAttributeDescriptor extraColumn1 = query.getExtraColumn().add("Extra1", DataTypes.INTEGER); |
|
358 |
EditableFeatureAttributeDescriptor extraColumn2 = query.getExtraColumn().add("Extra2", DataTypes.INTEGER); |
|
359 |
// EditableFeatureAttributeDescriptor extraColumn3 = query.getExtraColumn().add("LongMax", DataTypes.INTEGER); |
|
360 |
extraColumn1.setFeatureAttributeEmulator(new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("Compu1+1"))); |
|
361 |
extraColumn2.setFeatureAttributeEmulator(new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("20+Byte"))); |
|
362 |
// extraColumn3.setFeatureAttributeEmulator(new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression("Long"))); |
|
363 |
query.getGroupByColumns().add("Decimal"); |
|
364 |
query.getGroupByColumns().add("Extra1"); |
|
365 |
// query.getGroupByColumns().add("Compu1"); |
|
366 |
query.getAggregateFunctions().put("ID", "MIN"); |
|
367 |
query.getAggregateFunctions().put("Byte", "MIN"); |
|
368 |
// query.getAggregateFunctions().put("Long", "MIN"); |
|
369 |
// query.getAggregateFunctions().put("LongMax", "MAX"); |
|
370 |
query.getAggregateFunctions().put("Compu1", "MIN"); |
|
371 |
query.getAggregateFunctions().put("Double", "SUM"); |
|
372 |
query.getAggregateFunctions().put("Extra2", "SUM"); |
|
373 |
query.getAggregateFunctions().put("Compu2", "SUM"); |
|
374 |
h2Store.update(eFeatureType); |
|
375 |
h2Store.finishEditing(); |
|
376 |
|
|
377 |
|
|
378 |
List<Feature> features0 = h2Store.getFeatures(query); |
|
379 |
ArrayList<Feature> features = new ArrayList<>(); |
|
380 |
|
|
381 |
for (int i = 0; i < features0.size(); i++) { |
|
382 |
Feature feature = features0.get(i); |
|
383 |
features.add(feature.getCopy()); |
|
384 |
} |
|
385 |
features0 = null; |
|
386 |
features.get(1).get("Compu1"); |
|
387 |
features.get(1).get("Compu2"); |
|
388 |
// assertEquals("Long0",null,features.get(0).get("Long")); |
|
389 |
// assertEquals("Long1",null,features.get(1).get("Long")); |
|
390 |
// assertEquals("Long2",1000L,features.get(2).getLong("Long")); |
|
391 |
// assertEquals("Long3",1001L,features.get(3).getLong("Long")); |
|
392 |
// assertEquals("Long4",2000L,features.get(4).getLong("Long")); |
|
393 |
// assertEquals("Long5",2002L,features.get(5).getLong("Long")); |
|
394 |
// assertEquals("Long6",3000L,features.get(6).getLong("Long")); |
|
395 |
// assertEquals("Long7",4000L,features.get(7).getLong("Long")); |
|
396 |
// assertEquals("Long8",4001L,features.get(8).getLong("Long")); |
|
397 |
// assertEquals("Long9",5000L,features.get(9).getLong("Long")); |
|
398 |
// assertEquals("Long10",5002L,features.get(10).getLong("Long")); |
|
399 |
// assertEquals("Long11",6000L,features.get(11).getLong("Long")); |
|
400 |
// assertEquals("Long12",6003L,features.get(12).getLong("Long")); |
|
401 |
// assertEquals("Long13",7000L,features.get(13).getLong("Long")); |
|
402 |
// assertEquals("Long14",7004L,features.get(14).getLong("Long")); |
|
403 |
// assertEquals("Long15",8000L,features.get(15).getLong("Long")); |
|
404 |
// assertEquals("Long16",8005L,features.get(16).getLong("Long")); |
|
405 |
// assertEquals("Long17",9000L,features.get(17).getLong("Long")); |
|
406 |
// assertEquals("Long18",9006L,features.get(18).getLong("Long")); |
|
407 |
|
|
408 |
// for (int i = 0; i < features.size(); i++) { |
|
409 |
// Feature feature = features.get(i); |
|
410 |
// assertEquals("Long", feature.getInt("ID") * 2, feature.getInt("Compu1")); |
|
411 |
// assertEquals("Compu2", feature.getInt("Long") + 10 + feature.getInt("Compu1"), feature.getInt("Compu2")); |
|
412 |
// } |
|
413 |
DisposeUtils.dispose(h2Store); |
|
414 |
} |
|
415 |
|
|
416 |
|
|
310 | 417 |
|
311 | 418 |
} |
Also available in: Unified diff