svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.db / org.gvsig.fmap.dal.db.jdbc / src / test / java / org / gvsig / fmap / dal / store / jdbc2 / operations / usecases / arena2 / AbstractTestMultipleExpansionOfCalculatedField.java @ 46112
History | View | Annotate | Download (5.05 KB)
1 |
package org.gvsig.fmap.dal.store.jdbc2.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.jdbc2.AbstractTestUtils; |
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 abstract class AbstractTestMultipleExpansionOfCalculatedField extends TestCase { |
26 |
|
27 |
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractTestMultipleExpansionOfCalculatedField.class); |
28 |
|
29 |
public AbstractTestMultipleExpansionOfCalculatedField(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 AbstractTestUtils utils;
|
45 |
|
46 |
public AbstractTestUtils utils() {
|
47 |
if (this.utils == null) { |
48 |
this.utils = this.createUtils(); |
49 |
} |
50 |
return this.utils; |
51 |
} |
52 |
|
53 |
protected abstract AbstractTestUtils createUtils(); |
54 |
|
55 |
protected List<String> getExpectedSQLs(String name) throws Exception { |
56 |
return utils().getExpectedSQLs(name);
|
57 |
} |
58 |
|
59 |
public void testMultipleExpansionOfCalculatedField() throws Exception { |
60 |
try {
|
61 |
JDBCHelper helper = utils().createJDBCHelper(); |
62 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
63 |
OperationsFactory operations = helper.getOperations(); |
64 |
|
65 |
List<String> expectedSQLs = getExpectedSQLs("usecases/arena2/testMultipleExpansionOfCalculatedField.sql"); |
66 |
|
67 |
FeatureStore arena2_conductores = utils().openCSVStore("operations/usecases/arena2/ARENA2_CONDUCTORES.csv");
|
68 |
FeatureStore arena2_accidentes = utils().openCSVStore("operations/usecases/arena2/ARENA2_ACCIDENTES.csv");
|
69 |
FeatureStore arena2_vehiculos = utils().openCSVStore("operations/usecases/arena2/ARENA2_VEHICULOS.csv");
|
70 |
|
71 |
TableReference table = operations.createTableReference( |
72 |
"dbtest",
|
73 |
"public", //sqlbuilder.default_schema(), |
74 |
"ARENA2_CONDUCTORES",
|
75 |
null
|
76 |
); |
77 |
FeatureType featureType = arena2_conductores.getDefaultFeatureType(); |
78 |
EditableFeatureType eFeatureType = featureType.getEditable(); |
79 |
FeatureQuery query = arena2_conductores.createFeatureQuery(); |
80 |
addExtraColumn(eFeatureType, query, "AccKm0", DataTypes.DOUBLE, "FOREING_VALUE('ID_ACCIDENTE.KM')"); |
81 |
addExtraColumn(eFeatureType, query, "AccKm1", DataTypes.DOUBLE, "AccKm0 * 100"); |
82 |
addExtraColumn(eFeatureType, query, "AccKm2", DataTypes.DOUBLE, "AccKm0 * 222"); |
83 |
|
84 |
CountOperation count = operations.createCount(eFeatureType, table, null, query);
|
85 |
String sqlcount = count.getSQL();
|
86 |
System.out.println("###### SQL:" + sqlcount); |
87 |
System.out.println("###### EXP:" + expectedSQLs.get(1)); |
88 |
assertEquals("Count SQL", expectedSQLs.get(1), sqlcount); |
89 |
|
90 |
ResultSetForSetProviderOperation resultSetForSetProvider = operations.createResultSetForSetProvider( |
91 |
table, |
92 |
null,
|
93 |
null,
|
94 |
query, |
95 |
eFeatureType, |
96 |
eFeatureType, |
97 |
15,
|
98 |
0,
|
99 |
0
|
100 |
); |
101 |
String sql = resultSetForSetProvider.getSQL();
|
102 |
System.out.println("###### SQL:" + sql); |
103 |
System.out.println("###### EXP:" + expectedSQLs.get(0)); |
104 |
|
105 |
assertEquals("Select SQL", expectedSQLs.get(0), sql); |
106 |
|
107 |
|
108 |
} catch (Throwable th) { |
109 |
th.printStackTrace(); |
110 |
throw th;
|
111 |
} |
112 |
} |
113 |
|
114 |
private void addExtraColumn(EditableFeatureType eFeatureType, FeatureQuery query, String name, int type, String exp) { |
115 |
EditableFeatureAttributeDescriptor extraColumn = query.getExtraColumn().add(name, type); |
116 |
extraColumn.setFeatureAttributeEmulator(new DefaultFeatureAttributeEmulatorExpression(eFeatureType, ExpressionUtils.createExpression(exp)));
|
117 |
} |
118 |
|
119 |
} |