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 @ 46114
History | View | Annotate | Download (5.04 KB)
1 | 46112 | omartinez | package org.gvsig.fmap.dal.store.jdbc2.operations.usecases.arena2; |
---|---|---|---|
2 | 45472 | jjdelcerro | |
3 | import java.util.List; |
||
4 | import junit.framework.TestCase; |
||
5 | 46050 | omartinez | 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 | 45472 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureQuery; |
10 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
11 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
12 | 46050 | omartinez | import org.gvsig.fmap.dal.impl.expressionevaluator.DefaultFeatureAttributeEmulatorExpression; |
13 | 46112 | omartinez | import org.gvsig.fmap.dal.store.jdbc2.AbstractTestUtils; |
14 | 45472 | jjdelcerro | 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 | 46104 | omartinez | import org.gvsig.fmap.dal.store.jdbc2.spi.operations.CountOperation; |
19 | 45472 | jjdelcerro | 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 | 46010 | jjdelcerro | @SuppressWarnings("UseSpecificCatch") |
25 | 46112 | omartinez | public abstract class AbstractTestMultipleExpansionOfCalculatedField extends TestCase { |
26 | 45472 | jjdelcerro | |
27 | 46112 | omartinez | private static final Logger LOGGER = LoggerFactory.getLogger(AbstractTestMultipleExpansionOfCalculatedField.class); |
28 | 45472 | jjdelcerro | |
29 | 46112 | omartinez | public AbstractTestMultipleExpansionOfCalculatedField(String testName) { |
30 | 46105 | omartinez | super(testName);
|
31 | } |
||
32 | 45472 | jjdelcerro | |
33 | 46105 | omartinez | @Override
|
34 | protected void setUp() throws Exception { |
||
35 | super.setUp();
|
||
36 | new DefaultLibrariesInitializer().fullInitialize();
|
||
37 | } |
||
38 | 45472 | jjdelcerro | |
39 | 46105 | omartinez | @Override
|
40 | protected void tearDown() throws Exception { |
||
41 | super.tearDown();
|
||
42 | } |
||
43 | 46112 | omartinez | |
44 | protected AbstractTestUtils utils;
|
||
45 | 46050 | omartinez | |
46 | 46112 | omartinez | 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 | 46105 | omartinez | protected List<String> getExpectedSQLs(String name) throws Exception { |
56 | 46112 | omartinez | return utils().getExpectedSQLs(name);
|
57 | 46105 | omartinez | } |
58 | |||
59 | 46112 | omartinez | public void testMultipleExpansionOfCalculatedField() throws Exception { |
60 | 46010 | jjdelcerro | try {
|
61 | 46112 | omartinez | JDBCHelper helper = utils().createJDBCHelper(); |
62 | 46010 | jjdelcerro | JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
63 | OperationsFactory operations = helper.getOperations(); |
||
64 | 45472 | jjdelcerro | |
65 | 46112 | omartinez | List<String> expectedSQLs = getExpectedSQLs("usecases/arena2/testMultipleExpansionOfCalculatedField.sql"); |
66 | 45472 | jjdelcerro | |
67 | 46112 | omartinez | 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 | 45472 | jjdelcerro | |
71 | 46010 | jjdelcerro | TableReference table = operations.createTableReference( |
72 | "dbtest",
|
||
73 | 46114 | omartinez | sqlbuilder.default_schema(), |
74 | 46104 | omartinez | "ARENA2_CONDUCTORES",
|
75 | 46010 | jjdelcerro | null
|
76 | ); |
||
77 | 46104 | omartinez | FeatureType featureType = arena2_conductores.getDefaultFeatureType(); |
78 | 46050 | omartinez | EditableFeatureType eFeatureType = featureType.getEditable(); |
79 | 46104 | omartinez | FeatureQuery query = arena2_conductores.createFeatureQuery(); |
80 | 46112 | omartinez | 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 | 46105 | omartinez | |
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 | 46104 | omartinez | assertEquals("Count SQL", expectedSQLs.get(1), sqlcount); |
89 | 46105 | omartinez | |
90 | 46050 | omartinez | ResultSetForSetProviderOperation resultSetForSetProvider = operations.createResultSetForSetProvider( |
91 | table, |
||
92 | null,
|
||
93 | null,
|
||
94 | query, |
||
95 | eFeatureType, |
||
96 | eFeatureType, |
||
97 | 46105 | omartinez | 15,
|
98 | 46050 | omartinez | 0,
|
99 | 0
|
||
100 | ); |
||
101 | String sql = resultSetForSetProvider.getSQL();
|
||
102 | System.out.println("###### SQL:" + sql); |
||
103 | 46104 | omartinez | System.out.println("###### EXP:" + expectedSQLs.get(0)); |
104 | 46050 | omartinez | |
105 | 46104 | omartinez | assertEquals("Select SQL", expectedSQLs.get(0), sql); |
106 | 46105 | omartinez | |
107 | |||
108 | 46050 | omartinez | } catch (Throwable th) { |
109 | 46105 | omartinez | th.printStackTrace(); |
110 | 46050 | omartinez | throw th;
|
111 | } |
||
112 | } |
||
113 | 46112 | omartinez | |
114 | 46105 | omartinez | 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 | 45472 | jjdelcerro | |
119 | } |