svn-gvsig-desktop / 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 / usecases / arena2 / TestMultipleExpansionOfCalculatedField.java @ 46110
History | View | Annotate | Download (4.72 KB)
1 |
package org.gvsig.fmap.dal.store.h2.operations.usecases.arena2; |
---|---|
2 |
|
3 |
import java.util.List; |
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; |
9 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
10 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
11 |
import org.gvsig.fmap.dal.feature.FeatureType; |
12 |
import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureAttributeEmulatorExpression; |
13 |
import org.gvsig.fmap.dal.store.h2.TestUtils; |
14 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
15 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
16 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
17 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
18 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.CountOperation; |
19 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.ResultSetForSetProviderOperation; |
20 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
21 |
import org.slf4j.Logger; |
22 |
import org.slf4j.LoggerFactory; |
23 |
|
24 |
@SuppressWarnings("UseSpecificCatch") |
25 |
public class TestMultipleExpansionOfCalculatedField extends TestCase { |
26 |
|
27 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestMultipleExpansionOfCalculatedField.class); |
28 |
|
29 |
public TestMultipleExpansionOfCalculatedField(String testName) { |
30 |
super(testName);
|
31 |
} |
32 |
|
33 |
@Override
|
34 |
protected void setUp() throws Exception { |
35 |
super.setUp();
|
36 |
new DefaultLibrariesInitializer().fullInitialize();
|
37 |
} |
38 |
|
39 |
@Override
|
40 |
protected void tearDown() throws Exception { |
41 |
super.tearDown();
|
42 |
} |
43 |
|
44 |
protected List<String> getExpectedSQLs(String name) throws Exception { |
45 |
return TestUtils.getSQLs(name);
|
46 |
} |
47 |
|
48 |
public void testMultipleExpansionOfCalculatedField() throws Exception { |
49 |
try {
|
50 |
JDBCHelper helper = TestUtils.createJDBCHelper(); |
51 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
52 |
OperationsFactory operations = helper.getOperations(); |
53 |
|
54 |
List<String> expectedSQLs = getExpectedSQLs("usecases/arena2/testMultipleExpansionOfCalculatedField.sql"); |
55 |
|
56 |
FeatureStore arena2_conductores = TestUtils.openStoreTest("usecases/arena2/ARENA2_CONDUCTORES.csv");
|
57 |
FeatureStore arena2_accidentes = TestUtils.openStoreTest("usecases/arena2/ARENA2_ACCIDENTES.csv");
|
58 |
FeatureStore arena2_vehiculos = TestUtils.openStoreTest("usecases/arena2/ARENA2_VEHICULOS.csv");
|
59 |
|
60 |
TableReference table = operations.createTableReference( |
61 |
"dbtest",
|
62 |
"public", //sqlbuilder.default_schema(), |
63 |
"ARENA2_CONDUCTORES",
|
64 |
null
|
65 |
); |
66 |
FeatureType featureType = arena2_conductores.getDefaultFeatureType(); |
67 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
68 |
FeatureQuery query = arena2_conductores.createFeatureQuery(); |
69 |
addExtraColumn(eFeatureType, query, "AccKm0", DataTypes.DOUBLE, "FOREING_VALUE('ID_ACCIDENTE.KM')"); |
70 |
addExtraColumn(eFeatureType, query, "AccKm1", DataTypes.DOUBLE, "AccKm0 * 100"); |
71 |
addExtraColumn(eFeatureType, query, "AccKm2", DataTypes.DOUBLE, "AccKm0 * 222"); |
72 |
|
73 |
CountOperation count = operations.createCount(eFeatureType, table, null, query);
|
74 |
String sqlcount = count.getSQL();
|
75 |
System.out.println("###### SQL:" + sqlcount); |
76 |
System.out.println("###### EXP:" + expectedSQLs.get(1)); |
77 |
assertEquals("Count SQL", expectedSQLs.get(1), sqlcount); |
78 |
|
79 |
ResultSetForSetProviderOperation resultSetForSetProvider = operations.createResultSetForSetProvider( |
80 |
table, |
81 |
null,
|
82 |
null,
|
83 |
query, |
84 |
eFeatureType, |
85 |
eFeatureType, |
86 |
15,
|
87 |
0,
|
88 |
0
|
89 |
); |
90 |
String sql = resultSetForSetProvider.getSQL();
|
91 |
System.out.println("###### SQL:" + sql); |
92 |
System.out.println("###### EXP:" + expectedSQLs.get(0)); |
93 |
|
94 |
assertEquals("Select SQL", expectedSQLs.get(0), sql); |
95 |
|
96 |
|
97 |
} catch (Throwable th) { |
98 |
th.printStackTrace(); |
99 |
throw th;
|
100 |
} |
101 |
} |
102 |
|
103 |
private void addExtraColumn(EditableFeatureType eFeatureType, FeatureQuery query, String name, int type, String exp) { |
104 |
EditableFeatureAttributeDescriptor extraColumn = query.getExtraColumn().add(name, type); |
105 |
extraColumn.setFeatureAttributeEmulator(new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression(exp)));
|
106 |
} |
107 |
|
108 |
} |