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.h2 / src / test / java / org / gvsig / fmap / dal / store / h2 / operations / sql / TestResultSetForSetProvider.java @ 44769
History | View | Annotate | Download (5.23 KB)
1 | 44678 | jjdelcerro | package org.gvsig.fmap.dal.store.h2.operations.sql; |
---|---|---|---|
2 | 43512 | jjdelcerro | |
3 | 44669 | jjdelcerro | import java.util.List; |
4 | 43512 | jjdelcerro | import junit.framework.TestCase; |
5 | 44712 | jjdelcerro | import org.gvsig.fmap.dal.DataQuery; |
6 | import org.gvsig.fmap.dal.feature.FeatureQuery; |
||
7 | 44669 | jjdelcerro | import org.gvsig.fmap.dal.feature.FeatureStore; |
8 | import org.gvsig.fmap.dal.feature.FeatureType; |
||
9 | 44678 | jjdelcerro | import org.gvsig.fmap.dal.store.h2.TestUtils; |
10 | import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
||
11 | import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
||
12 | import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
||
13 | import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
||
14 | import org.gvsig.fmap.dal.store.jdbc2.spi.operations.ResultSetForSetProviderOperation; |
||
15 | 44098 | jjdelcerro | import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
16 | 44669 | jjdelcerro | import org.slf4j.Logger; |
17 | import org.slf4j.LoggerFactory; |
||
18 | 43512 | jjdelcerro | |
19 | 44678 | jjdelcerro | public class TestResultSetForSetProvider extends TestCase { |
20 | 43512 | jjdelcerro | |
21 | 44678 | jjdelcerro | private static final Logger LOGGER = LoggerFactory.getLogger(TestResultSetForSetProvider.class); |
22 | 44139 | jjdelcerro | |
23 | 44678 | jjdelcerro | public TestResultSetForSetProvider(String testName) { |
24 | super(testName);
|
||
25 | } |
||
26 | 44421 | jjdelcerro | |
27 | 44678 | jjdelcerro | @Override
|
28 | protected void setUp() throws Exception { |
||
29 | super.setUp();
|
||
30 | new DefaultLibrariesInitializer().fullInitialize();
|
||
31 | } |
||
32 | 44139 | jjdelcerro | |
33 | 44678 | jjdelcerro | @Override
|
34 | protected void tearDown() throws Exception { |
||
35 | super.tearDown();
|
||
36 | } |
||
37 | 44139 | jjdelcerro | |
38 | 44712 | jjdelcerro | public void testSimple() throws Exception { |
39 | 44685 | jjdelcerro | JDBCHelper helper = TestUtils.getJDBCHelper(); |
40 | 44678 | jjdelcerro | JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
41 | OperationsFactory operations = helper.getOperations(); |
||
42 | |||
43 | List<String> expectedSQLs = TestUtils.getSQLs("resultSetForSetProvider.sql"); |
||
44 | 43512 | jjdelcerro | |
45 | 44678 | jjdelcerro | FeatureStore sourceStore = TestUtils.openSourceStore1(); |
46 | |||
47 | TableReference table = operations.createTableReference( |
||
48 | "dbtest",
|
||
49 | sqlbuilder.default_schema(), |
||
50 | "test",
|
||
51 | null
|
||
52 | ); |
||
53 | FeatureType featureType = sourceStore.getDefaultFeatureType(); |
||
54 | ResultSetForSetProviderOperation resultSetForSetProvider = operations.createResultSetForSetProvider( |
||
55 | table, |
||
56 | null,
|
||
57 | null,
|
||
58 | null,
|
||
59 | featureType, |
||
60 | featureType, |
||
61 | 0,
|
||
62 | 0,
|
||
63 | 0
|
||
64 | ); |
||
65 | String sql = resultSetForSetProvider.getSQL();
|
||
66 | assertEquals("ResultSetForSetProvider SQL", expectedSQLs.get(0), sql); |
||
67 | } |
||
68 | |||
69 | 44712 | jjdelcerro | public void testSimpleGroup() throws Exception { |
70 | JDBCHelper helper = TestUtils.getJDBCHelper(); |
||
71 | JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
||
72 | OperationsFactory operations = helper.getOperations(); |
||
73 | |||
74 | List<String> expectedSQLs = TestUtils.getSQLs("resultSetForSetProvider.sql"); |
||
75 | |||
76 | FeatureStore sourceStore = TestUtils.openSourceStore1(); |
||
77 | |||
78 | TableReference table = operations.createTableReference( |
||
79 | "dbtest",
|
||
80 | sqlbuilder.default_schema(), |
||
81 | "test",
|
||
82 | null
|
||
83 | ); |
||
84 | FeatureType featureType = sourceStore.getDefaultFeatureType(); |
||
85 | FeatureQuery query = sourceStore.createFeatureQuery(); |
||
86 | query.getGroupByColumns().add("Long");
|
||
87 | query.getAggregateFunctions().put("ID", "MIN"); |
||
88 | query.getAggregateFunctions().put("Byte", "MAX"); |
||
89 | query.getAggregateFunctions().put("Double", "SUM"); |
||
90 | ResultSetForSetProviderOperation resultSetForSetProvider = operations.createResultSetForSetProvider( |
||
91 | table, |
||
92 | null,
|
||
93 | null,
|
||
94 | query, |
||
95 | featureType, |
||
96 | featureType, |
||
97 | 0,
|
||
98 | 0,
|
||
99 | 0
|
||
100 | ); |
||
101 | String sql = resultSetForSetProvider.getSQL();
|
||
102 | System.out.println("###### SQL:"+sql); |
||
103 | System.out.println("###### EXP:"+expectedSQLs.get(1)); |
||
104 | |||
105 | assertEquals("ResultSetForSetProvider SQL", expectedSQLs.get(1), sql); |
||
106 | } |
||
107 | 44750 | jjdelcerro | |
108 | public void testSubselect() throws Exception { |
||
109 | JDBCHelper helper = TestUtils.getJDBCHelper(); |
||
110 | JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
||
111 | OperationsFactory operations = helper.getOperations(); |
||
112 | |||
113 | List<String> expectedSQLs = TestUtils.getSQLs("resultSetForSetProvider.sql"); |
||
114 | |||
115 | FeatureStore sourceStore = TestUtils.openSourceStore1(); |
||
116 | |||
117 | TableReference table = operations.createTableReference( |
||
118 | "dbtest",
|
||
119 | sqlbuilder.default_schema(), |
||
120 | "test",
|
||
121 | null
|
||
122 | ); |
||
123 | StringBuilder filter = new StringBuilder(); |
||
124 | filter.append("EXISTS(");
|
||
125 | 44769 | jjdelcerro | filter.append(" SELECT \"ISO_A2\" FROM countries");
|
126 | 44750 | jjdelcerro | filter.append(" WHERE ");
|
127 | filter.append(" TEST.STRING = countries.CONTINENT AND ");
|
||
128 | filter.append(" countries.LASTCENSUS < 0 ");
|
||
129 | filter.append(" LIMIT 1;, ");
|
||
130 | filter.append(" 'EXISTS62a964cd7bc24f409b97c03b9170408d' ");
|
||
131 | filter.append(")");
|
||
132 | FeatureType featureType = sourceStore.getDefaultFeatureType(); |
||
133 | FeatureQuery query = sourceStore.createFeatureQuery(); |
||
134 | query.addFilter(filter.toString()); |
||
135 | ResultSetForSetProviderOperation resultSetForSetProvider = operations.createResultSetForSetProvider( |
||
136 | table, |
||
137 | null,
|
||
138 | null,
|
||
139 | query, |
||
140 | featureType, |
||
141 | featureType, |
||
142 | 0,
|
||
143 | 0,
|
||
144 | 0
|
||
145 | ); |
||
146 | String sql = resultSetForSetProvider.getSQL();
|
||
147 | System.out.println("###### SQL:"+sql); |
||
148 | System.out.println("###### EXP:"+expectedSQLs.get(2)); |
||
149 | |||
150 | assertEquals("ResultSetForSetProvider SQL", expectedSQLs.get(2), sql); |
||
151 | } |
||
152 | |||
153 | 44732 | jjdelcerro | // TODO: a?adir un test con where, group y order.
|
154 | 43939 | jjdelcerro | } |