Revision 350
org.gvsig.oracle/tags/org.gvsig.oracle-2.0.49/org.gvsig.oracle.provider/src/test/java/org/gvsig/oracle/dal/OracleSQLBuilderTest.java | ||
---|---|---|
1 |
package org.gvsig.oracle.dal; |
|
2 |
|
|
3 |
|
|
4 |
import junit.framework.TestCase; |
|
5 |
import org.apache.commons.lang3.ArrayUtils; |
|
6 |
import org.cresques.cts.IProjection; |
|
7 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
8 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
|
9 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper; |
|
10 |
import org.gvsig.fmap.crs.CRSFactory; |
|
11 |
import org.gvsig.fmap.dal.SQLBuilder; |
|
12 |
import org.gvsig.fmap.dal.SQLBuilder.Privilege; |
|
13 |
import org.gvsig.fmap.dal.feature.spi.SQLBuilderBase; |
|
14 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
|
15 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.OperationsFactoryBase; |
|
16 |
import org.gvsig.fmap.geom.DataTypes; |
|
17 |
import org.gvsig.fmap.geom.Geometry; |
|
18 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
19 |
import org.gvsig.fmap.geom.GeometryManager; |
|
20 |
import org.gvsig.fmap.geom.primitive.Polygon; |
|
21 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
22 |
|
|
23 |
public class OracleSQLBuilderTest extends TestCase { |
|
24 |
|
|
25 |
public OracleSQLBuilderTest(String testName) { |
|
26 |
super(testName); |
|
27 |
} |
|
28 |
|
|
29 |
@Override |
|
30 |
protected void setUp() throws Exception { |
|
31 |
super.setUp(); |
|
32 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
33 |
} |
|
34 |
|
|
35 |
@Override |
|
36 |
protected void tearDown() throws Exception { |
|
37 |
super.tearDown(); |
|
38 |
} |
|
39 |
|
|
40 |
private SQLBuilder createSQLBuilder() { |
|
41 |
return new OracleSQLBuilder(TestUtils.getJDBCHelper()); |
|
42 |
} |
|
43 |
|
|
44 |
public void testCalculateEnvelopeOfColumn() throws Exception { |
|
45 |
|
|
46 |
TableReference table = new OperationsFactoryBase.DefaultTableReference("master","dbo","test1", null); |
|
47 |
String columnName = "geom"; |
|
48 |
|
|
49 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
50 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
51 |
|
|
52 |
sqlbuilder.select().column().value( |
|
53 |
expbuilder.as_geometry( |
|
54 |
expbuilder.ST_ExtentAggregate( |
|
55 |
expbuilder.column(columnName) |
|
56 |
) |
|
57 |
) |
|
58 |
); |
|
59 |
//sqlbuilder.select().group_by(expbuilder.column(columnName)); |
|
60 |
sqlbuilder.select().from().table() |
|
61 |
.database(table.getDatabase()) |
|
62 |
.schema(table.getSchema()) |
|
63 |
.name(table.getTable()); |
|
64 |
sqlbuilder.select().from().subquery(table.getSubquery()); |
|
65 |
|
|
66 |
sqlbuilder.select().where().set( |
|
67 |
expbuilder.not_is_null(expbuilder.column(columnName)) |
|
68 |
); |
|
69 |
|
|
70 |
System.out.println("# Test:: testCalculateEnvelopeOfColumn"); |
|
71 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
72 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
73 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
74 |
assertEquals( |
|
75 |
"SELECT NVL2((SDO_AGGR_MBR(\"geom\")),(SDO_AGGR_MBR(\"geom\")).Get_WKB(),NULL) FROM \"dbo\".\"test1\" WHERE ( (\"geom\") IS NOT NULL )", |
|
76 |
sqlbuilder.toString() |
|
77 |
); |
|
78 |
assertEquals( |
|
79 |
"[geom]", |
|
80 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
81 |
); |
|
82 |
assertEquals( |
|
83 |
"[]", |
|
84 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
85 |
); |
|
86 |
} |
|
87 |
|
|
88 |
public void testCalculateEnvelope() throws Exception { |
|
89 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
90 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
|
91 |
|
|
92 |
Polygon limit = geometryManager.createPolygon(Geometry.SUBTYPES.GEOM2D); |
|
93 |
limit.addVertex(0, 0); |
|
94 |
limit.addVertex(0, 100); |
|
95 |
limit.addVertex(100, 100); |
|
96 |
limit.addVertex(100, 0); |
|
97 |
limit.addVertex(0, 0); |
|
98 |
|
|
99 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
100 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
101 |
|
|
102 |
sqlbuilder.select().column().value( |
|
103 |
expbuilder.as_geometry( |
|
104 |
expbuilder.ST_ExtentAggregate( |
|
105 |
expbuilder.column("the_geom") |
|
106 |
) |
|
107 |
) |
|
108 |
).as("envelope"); |
|
109 |
sqlbuilder.select().from().table().database("master").schema("dbo").name("test1"); |
|
110 |
sqlbuilder.select().where().set( |
|
111 |
expbuilder.ST_Intersects( |
|
112 |
expbuilder.ST_Envelope( |
|
113 |
expbuilder.column("the_geom") |
|
114 |
), |
|
115 |
expbuilder.geometry(limit, proj) |
|
116 |
) |
|
117 |
); |
|
118 |
sqlbuilder.select().where().and( |
|
119 |
expbuilder.custom("x = 27") |
|
120 |
); |
|
121 |
|
|
122 |
System.out.println("# Test:: testCalculateEnvelope"); |
|
123 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
124 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
125 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
126 |
assertEquals( |
|
127 |
"SELECT NVL2((SDO_AGGR_MBR(\"the_geom\")),(SDO_AGGR_MBR(\"the_geom\")).Get_WKB(),NULL) \"envelope\" FROM \"dbo\".\"test1\" WHERE ( ((SDO_RELATE(SDO_GEOM.SDO_MBR(\"the_geom\"), SDO_GEOMETRY((TO_BLOB(HEXTORAW('000000000300000001000000050000000000000000000000000000000000000000000000004059000000000000405900000000000040590000000000004059000000000000000000000000000000000000000000000000000000000000'))), (4326)), 'mask=ANYINTERACT') = 'TRUE')) AND (x = 27) )", |
|
128 |
sqlbuilder.toString() |
|
129 |
); |
|
130 |
assertEquals( |
|
131 |
"[the_geom]", |
|
132 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
133 |
); |
|
134 |
assertEquals( |
|
135 |
"[]", |
|
136 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
137 |
); |
|
138 |
} |
|
139 |
|
|
140 |
public void testCount() throws Exception { |
|
141 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
142 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
143 |
|
|
144 |
sqlbuilder.select().column().value(sqlbuilder.count().all()); |
|
145 |
sqlbuilder.select().from().table().database("master").schema("dbo").name("test1"); |
|
146 |
sqlbuilder.select().from().subquery(null); |
|
147 |
sqlbuilder.select().where().set( expbuilder.custom("pp = 200")); |
|
148 |
|
|
149 |
System.out.println("# Test:: testCount"); |
|
150 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
151 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
152 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
153 |
|
|
154 |
//# Test:: testCount |
|
155 |
//# SQL:: SELECT COUNT(*) FROM "test1" WHERE pp = 200 |
|
156 |
//# Variables:: [] |
|
157 |
//# Parametros:: [] |
|
158 |
|
|
159 |
assertEquals( |
|
160 |
"SELECT COUNT(*) FROM \"dbo\".\"test1\" WHERE pp = 200", |
|
161 |
sqlbuilder.toString() |
|
162 |
); |
|
163 |
assertEquals( |
|
164 |
"[]", |
|
165 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
166 |
); |
|
167 |
assertEquals( |
|
168 |
"[]", |
|
169 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
170 |
); |
|
171 |
} |
|
172 |
|
|
173 |
public void testCreateTable() throws Exception { |
|
174 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
175 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
176 |
|
|
177 |
sqlbuilder.create_table().table().database("master").schema("dbo").name("test1"); |
|
178 |
sqlbuilder.create_table().add_column( |
|
179 |
"name", |
|
180 |
DataTypes.STRING, |
|
181 |
45, |
|
182 |
0, |
|
183 |
0, |
|
184 |
false, |
|
185 |
false, |
|
186 |
true, |
|
187 |
false, |
|
188 |
null |
|
189 |
); |
|
190 |
sqlbuilder.create_table().add_column( |
|
191 |
"id", |
|
192 |
DataTypes.INT, |
|
193 |
0, |
|
194 |
0, |
|
195 |
0, |
|
196 |
true, |
|
197 |
false, |
|
198 |
false, |
|
199 |
true, |
|
200 |
0 |
|
201 |
); |
|
202 |
sqlbuilder.create_table().add_column( |
|
203 |
"geom", |
|
204 |
DataTypes.GEOMETRY, |
|
205 |
0, |
|
206 |
0, |
|
207 |
0, |
|
208 |
false, |
|
209 |
false, |
|
210 |
true, |
|
211 |
false, |
|
212 |
null |
|
213 |
); |
|
214 |
|
|
215 |
|
|
216 |
// CREATE TABLE "test1" ("name" VARCHAR(45) DEFAULT NULL, "id" INTEGER PRIMARY KEY AUTO_INCREMENT DEFAULT '0' NOT NULL, "geom" GEOMETRY ); ALTER TABLE "test1" ADD CONSTRAINT IF NOT EXISTS "constraint_test1_geom_dim" CHECK ST_CoordDim("geom") = 2 |
|
217 |
System.out.println("# Test:: testCreateTable"); |
|
218 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
219 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
220 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
221 |
assertEquals( |
|
222 |
"CREATE TABLE \"dbo\".\"TEST1\" (\"name\" VARCHAR(45) DEFAULT NULL, \"id\" NUMBER(9,0), \"geom\" SDO_GEOMETRY DEFAULT NULL ); ALTER TABLE \"dbo\".\"TEST1\" ADD PRIMARY KEY (\"id\"); CREATE SEQUENCE \"GVSEQ_TEST1_ID\"; CREATE OR REPLACE TRIGGER \"GVSER_TEST1_ID\" BEFORE INSERT ON \"dbo\".\"TEST1\" FOR EACH ROW BEGIN SELECT \"GVSEQ_TEST1_ID\".NEXTVAL INTO :new.\"id\" FROM dual; END;; DELETE FROM MDSYS.OGIS_GEOMETRY_COLUMNS WHERE F_TABLE_SCHEMA = 'dbo' AND F_TABLE_NAME = 'TEST1' AND F_GEOMETRY_COLUMN = 'geom'; INSERT INTO MDSYS.OGIS_GEOMETRY_COLUMNS (F_TABLE_SCHEMA, F_TABLE_NAME, F_GEOMETRY_COLUMN, GEOMETRY_TYPE) VALUES ('dbo', 'TEST1', 'geom', 0)", |
|
223 |
sqlbuilder.toString() |
|
224 |
); |
|
225 |
assertEquals( |
|
226 |
"[]", |
|
227 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
228 |
); |
|
229 |
assertEquals( |
|
230 |
"[]", |
|
231 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
232 |
); |
|
233 |
} |
|
234 |
|
|
235 |
public void testDropTable() throws Exception { |
|
236 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
237 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
238 |
|
|
239 |
sqlbuilder.drop_table().table().database("master").schema("dbo").name("test1"); |
|
240 |
|
|
241 |
// DROP TABLE "test1" |
|
242 |
|
|
243 |
System.out.println("# Test:: testDropTable"); |
|
244 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
245 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
246 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
247 |
assertEquals( |
|
248 |
"DROP TABLE \"dbo\".\"test1\"", |
|
249 |
sqlbuilder.toString() |
|
250 |
); |
|
251 |
assertEquals( |
|
252 |
"[]", |
|
253 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
254 |
); |
|
255 |
assertEquals( |
|
256 |
"[]", |
|
257 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
258 |
); |
|
259 |
} |
|
260 |
|
|
261 |
public void testFetchFeatureProviderByReference() throws Exception { |
|
262 |
SQLBuilder sqlbuilder = new SQLBuilderBase(); |
|
263 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
264 |
|
|
265 |
String value = "yoyo"; |
|
266 |
sqlbuilder.select().column().name("name"); |
|
267 |
sqlbuilder.select().column().name("id"); |
|
268 |
sqlbuilder.select().column().name("geom").as_geometry(); |
|
269 |
sqlbuilder.select().from().table().database("master").schema("dbo").name("test1"); |
|
270 |
sqlbuilder.select().where().set( |
|
271 |
expbuilder.eq( |
|
272 |
expbuilder.column("name"), |
|
273 |
expbuilder.parameter(value).as_constant() |
|
274 |
) |
|
275 |
); |
|
276 |
sqlbuilder.select().limit(1); |
|
277 |
|
|
278 |
// SELECT "name", "id", ST_AsBinary("geom") FROM "master"."dbo"."test1" WHERE ( ("name") = (?) ) LIMIT 1 |
|
279 |
|
|
280 |
System.out.println("# Test:: testFetchFeatureProviderByReference"); |
|
281 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
282 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
283 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
284 |
assertEquals( |
|
285 |
"SELECT \"name\", \"id\", ST_AsBinary(\"geom\") FROM \"master\".\"dbo\".\"test1\" WHERE ( (\"name\") = (?) ) LIMIT 1", |
|
286 |
sqlbuilder.toString() |
|
287 |
); |
|
288 |
assertEquals( |
|
289 |
"[geom, id, name]", |
|
290 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
291 |
); |
|
292 |
assertEquals( |
|
293 |
"['yoyo']", |
|
294 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
295 |
); |
|
296 |
} |
|
297 |
|
|
298 |
public void testFetchFeatureType() throws Exception { |
|
299 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
300 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
301 |
|
|
302 |
sqlbuilder.select().column().all(); |
|
303 |
sqlbuilder.select().from().table().database("master").schema("dbo").name("test1"); |
|
304 |
sqlbuilder.select().limit(1); |
|
305 |
|
|
306 |
System.out.println("# Test:: testFetchFeatureType"); |
|
307 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
308 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
309 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
310 |
|
|
311 |
//# Test:: testFetchFeatureType |
|
312 |
//# SQL:: SELECT * FROM "test1" LIMIT 1 |
|
313 |
//# Variables:: [] |
|
314 |
//# Parametros:: [] |
|
315 |
|
|
316 |
assertEquals( |
|
317 |
"SELECT * FROM \"dbo\".\"test1\" WHERE ROWNUM <= 1", |
|
318 |
sqlbuilder.toString() |
|
319 |
); |
|
320 |
assertEquals( |
|
321 |
"[]", |
|
322 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
323 |
); |
|
324 |
assertEquals( |
|
325 |
"[]", |
|
326 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
327 |
); |
|
328 |
} |
|
329 |
|
|
330 |
public void testPerformDeletes() throws Exception { |
|
331 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
332 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
333 |
|
|
334 |
sqlbuilder.delete().table().database("master").schema("dbo").name("test1"); |
|
335 |
sqlbuilder.delete().where().set( |
|
336 |
expbuilder.eq( |
|
337 |
expbuilder.column("id1"), |
|
338 |
expbuilder.parameter("id1").as_variable() |
|
339 |
) |
|
340 |
); |
|
341 |
sqlbuilder.delete().where().and( |
|
342 |
expbuilder.eq( |
|
343 |
expbuilder.column("id2"), |
|
344 |
expbuilder.parameter("id2").as_variable() |
|
345 |
) |
|
346 |
); |
|
347 |
|
|
348 |
System.out.println("# Test:: testPerformDeletes"); |
|
349 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
350 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
351 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
352 |
assertEquals( |
|
353 |
"DELETE FROM \"dbo\".\"test1\" WHERE ( (( (\"id1\") = (?) )) AND (( (\"id2\") = (?) )) )", |
|
354 |
sqlbuilder.toString() |
|
355 |
); |
|
356 |
assertEquals( |
|
357 |
"[id1, id2]", |
|
358 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
359 |
); |
|
360 |
assertEquals( |
|
361 |
"[\"id1\", \"id2\"]", |
|
362 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
363 |
); |
|
364 |
} |
|
365 |
|
|
366 |
public void testPerformInserts1() throws Exception { |
|
367 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
|
368 |
|
|
369 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
370 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
371 |
|
|
372 |
sqlbuilder.insert().table().database("master").schema("dbo").name("test1"); |
|
373 |
sqlbuilder.insert().column().name("id").with_value(expbuilder.parameter("id")); |
|
374 |
sqlbuilder.insert().column().name("name").with_value(expbuilder.parameter("name")); |
|
375 |
sqlbuilder.insert().column().name("geom").with_value(expbuilder.parameter("geom").as_geometry_variable().srs(proj)); |
|
376 |
|
|
377 |
System.out.println("# Test:: testPerformInserts1"); |
|
378 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
379 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
380 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
381 |
assertEquals( |
|
382 |
"INSERT INTO \"dbo\".\"test1\" ( \"id\", \"name\", \"geom\" ) VALUES ( ?, ?, NVL2((?),SDO_GEOMETRY((?), (4326)),NULL) )", |
|
383 |
sqlbuilder.toString() |
|
384 |
); |
|
385 |
assertEquals( |
|
386 |
"[geom, id, name]", |
|
387 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
388 |
); |
|
389 |
assertEquals( |
|
390 |
"[\"id\", \"name\", \"geom\", \"geom\"]", |
|
391 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
392 |
); |
|
393 |
} |
|
394 |
|
|
395 |
public void testPerformInserts2() throws Exception { |
|
396 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
|
397 |
|
|
398 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
399 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
400 |
|
|
401 |
sqlbuilder.insert().table().database("master").schema("dbo").name("test1"); |
|
402 |
sqlbuilder.insert().column().name("id").with_value(expbuilder.parameter("id")); |
|
403 |
sqlbuilder.insert().column().name("name").with_value(expbuilder.parameter("name")); |
|
404 |
sqlbuilder.insert().column().name("geom").with_value(expbuilder.parameter("geom").as_geometry_variable().srs(proj)); |
|
405 |
|
|
406 |
System.out.println("# Test:: testPerformInserts2"); |
|
407 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
408 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
409 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
410 |
assertEquals( |
|
411 |
"INSERT INTO \"dbo\".\"test1\" ( \"id\", \"name\", \"geom\" ) VALUES ( ?, ?, NVL2((?),SDO_GEOMETRY((?), (4326)),NULL) )", |
|
412 |
sqlbuilder.toString() |
|
413 |
); |
|
414 |
assertEquals( |
|
415 |
"[geom, id, name]", |
|
416 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
417 |
); |
|
418 |
assertEquals( |
|
419 |
"[\"id\", \"name\", \"geom\", \"geom\"]", |
|
420 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
421 |
); |
|
422 |
} |
|
423 |
|
|
424 |
public void testPerformUpdates1() throws Exception { |
|
425 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
|
426 |
|
|
427 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
428 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
429 |
|
|
430 |
sqlbuilder.update().table().database("master").schema("dbo").name("test1"); |
|
431 |
sqlbuilder.update().where().set( |
|
432 |
expbuilder.eq( |
|
433 |
expbuilder.column("id"), |
|
434 |
expbuilder.parameter("id").as_variable() |
|
435 |
) |
|
436 |
); |
|
437 |
sqlbuilder.update().column().name("name").with_value(expbuilder.parameter("name")); |
|
438 |
sqlbuilder.update().column().name("geom").with_value( |
|
439 |
expbuilder.parameter("geom").as_geometry_variable().srs(proj) |
|
440 |
); |
|
441 |
|
|
442 |
System.out.println("# Test:: testPerformUpdates"); |
|
443 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
444 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
445 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
446 |
assertEquals( |
|
447 |
"UPDATE \"dbo\".\"test1\" SET \"name\" = ?, \"geom\" = NVL2((?),SDO_GEOMETRY((?), (4326)),NULL) WHERE ( (\"id\") = (?) )", |
|
448 |
sqlbuilder.toString() |
|
449 |
); |
|
450 |
assertEquals( |
|
451 |
"[geom, id, name]", |
|
452 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
453 |
); |
|
454 |
assertEquals( |
|
455 |
"[\"name\", \"geom\", \"geom\", \"id\"]", |
|
456 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
457 |
); |
|
458 |
} |
|
459 |
|
|
460 |
public void testPerformUpdates2() throws Exception { |
|
461 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
|
462 |
|
|
463 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
464 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
465 |
|
|
466 |
sqlbuilder.update().table().database("master").schema("dbo").name("test1"); |
|
467 |
sqlbuilder.update().where().set( |
|
468 |
expbuilder.eq( |
|
469 |
expbuilder.column("id"), |
|
470 |
expbuilder.parameter("id").as_variable() |
|
471 |
) |
|
472 |
); |
|
473 |
sqlbuilder.update().column().name("name").with_value(expbuilder.parameter("name")); |
|
474 |
sqlbuilder.update().column().name("geom").with_value( |
|
475 |
expbuilder.parameter("geom").as_geometry_variable() |
|
476 |
.srs(expbuilder.parameter().value(proj)) |
|
477 |
); |
|
478 |
|
|
479 |
System.out.println("# Test:: testPerformUpdates"); |
|
480 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
481 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
482 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
483 |
assertEquals( |
|
484 |
"UPDATE \"dbo\".\"test1\" SET \"name\" = ?, \"geom\" = NVL2((?),SDO_GEOMETRY((?), (?)),NULL) WHERE ( (\"id\") = (?) )", |
|
485 |
sqlbuilder.toString() |
|
486 |
); |
|
487 |
|
|
488 |
assertEquals( |
|
489 |
"[geom, id, name]", |
|
490 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
491 |
); |
|
492 |
assertEquals( |
|
493 |
"[\"name\", \"geom\", \"geom\", 4326, \"id\"]", |
|
494 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
495 |
); |
|
496 |
} |
|
497 |
|
|
498 |
public void testGrant1() throws Exception { |
|
499 |
|
|
500 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
501 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
502 |
|
|
503 |
sqlbuilder.grant().table().database("master").schema("dbo").name("test1"); |
|
504 |
sqlbuilder.grant().role("prueba").select().insert().update(); |
|
505 |
sqlbuilder.grant().role("gis").all(); |
|
506 |
|
|
507 |
|
|
508 |
System.out.println("# Test:: testGrant1"); |
|
509 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
510 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
511 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
512 |
assertEquals( |
|
513 |
"", |
|
514 |
sqlbuilder.toString() |
|
515 |
); |
|
516 |
assertEquals( |
|
517 |
"[]", |
|
518 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
519 |
); |
|
520 |
assertEquals( |
|
521 |
"[]", |
|
522 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
523 |
); |
|
524 |
} |
|
525 |
|
|
526 |
public void testGrant2() throws Exception { |
|
527 |
|
|
528 |
SQLBuilder sqlbuilder = new SQLBuilderBase(); |
|
529 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
530 |
|
|
531 |
sqlbuilder.grant().table().database("master").schema("dbo").name("test1"); |
|
532 |
sqlbuilder.grant().role("prueba").privilege(Privilege.SELECT) |
|
533 |
.privilege(Privilege.INSERT) |
|
534 |
.privilege(Privilege.UPDATE); |
|
535 |
sqlbuilder.grant().role("gis").privilege(Privilege.ALL); |
|
536 |
|
|
537 |
|
|
538 |
System.out.println("# Test:: testGrant2"); |
|
539 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
540 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
541 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
542 |
assertEquals( |
|
543 |
"", |
|
544 |
sqlbuilder.toString() |
|
545 |
); |
|
546 |
assertEquals( |
|
547 |
"[]", |
|
548 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
549 |
); |
|
550 |
assertEquals( |
|
551 |
"[]", |
|
552 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
553 |
); |
|
554 |
} |
|
555 |
|
|
556 |
public void testSelect() throws Exception { |
|
557 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
558 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
559 |
|
|
560 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
|
561 |
|
|
562 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
563 |
Polygon limit = geometryManager.createPolygon(Geometry.SUBTYPES.GEOM2D); |
|
564 |
limit.addVertex(0, 0); |
|
565 |
limit.addVertex(0, 100); |
|
566 |
limit.addVertex(100, 100); |
|
567 |
limit.addVertex(100, 0); |
|
568 |
limit.addVertex(0, 0); |
|
569 |
|
|
570 |
sqlbuilder.select().column().value(expbuilder.parameter("Geometry").as_geometry_variable().srs(proj)); |
|
571 |
sqlbuilder.select().column().value(expbuilder.parameter("ID").as_variable()); |
|
572 |
sqlbuilder.select().column().value(expbuilder.constant(limit)); |
|
573 |
sqlbuilder.select().from().table().database("master").schema("dbo").name("test1"); |
|
574 |
|
|
575 |
System.out.println("# Test:: testSelect"); |
|
576 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
577 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
578 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
579 |
|
|
580 |
//# Test:: testCount |
|
581 |
//# SQL:: SELECT NVL2((?),SDO_GEOMETRY((?).Get_WKB(), (?)),NULL), "ID", SDO_GEOMETRY((TO_BLOB(HEXTORAW('000000000300000001000000050000000000000000000000000000000000000000000000004059000000000000405900000000000040590000000000004059000000000000000000000000000000000000000000000000000000000000'))), (4326)) FROM "dbo"."test1" |
|
582 |
//# Variables:: [] |
|
583 |
//# Parametros:: ["Geometry", "Geometry", "ID"] |
|
584 |
|
|
585 |
assertEquals( |
|
586 |
"SELECT NVL2((?),SDO_GEOMETRY((?), (4326)),NULL), ?, SDO_GEOMETRY((TO_BLOB(HEXTORAW('000000000300000001000000050000000000000000000000000000000000000000000000004059000000000000405900000000000040590000000000004059000000000000000000000000000000000000000000000000000000000000'))), (0)) FROM \"dbo\".\"test1\"", |
|
587 |
sqlbuilder.toString() |
|
588 |
); |
|
589 |
assertEquals( |
|
590 |
"[]", |
|
591 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
592 |
); |
|
593 |
assertEquals( |
|
594 |
"[\"Geometry\", \"Geometry\", \"ID\"]", |
|
595 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
596 |
); |
|
597 |
} |
|
598 |
|
|
599 |
|
|
600 |
public void testSelectIntersect() throws Exception { |
|
601 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
|
602 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
|
603 |
|
|
604 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
|
605 |
|
|
606 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
|
607 |
Polygon envelope = geometryManager.createPolygon(Geometry.SUBTYPES.GEOM2D); |
|
608 |
envelope.addVertex(0, 0); |
|
609 |
envelope.addVertex(0, 100); |
|
610 |
envelope.addVertex(100, 100); |
|
611 |
envelope.addVertex(100, 0); |
|
612 |
envelope.addVertex(0, 0); |
|
613 |
|
|
614 |
GeometryExpressionBuilderHelper.GeometryParameter column = expbuilder.parameter("Geometry").as_geometry_variable().srs(proj); |
|
615 |
|
|
616 |
sqlbuilder.select().column().value(column); |
|
617 |
sqlbuilder.select().column().value(expbuilder.parameter("ID").as_variable()); |
|
618 |
sqlbuilder.select().from().table().database("master").schema("dbo").name("test1"); |
|
619 |
sqlbuilder.select().where().set( |
|
620 |
expbuilder.not_is_null(column)).and( |
|
621 |
expbuilder.ST_Intersects( |
|
622 |
column, |
|
623 |
expbuilder.geometry(envelope, proj) |
|
624 |
) |
|
625 |
); |
|
626 |
|
|
627 |
System.out.println("# Test:: testSelect"); |
|
628 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
|
629 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
|
630 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
|
631 |
|
|
632 |
//# Test:: testCount |
|
633 |
//# SQL:: SELECT NVL2((?),SDO_GEOMETRY((?).Get_WKB(), (?)),NULL), "ID", SDO_GEOMETRY((TO_BLOB(HEXTORAW('000000000300000001000000050000000000000000000000000000000000000000000000004059000000000000405900000000000040590000000000004059000000000000000000000000000000000000000000000000000000000000'))), (4326)) FROM "dbo"."test1" |
|
634 |
//# Variables:: [] |
|
635 |
//# Parametros:: ["Geometry", "Geometry", "ID"] |
|
636 |
|
|
637 |
assertEquals( |
|
638 |
"SELECT NVL2((?),SDO_GEOMETRY((?), (4326)),NULL), ? FROM \"dbo\".\"test1\" WHERE ( (( (NVL2((?),SDO_GEOMETRY((?), (4326)),NULL)) IS NOT NULL )) AND ((SDO_RELATE(NVL2((?),SDO_GEOMETRY((?), (4326)),NULL), SDO_GEOMETRY((TO_BLOB(HEXTORAW('000000000300000001000000050000000000000000000000000000000000000000000000004059000000000000405900000000000040590000000000004059000000000000000000000000000000000000000000000000000000000000'))), (4326)), 'mask=ANYINTERACT') = 'TRUE')) )", |
|
639 |
sqlbuilder.toString() |
|
640 |
); |
|
641 |
assertEquals( |
|
642 |
"[]", |
|
643 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
|
644 |
); |
|
645 |
assertEquals( |
|
646 |
"[\"Geometry\", \"Geometry\", \"ID\", \"Geometry\", \"Geometry\", \"Geometry\", \"Geometry\"]", |
|
647 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
|
648 |
); |
|
649 |
} |
|
650 |
|
|
651 |
|
|
652 |
} |
org.gvsig.oracle/tags/org.gvsig.oracle-2.0.49/org.gvsig.oracle.provider/src/test/java/org/gvsig/oracle/dal/TestUtils.java | ||
---|---|---|
1 |
package org.gvsig.oracle.dal; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.FileInputStream; |
|
5 |
import java.io.FileOutputStream; |
|
6 |
import java.net.URL; |
|
7 |
import java.util.ArrayList; |
|
8 |
import java.util.List; |
|
9 |
import java.util.Properties; |
|
10 |
import org.apache.commons.io.FileUtils; |
|
11 |
import org.apache.commons.io.FilenameUtils; |
|
12 |
import org.apache.commons.lang3.StringUtils; |
|
13 |
import org.gvsig.fmap.dal.DALLocator; |
|
14 |
import org.gvsig.fmap.dal.DataManager; |
|
15 |
import org.gvsig.fmap.dal.DataStore; |
|
16 |
import org.gvsig.fmap.dal.feature.Feature; |
|
17 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
18 |
import org.gvsig.fmap.dal.feature.impl.DefaultFeature; |
|
19 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
|
20 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
|
21 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
|
22 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
|
23 |
import org.gvsig.fmap.dal.store.jdbc2.spi.FakeConnectionProvider; |
|
24 |
import org.gvsig.tools.resourcesstorage.ResourcesStorage; |
|
25 |
import org.slf4j.Logger; |
|
26 |
import org.slf4j.LoggerFactory; |
|
27 |
|
|
28 |
public class TestUtils { |
|
29 |
|
|
30 |
public static final Logger LOGGER = LoggerFactory.getLogger(TestUtils.class); |
|
31 |
|
|
32 |
public static final String PROVIDER_NAME = OracleLibrary.NAME; |
|
33 |
public static final String TEST_USER = "dba"; |
|
34 |
public static final String TEST_SCHEMA = "public"; |
|
35 |
public static final String TEST_DB_NAME = "dbtest"; |
|
36 |
|
|
37 |
public static OracleConnectionParameters buildDBConnection() throws Exception { |
|
38 |
DataManager dataManager = DALLocator.getDataManager(); |
|
39 |
OracleConnectionParameters conn = (OracleConnectionParameters) |
|
40 |
dataManager.createServerExplorerParameters(OracleLibrary.NAME); |
|
41 |
|
|
42 |
Properties p = new Properties(); |
|
43 |
File userDirectory = FileUtils.getUserDirectory(); |
|
44 |
String properties = FilenameUtils.concat( |
|
45 |
userDirectory.getCanonicalPath(), |
|
46 |
".gvSIG_Oracle_testDBConnection.properties"); |
|
47 |
File fileProperties = new File(properties); |
|
48 |
if(!fileProperties.exists()) { |
|
49 |
p.setProperty("host", "127.0.0.1"); |
|
50 |
p.setProperty("port", "1521"); |
|
51 |
p.setProperty("dbuser", TEST_USER); |
|
52 |
p.setProperty("schema", TEST_SCHEMA); |
|
53 |
p.setProperty("password", "PASSWD"); |
|
54 |
p.setProperty("dbname", TEST_DB_NAME); |
|
55 |
p.setProperty("mode", "service"); |
|
56 |
p.store(new FileOutputStream(properties), "Oracle test DB connection"); |
|
57 |
} else { |
|
58 |
FileInputStream fis = new FileInputStream(properties); |
|
59 |
p.load(fis); |
|
60 |
} |
|
61 |
|
|
62 |
conn.setDynValue("host", p.getProperty("host", null)); |
|
63 |
conn.setDynValue("port", p.getProperty("port", null)); |
|
64 |
conn.setDynValue("dbuser", p.getProperty("dbuser", null)); |
|
65 |
conn.setDynValue("schema", p.getProperty("schema", null)); |
|
66 |
conn.setDynValue("password", p.getProperty("password", null)); |
|
67 |
conn.setDynValue("dbname", p.getProperty("dbname", null)); |
|
68 |
conn.setDynValue("mode", p.getProperty("mode", null)); |
|
69 |
|
|
70 |
return conn; |
|
71 |
} |
|
72 |
|
|
73 |
public static JDBCServerExplorer openServerExplorer() throws Exception { |
|
74 |
DataManager dataManager = DALLocator.getDataManager(); |
|
75 |
OracleConnectionParameters conn = buildDBConnection(); |
|
76 |
JDBCServerExplorer explorer = (JDBCServerExplorer) dataManager.openServerExplorer( |
|
77 |
PROVIDER_NAME, conn |
|
78 |
); |
|
79 |
return explorer; |
|
80 |
} |
|
81 |
|
|
82 |
public static File getTargetFolder() throws Exception { |
|
83 |
URL url = TestUtils.class.getResource("/"); |
|
84 |
File x = new File(url.toURI()); |
|
85 |
File target = x.getParentFile(); |
|
86 |
return target; |
|
87 |
} |
|
88 |
|
|
89 |
public static File getResource(String name) throws Exception { |
|
90 |
File x = new File(getTargetFolder(), name); |
|
91 |
return x; |
|
92 |
} |
|
93 |
|
|
94 |
public static File getResourceAsFile(String pathname) throws Exception { |
|
95 |
URL url = TestUtils.class.getResource(pathname); |
|
96 |
File x = new File(url.toURI()); |
|
97 |
return x; |
|
98 |
} |
|
99 |
|
|
100 |
public static void removeDALResource(String tableName) throws Exception { |
|
101 |
// OracleConnectionParameters connection = buildDBConnection(dbname); |
|
102 |
// DatabaseWorkspaceManager workspace = DALLocator.getDataManager().createDatabaseWorkspaceManager( |
|
103 |
// (DataServerExplorerParameters) connection |
|
104 |
// ); |
|
105 |
|
|
106 |
JDBCServerExplorer explorer = openServerExplorer(); |
|
107 |
JDBCStoreParameters params = explorer.get(tableName); |
|
108 |
|
|
109 |
ResourcesStorage resources = explorer.getResourcesStorage(params); |
|
110 |
|
|
111 |
resources.remove("dal"); |
|
112 |
} |
|
113 |
|
|
114 |
public static FeatureStore openSourceStore1() throws Exception { |
|
115 |
DataManager dataManager = DALLocator.getDataManager(); |
|
116 |
File f = getResourceAsFile("/org/gvsig/oracle/dal/testCreateSource1.csv"); |
|
117 |
FeatureStore store = (FeatureStore) dataManager.openStore( |
|
118 |
DataStore.CSV_PROVIDER_NAME, |
|
119 |
"file=",f, |
|
120 |
"automaticTypesDetection=", false, |
|
121 |
"locale=","en" |
|
122 |
); |
|
123 |
return store; |
|
124 |
} |
|
125 |
|
|
126 |
public static FeatureStore openSourceStoreShort() throws Exception { |
|
127 |
DataManager dataManager = DALLocator.getDataManager(); |
|
128 |
File f = getResourceAsFile("/org/gvsig/oracle/dal/testCreateSource_short.csv"); |
|
129 |
FeatureStore store = (FeatureStore) dataManager.openStore( |
|
130 |
DataStore.CSV_PROVIDER_NAME, |
|
131 |
"file=",f, |
|
132 |
"automaticTypesDetection=", false, |
|
133 |
"locale=","en" |
|
134 |
); |
|
135 |
return store; |
|
136 |
} |
|
137 |
|
|
138 |
|
|
139 |
public static List<String> getSQLs(String name) throws Exception { |
|
140 |
File f = getResourceAsFile("/org/gvsig/oracle/dal/"+name); |
|
141 |
List<String> SQLs = new ArrayList<>(); |
|
142 |
List<String> lines = FileUtils.readLines(f); |
|
143 |
StringBuilder sb = new StringBuilder(); |
|
144 |
for (String line : lines) { |
|
145 |
line = StringUtils.stripStart(line, null); |
|
146 |
if( line.startsWith("--") ) { |
|
147 |
continue; |
|
148 |
} |
|
149 |
if( line.endsWith(";") ) { |
|
150 |
sb.append(line.substring(0, line.length()-1)); |
|
151 |
SQLs.add(sb.toString()); |
|
152 |
sb.setLength(0); |
|
153 |
} else { |
|
154 |
sb.append(line); |
|
155 |
} |
|
156 |
} |
|
157 |
return SQLs; |
|
158 |
} |
|
159 |
|
|
160 |
public static FeatureProvider getFeatureProvider(Feature feature) { |
|
161 |
return ((DefaultFeature)feature).getData(); |
|
162 |
} |
|
163 |
|
|
164 |
public static JDBCHelper getJDBCHelper() { |
|
165 |
return getJDBCHelper(TEST_SCHEMA, TEST_USER); |
|
166 |
} |
|
167 |
|
|
168 |
public static JDBCHelper getJDBCHelper(String schema, String user) { |
|
169 |
OracleExplorerParameters params = new OracleExplorerParameters(); |
|
170 |
params.setSchema(schema); |
|
171 |
params.setUser(user); |
|
172 |
params.setDBName(TEST_DB_NAME); |
|
173 |
OracleHelper helper = new OracleHelper(params, new FakeConnectionProvider(params)); |
|
174 |
return helper; |
|
175 |
} |
|
176 |
|
|
177 |
} |
org.gvsig.oracle/tags/org.gvsig.oracle-2.0.49/org.gvsig.oracle.provider/src/test/java/org/gvsig/oracle/dal/TestCreate.java | ||
---|---|---|
1 |
package org.gvsig.oracle.dal; |
|
2 |
|
|
3 |
import java.util.Date; |
|
4 |
import java.util.List; |
|
5 |
import junit.framework.TestCase; |
|
6 |
import static junit.framework.TestCase.assertEquals; |
|
7 |
import org.gvsig.fmap.dal.DALLocator; |
|
8 |
import org.gvsig.fmap.dal.DataManager; |
|
9 |
import org.gvsig.fmap.dal.DataTypes; |
|
10 |
import org.gvsig.fmap.dal.exception.ValidateDataParametersException; |
|
11 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
|
12 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
|
13 |
import org.gvsig.fmap.dal.feature.Feature; |
|
14 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
|
15 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
16 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
17 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
|
18 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
|
19 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCServerExplorer; |
|
20 |
import org.gvsig.fmap.geom.Geometry; |
|
21 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
22 |
import org.slf4j.Logger; |
|
23 |
import org.slf4j.LoggerFactory; |
|
24 |
|
|
25 |
public class TestCreate extends TestCase { |
|
26 |
|
|
27 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestCreate.class); |
|
28 |
|
|
29 |
public static final String DBNAME = "testCreate"; |
|
30 |
|
|
31 |
public static final int ZERO_DEFAULT_DISPLAY_SIZE = 0; |
|
32 |
public static final int BYTE_DEFAULT_DISPLAY_SIZE = 4; |
|
33 |
public static final int FLOAT_DEFAULT_DISPLAY_SIZE = 4; |
|
34 |
public static final int DOUBLE_DEFAULT_DISPLAY_SIZE = 8; |
|
35 |
|
|
36 |
public TestCreate(String testName) { |
|
37 |
super(testName); |
|
38 |
} |
|
39 |
|
|
40 |
@Override |
|
41 |
protected void setUp() throws Exception { |
|
42 |
super.setUp(); |
|
43 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
protected void tearDown() throws Exception { |
|
48 |
super.tearDown(); |
|
49 |
} |
|
50 |
|
|
51 |
// TODO add test methods here. The name must begin with 'test'. For example: |
|
52 |
// public void testHello() {} |
|
53 |
protected String getProviderName() { |
|
54 |
return OracleLibrary.NAME; |
|
55 |
} |
|
56 |
|
|
57 |
protected String getTargetName() { |
|
58 |
return "testCreateTarget6".toUpperCase(); |
|
59 |
} |
|
60 |
|
|
61 |
protected FeatureStore openTargetStore1(JDBCServerExplorer explorer) throws Exception { |
|
62 |
JDBCStoreParameters params = explorer.get(getTargetName()); |
|
63 |
|
|
64 |
DataManager dataManager = DALLocator.getDataManager(); |
|
65 |
FeatureStore store; |
|
66 |
try { |
|
67 |
store = (FeatureStore) dataManager.openStore( |
|
68 |
getProviderName(), |
|
69 |
params |
|
70 |
); |
|
71 |
} catch (ValidateDataParametersException ex) { |
|
72 |
LOGGER.warn(ex.getLocalizedMessageStack()); |
|
73 |
throw ex; |
|
74 |
} |
|
75 |
return store; |
|
76 |
} |
|
77 |
|
|
78 |
protected void createFrom(JDBCServerExplorer explorer, FeatureStore sourceStore) throws Exception { |
|
79 |
NewFeatureStoreParameters params = (NewFeatureStoreParameters) explorer.getAddParameters( |
|
80 |
getTargetName() |
|
81 |
); |
|
82 |
EditableFeatureType ft = params.getDefaultFeatureType(); |
|
83 |
ft.addAll(sourceStore.getDefaultFeatureType()); |
|
84 |
explorer.add(getProviderName(), params, true); |
|
85 |
} |
|
86 |
|
|
87 |
protected void checkTypes(JDBCServerExplorer explorer, FeatureType sourceFeatureType, boolean withDalResource) throws Exception { |
|
88 |
FeatureStore targetStore = openTargetStore1(explorer); |
|
89 |
FeatureType targetFeatureType = targetStore.getDefaultFeatureType(); |
|
90 |
|
|
91 |
assertEquals("Feature type size", sourceFeatureType.size(), targetFeatureType.size()); |
|
92 |
for (int i = 0; i < sourceFeatureType.size(); i++) { |
|
93 |
FeatureAttributeDescriptor sourceAttr = sourceFeatureType.get(i); |
|
94 |
FeatureAttributeDescriptor targetAttr = targetFeatureType.get(i); |
|
95 |
if (withDalResource) { |
|
96 |
if (sourceAttr.getType() == DataTypes.GEOMETRY) { |
|
97 |
assertEquals( |
|
98 |
String.format("Field %s name mismatch", sourceAttr.getName()), |
|
99 |
sourceAttr.getName().toUpperCase(), |
|
100 |
targetAttr.getName() |
|
101 |
); |
|
102 |
} else { |
|
103 |
assertEquals( |
|
104 |
String.format("Field %s name mismatch", sourceAttr.getName()), |
|
105 |
sourceAttr.getName(), |
|
106 |
targetAttr.getName() |
|
107 |
); |
|
108 |
} |
|
109 |
|
|
110 |
assertEquals( |
|
111 |
String.format("Field %s type mismatch", sourceAttr.getName()), |
|
112 |
sourceAttr.getDataTypeName(), |
|
113 |
targetAttr.getDataTypeName() |
|
114 |
); |
|
115 |
assertEquals( |
|
116 |
String.format("Field %s display size mismatch", sourceAttr.getName()), |
|
117 |
sourceAttr.getDisplaySize(), |
|
118 |
targetAttr.getDisplaySize() |
|
119 |
); |
|
120 |
assertEquals( |
|
121 |
String.format("Field %s size mismatch", sourceAttr.getName()), |
|
122 |
sourceAttr.getSize(), |
|
123 |
targetAttr.getSize() |
|
124 |
); |
|
125 |
assertEquals( |
|
126 |
String.format("Field %s precision mismatch", sourceAttr.getName()), |
|
127 |
sourceAttr.getPrecision(), |
|
128 |
targetAttr.getPrecision() |
|
129 |
); |
|
130 |
assertEquals( |
|
131 |
String.format("Field %s scale mismatch", sourceAttr.getName()), |
|
132 |
sourceAttr.getScale(), |
|
133 |
targetAttr.getScale() |
|
134 |
); |
|
135 |
|
|
136 |
if (sourceAttr.getType() == DataTypes.GEOMETRY) { |
|
137 |
assertEquals( |
|
138 |
String.format("Field %s geometry type mismatch", sourceAttr.getName()), |
|
139 |
sourceAttr.getGeomType().getName(), |
|
140 |
targetAttr.getGeomType().getName() |
|
141 |
); |
|
142 |
assertEquals( |
|
143 |
String.format("Field %s geometry SRS mismatch", sourceAttr.getName()), |
|
144 |
sourceAttr.getSRS().getAbrev(), |
|
145 |
targetAttr.getSRS().getAbrev() |
|
146 |
); |
|
147 |
|
|
148 |
} |
|
149 |
|
|
150 |
} else { |
|
151 |
switch (sourceAttr.getType()) { |
|
152 |
case DataTypes.BYTE: |
|
153 |
assertEquals( |
|
154 |
String.format("Field %s name mismatch", sourceAttr.getName()), |
|
155 |
sourceAttr.getName(), |
|
156 |
targetAttr.getName() |
|
157 |
); |
|
158 |
assertEquals( |
|
159 |
String.format("Field %s type mismatch", sourceAttr.getName()), |
|
160 |
DataTypes.DECIMAL, |
|
161 |
targetAttr.getDataType().getType() |
|
162 |
); |
|
163 |
assertEquals( |
|
164 |
String.format("Field %s display size mismatch", sourceAttr.getName()), |
|
165 |
BYTE_DEFAULT_DISPLAY_SIZE, |
|
166 |
targetAttr.getDisplaySize() |
|
167 |
); |
|
168 |
assertEquals( |
|
169 |
String.format("Field %s size mismatch", sourceAttr.getName()), |
|
170 |
sourceAttr.getSize(), |
|
171 |
targetAttr.getSize() |
|
172 |
); |
|
173 |
assertEquals( |
|
174 |
String.format("Field %s precision mismatch", sourceAttr.getName()), |
|
175 |
sourceAttr.getPrecision(), |
|
176 |
targetAttr.getPrecision() |
|
177 |
); |
|
178 |
assertEquals( |
|
179 |
String.format("Field %s scale mismatch", sourceAttr.getName()), |
|
180 |
sourceAttr.getScale(), |
|
181 |
targetAttr.getScale() |
|
182 |
); |
|
183 |
break; |
|
184 |
case DataTypes.BOOLEAN: |
|
185 |
assertEquals( |
|
186 |
String.format("Field %s name mismatch", sourceAttr.getName()), |
|
187 |
sourceAttr.getName(), |
|
188 |
targetAttr.getName() |
|
189 |
); |
|
190 |
assertEquals( |
|
191 |
String.format("Field %s type mismatch", sourceAttr.getName()), |
|
192 |
DataTypes.STRING_NAME, |
|
193 |
targetAttr.getDataTypeName() |
|
194 |
); |
|
195 |
assertEquals(String.format("Field %s display size mismatch", sourceAttr.getName()), |
|
196 |
ZERO_DEFAULT_DISPLAY_SIZE, |
|
197 |
targetAttr.getDisplaySize() |
|
198 |
); |
|
199 |
assertEquals(String.format("Field %s size mismatch", sourceAttr.getName()), |
|
200 |
OracleSQLBuilder.BOOLEAN_STRING_DEFAULT_LENGTH, |
|
201 |
targetAttr.getSize() |
|
202 |
); |
|
203 |
assertEquals( |
|
204 |
String.format("Field %s precision mismatch", sourceAttr.getName()), |
|
205 |
sourceAttr.getPrecision(), |
|
206 |
targetAttr.getPrecision() |
|
207 |
); |
|
208 |
assertEquals( |
|
209 |
String.format("Field %s scale mismatch", sourceAttr.getName()), |
|
210 |
sourceAttr.getScale(), |
|
211 |
targetAttr.getScale() |
|
212 |
); |
|
213 |
break; |
|
214 |
case DataTypes.STRING: |
|
215 |
assertEquals( |
|
216 |
String.format("Field %s name mismatch", sourceAttr.getName()), |
|
217 |
sourceAttr.getName(), |
|
218 |
targetAttr.getName() |
|
219 |
); |
|
220 |
assertEquals( |
|
221 |
String.format("Field %s type mismatch", sourceAttr.getName()), |
|
222 |
sourceAttr.getDataTypeName(), |
|
223 |
targetAttr.getDataTypeName() |
|
224 |
); |
|
225 |
assertEquals(String.format("Field %s display size mismatch", sourceAttr.getName()), |
|
226 |
ZERO_DEFAULT_DISPLAY_SIZE, |
|
227 |
targetAttr.getDisplaySize() |
|
228 |
); |
|
229 |
assertEquals( |
|
230 |
String.format("Field %s size mismatch", sourceAttr.getName()), |
|
231 |
sourceAttr.getSize(), |
|
232 |
targetAttr.getSize() |
|
233 |
); |
|
234 |
assertEquals( |
|
235 |
String.format("Field %s precision mismatch", sourceAttr.getName()), |
|
236 |
sourceAttr.getPrecision(), |
|
237 |
targetAttr.getPrecision() |
|
238 |
); |
|
239 |
assertEquals( |
|
240 |
String.format("Field %s scale mismatch", sourceAttr.getName()), |
|
241 |
sourceAttr.getScale(), |
|
242 |
targetAttr.getScale() |
|
243 |
); |
|
244 |
break; |
|
245 |
case DataTypes.TIME: |
|
246 |
case DataTypes.DATE: |
|
247 |
assertEquals( |
|
248 |
String.format("Field %s name mismatch", sourceAttr.getName()), |
|
249 |
sourceAttr.getName(), |
|
250 |
targetAttr.getName() |
|
251 |
); |
|
252 |
assertEquals( |
|
253 |
String.format("Field %s type mismatch", sourceAttr.getName()), |
|
254 |
DataTypes.TIMESTAMP_NAME, |
|
255 |
targetAttr.getDataTypeName() |
|
256 |
); |
|
257 |
assertEquals(String.format("Field %s display size mismatch", sourceAttr.getName()), |
|
258 |
ZERO_DEFAULT_DISPLAY_SIZE, |
|
259 |
targetAttr.getDisplaySize() |
|
260 |
); |
|
261 |
assertEquals( |
|
262 |
String.format("Field %s size mismatch", sourceAttr.getName()), |
|
263 |
sourceAttr.getSize(), |
|
264 |
targetAttr.getSize() |
|
265 |
); |
|
266 |
assertEquals( |
|
267 |
String.format("Field %s precision mismatch", sourceAttr.getName()), |
|
268 |
sourceAttr.getPrecision(), |
|
269 |
targetAttr.getPrecision() |
|
270 |
); |
|
271 |
assertEquals( |
|
272 |
String.format("Field %s scale mismatch", sourceAttr.getName()), |
|
273 |
sourceAttr.getScale(), |
|
274 |
targetAttr.getScale() |
|
275 |
); |
|
276 |
break; |
|
277 |
|
|
278 |
case DataTypes.DOUBLE: |
|
279 |
assertEquals( |
|
280 |
String.format("Field %s name mismatch", sourceAttr.getName()), |
|
281 |
sourceAttr.getName(), |
|
282 |
targetAttr.getName() |
|
283 |
); |
|
284 |
assertEquals( |
|
285 |
String.format("Field %s type mismatch", sourceAttr.getName()), |
|
286 |
sourceAttr.getDataTypeName(), |
|
287 |
targetAttr.getDataTypeName() |
|
288 |
); |
|
289 |
assertEquals( |
|
290 |
String.format("Field %s display size mismatch", sourceAttr.getName()), |
|
291 |
DOUBLE_DEFAULT_DISPLAY_SIZE, |
|
292 |
targetAttr.getDisplaySize() |
|
293 |
); |
|
294 |
assertEquals( |
|
295 |
String.format("Field %s size mismatch", sourceAttr.getName()), |
|
296 |
sourceAttr.getSize(), |
|
297 |
targetAttr.getSize() |
|
298 |
); |
|
299 |
assertEquals( |
|
300 |
String.format("Field %s precision mismatch", sourceAttr.getName()), |
|
301 |
sourceAttr.getPrecision(), |
|
302 |
targetAttr.getPrecision() |
|
303 |
); |
|
304 |
assertEquals( |
|
305 |
String.format("Field %s scale mismatch", sourceAttr.getName()), |
|
306 |
sourceAttr.getScale(), |
|
307 |
targetAttr.getScale() |
|
308 |
); |
|
309 |
break; |
|
310 |
case DataTypes.FLOAT: |
|
311 |
assertEquals( |
|
312 |
String.format("Field %s name mismatch", sourceAttr.getName()), |
|
313 |
sourceAttr.getName(), |
|
314 |
targetAttr.getName() |
|
315 |
); |
|
316 |
assertEquals( |
|
317 |
String.format("Field %s type mismatch", sourceAttr.getName()), |
|
318 |
sourceAttr.getDataTypeName(), |
|
319 |
targetAttr.getDataTypeName() |
|
320 |
); |
|
321 |
assertEquals( |
|
322 |
String.format("Field %s display size mismatch", sourceAttr.getName()), |
|
323 |
FLOAT_DEFAULT_DISPLAY_SIZE, |
|
324 |
targetAttr.getDisplaySize() |
|
325 |
); |
|
326 |
assertEquals( |
|
327 |
String.format("Field %s size mismatch", sourceAttr.getName()), |
|
328 |
sourceAttr.getSize(), |
|
329 |
targetAttr.getSize() |
|
330 |
); |
|
331 |
assertEquals( |
|
332 |
String.format("Field %s precision mismatch", sourceAttr.getName()), |
|
333 |
sourceAttr.getPrecision(), |
|
334 |
targetAttr.getPrecision() |
|
335 |
); |
|
336 |
assertEquals( |
|
337 |
String.format("Field %s scale mismatch", sourceAttr.getName()), |
|
338 |
sourceAttr.getScale(), |
|
339 |
targetAttr.getScale() |
|
340 |
); |
|
341 |
break; |
|
342 |
|
|
343 |
case DataTypes.INT: |
|
344 |
case DataTypes.LONG: |
|
345 |
case DataTypes.TIMESTAMP: |
|
346 |
assertEquals( |
|
347 |
String.format("Field %s name mismatch", sourceAttr.getName()), |
|
348 |
sourceAttr.getName(), |
|
349 |
targetAttr.getName() |
|
350 |
); |
|
351 |
assertEquals( |
|
352 |
String.format("Field %s type mismatch", sourceAttr.getName()), |
|
353 |
sourceAttr.getDataType().getType(), |
|
354 |
targetAttr.getDataType().getType() |
|
355 |
); |
|
356 |
assertEquals(String.format("Field %s display size mismatch", sourceAttr.getName()), |
|
357 |
ZERO_DEFAULT_DISPLAY_SIZE, |
|
358 |
targetAttr.getDisplaySize() |
|
359 |
); |
|
360 |
assertEquals( |
|
361 |
String.format("Field %s size mismatch", sourceAttr.getName()), |
|
362 |
sourceAttr.getSize(), |
|
363 |
targetAttr.getSize() |
|
364 |
); |
|
365 |
assertEquals( |
|
366 |
String.format("Field %s precision mismatch", sourceAttr.getName()), |
|
367 |
sourceAttr.getPrecision(), |
|
368 |
targetAttr.getPrecision() |
|
369 |
); |
|
370 |
assertEquals( |
|
371 |
String.format("Field %s scale mismatch", sourceAttr.getName()), |
|
372 |
sourceAttr.getScale(), |
|
373 |
targetAttr.getScale() |
|
374 |
); |
|
375 |
break; |
|
376 |
|
|
377 |
case DataTypes.DECIMAL: |
|
378 |
assertEquals( |
|
379 |
String.format("Field %s name mismatch", sourceAttr.getName()), |
|
380 |
sourceAttr.getName(), |
|
381 |
targetAttr.getName() |
|
382 |
); |
|
383 |
assertEquals( |
|
384 |
String.format("Field %s type mismatch", sourceAttr.getName()), |
|
385 |
sourceAttr.getDataTypeName(), |
|
386 |
targetAttr.getDataTypeName() |
|
387 |
); |
|
388 |
assertEquals( |
|
389 |
String.format("Field %s display size mismatch", sourceAttr.getName()), |
|
390 |
sourceAttr.getPrecision() + 2, //Precision plus sign and decimal separator |
|
391 |
targetAttr.getDisplaySize() |
|
392 |
); |
|
393 |
assertEquals( |
|
394 |
String.format("Field %s size mismatch", sourceAttr.getName()), |
|
395 |
sourceAttr.getSize(), |
|
396 |
targetAttr.getSize() |
|
397 |
); |
|
398 |
assertEquals( |
|
399 |
String.format("Field %s precision mismatch", sourceAttr.getName()), |
|
400 |
sourceAttr.getPrecision(), |
|
401 |
targetAttr.getPrecision() |
|
402 |
); |
|
403 |
assertEquals( |
|
404 |
String.format("Field %s scale mismatch", sourceAttr.getName()), |
|
405 |
sourceAttr.getScale(), |
|
406 |
targetAttr.getScale() |
|
407 |
); |
|
408 |
break; |
|
409 |
case DataTypes.GEOMETRY: |
|
410 |
assertEquals( |
|
411 |
String.format("Field %s name mismatch", sourceAttr.getName()), |
|
412 |
sourceAttr.getName().toUpperCase(), |
|
413 |
targetAttr.getName() |
|
414 |
); |
|
415 |
assertEquals( |
|
416 |
String.format("Field %s type mismatch", sourceAttr.getName()), |
|
417 |
sourceAttr.getDataTypeName(), |
|
418 |
targetAttr.getDataTypeName() |
|
419 |
); |
|
420 |
assertEquals( |
|
421 |
String.format("Field %s geometry type mismatch", sourceAttr.getName()), |
|
422 |
sourceAttr.getGeomType().getName(), |
|
423 |
targetAttr.getGeomType().getName() |
|
424 |
); |
|
425 |
assertEquals( |
|
426 |
String.format("Field %s geometry SRS mismatch", sourceAttr.getName()), |
|
427 |
sourceAttr.getSRS().getAbrev(), |
|
428 |
targetAttr.getSRS().getAbrev() |
|
429 |
); |
|
430 |
assertEquals( |
|
431 |
String.format("Field %s size mismatch", sourceAttr.getName()), |
|
432 |
sourceAttr.getSize(), |
|
433 |
targetAttr.getSize() |
|
434 |
); |
|
435 |
assertEquals( |
|
436 |
String.format("Field %s precision mismatch", sourceAttr.getName()), |
|
437 |
sourceAttr.getPrecision(), |
|
438 |
targetAttr.getPrecision() |
|
439 |
); |
|
440 |
break; |
|
441 |
default: |
|
442 |
fail( |
|
443 |
String.format("Field %s type %d (%s) not supported.", |
|
444 |
targetAttr.getName(), |
|
445 |
targetAttr.getType(), |
|
446 |
targetAttr.getDataTypeName() |
|
447 |
) |
|
448 |
); |
|
449 |
} |
|
450 |
} |
|
451 |
} |
|
452 |
} |
|
453 |
|
|
454 |
protected void copyFrom(JDBCServerExplorer explorer, FeatureStore sourceStore, int mode) throws Exception { |
|
455 |
FeatureStore targetStore = openTargetStore1(explorer); |
|
456 |
targetStore.edit(mode); |
|
457 |
try { |
|
458 |
for (Feature sourceFeature : sourceStore.getFeatureSet()) { |
|
459 |
EditableFeature targetFeature = targetStore.createNewFeature(sourceFeature); |
|
460 |
targetStore.insert(targetFeature); |
|
461 |
} |
|
462 |
} finally { |
|
463 |
targetStore.finishEditing(); |
|
464 |
} |
|
465 |
} |
|
466 |
|
|
467 |
protected void checkData(JDBCServerExplorer explorer, FeatureStore sourceStore, boolean withDalResource) throws Exception { |
|
468 |
FeatureStore targetStore = openTargetStore1(explorer); |
|
469 |
|
|
470 |
List<Feature> sourceFeatures = sourceStore.getFeatures(); |
|
471 |
List<Feature> targetFeatures = targetStore.getFeatures(); |
|
472 |
assertEquals("Count features", sourceFeatures.size(), targetFeatures.size()); |
|
473 |
for (int i = 0; i < targetFeatures.size(); i++) { |
|
474 |
Feature sourceFeature = sourceFeatures.get(i); |
|
475 |
Feature targetFeature = targetFeatures.get(i); |
|
476 |
for (FeatureAttributeDescriptor sourceAttr : sourceStore.getDefaultFeatureType()) { |
|
477 |
switch (sourceAttr.getType()) { |
|
478 |
case DataTypes.BYTE: |
|
479 |
assertEquals( |
|
480 |
String.format("Feature %03d attribute %s", i, sourceAttr.getName()), |
|
481 |
sourceFeature.getInt(sourceAttr.getName()), |
|
482 |
targetFeature.getInt(sourceAttr.getName()) |
|
483 |
); |
|
484 |
break; |
|
485 |
case DataTypes.TIMESTAMP: |
|
486 |
Date sourceTimestamp = sourceFeature.getDate(sourceAttr.getName()); |
|
487 |
Date targetTimestamp = targetFeature.getDate(sourceAttr.getName()); |
|
488 |
assertEquals( |
|
489 |
String.format("Feature %03d attribute %s", i, sourceAttr.getName()), |
|
490 |
sourceTimestamp, |
|
491 |
targetTimestamp |
|
492 |
); |
|
493 |
break; |
|
494 |
case DataTypes.TIME: |
|
495 |
assertEquals( |
|
496 |
String.format("Feature %03d attribute %s", i, sourceAttr.getName()), |
|
497 |
sourceFeature.getDate(sourceAttr.getName()), |
|
498 |
targetFeature.getDate(sourceAttr.getName()) |
|
499 |
); |
|
500 |
break; |
|
501 |
case DataTypes.GEOMETRY: |
|
502 |
Geometry sourceGeometry = (Geometry) (sourceFeature.get(sourceAttr.getName())); |
|
503 |
Geometry targetGeometry = (Geometry) (targetFeature.get(sourceAttr.getName())); |
|
504 |
if (sourceGeometry == null) { |
|
505 |
assertNull(targetGeometry); |
|
506 |
} else { |
|
507 |
assertEquals( |
|
508 |
String.format("Feature %03d attribute %s", i, sourceAttr.getName()), |
|
509 |
sourceGeometry.getGeometryType(), |
|
510 |
targetGeometry.getGeometryType() |
|
511 |
); |
|
512 |
assertTrue(sourceGeometry.distance(targetGeometry) < 0.0000000000001); |
|
513 |
} |
|
514 |
|
|
515 |
break; |
|
516 |
|
|
517 |
case DataTypes.BOOLEAN: |
|
518 |
assertEquals( |
|
519 |
String.format("Feature %03d attribute %s", i, sourceAttr.getName()), |
|
520 |
sourceFeature.getBoolean(sourceAttr.getName()), |
|
521 |
targetFeature.getBoolean(sourceAttr.getName()) |
|
522 |
); |
|
523 |
break; |
|
524 |
case DataTypes.STRING: |
|
525 |
case DataTypes.INT: |
|
526 |
case DataTypes.LONG: |
|
527 |
case DataTypes.FLOAT: |
|
528 |
case DataTypes.DOUBLE: |
|
529 |
default: |
|
530 |
Object sourceValue = sourceFeature.get(sourceAttr.getName()); |
|
531 |
Object targetValue = targetFeature.get(sourceAttr.getName()); |
|
532 |
if (sourceValue == null) { |
|
533 |
LOGGER.info(String.format("Feature %03d attribute %s is null", i, sourceAttr.getName())); |
|
534 |
} |
|
535 |
assertEquals( |
|
536 |
String.format("Feature %03d attribute %s", i, sourceAttr.getName()), |
|
537 |
sourceValue, |
|
538 |
targetValue |
|
539 |
); |
|
540 |
} |
|
541 |
} |
|
542 |
} |
|
543 |
} |
|
544 |
|
|
545 |
public void testCreatePopulateAndCheckDataWithoutDalResource() throws Exception { |
|
546 |
// FeatureStore sourceStore = TestUtils.openSourceStoreShort(); |
|
547 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
548 |
JDBCServerExplorer explorer = TestUtils.openServerExplorer(); |
|
549 |
|
|
550 |
JDBCStoreParameters params = explorer.get(this.getTargetName()); |
|
551 |
if(params != null && explorer.exists(params) ){ |
|
552 |
explorer.remove(params); |
|
553 |
} |
|
554 |
|
|
555 |
createFrom(explorer, sourceStore); |
|
556 |
|
|
557 |
TestUtils.removeDALResource(this.getTargetName()); |
|
558 |
checkTypes(explorer, sourceStore.getDefaultFeatureType(), false); |
|
559 |
|
|
560 |
copyFrom(explorer, sourceStore, FeatureStore.MODE_APPEND); |
|
561 |
TestUtils.removeDALResource(this.getTargetName()); |
|
562 |
checkData(explorer, sourceStore, false); |
|
563 |
|
|
564 |
explorer.remove(params); |
|
565 |
|
|
566 |
createFrom(explorer, sourceStore); |
|
567 |
copyFrom(explorer, sourceStore, FeatureStore.MODE_FULLEDIT); |
|
568 |
TestUtils.removeDALResource(this.getTargetName()); |
|
569 |
checkData(explorer, sourceStore, false); |
|
570 |
|
|
571 |
explorer.remove(params); |
|
572 |
|
|
573 |
} |
|
574 |
|
|
575 |
public void testCreatePopulateAndCheckDataWithDalResource() throws Exception { |
|
576 |
// FeatureStore sourceStore = TestUtils.openSourceStoreShort(); |
|
577 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
578 |
JDBCServerExplorer explorer = TestUtils.openServerExplorer(); |
|
579 |
|
|
580 |
JDBCStoreParameters params = explorer.get(this.getTargetName()); |
|
581 |
if (params != null && explorer.exists(params)) { |
|
582 |
explorer.remove(params); |
|
583 |
} |
|
584 |
|
|
585 |
createFrom(explorer, sourceStore); |
|
586 |
|
|
587 |
checkTypes(explorer, sourceStore.getDefaultFeatureType(), true); |
|
588 |
|
|
589 |
copyFrom(explorer, sourceStore, FeatureStore.MODE_APPEND); |
|
590 |
checkData(explorer, sourceStore, true); |
|
591 |
|
|
592 |
explorer.remove(params); |
|
593 |
|
|
594 |
createFrom(explorer, sourceStore); |
|
595 |
copyFrom(explorer, sourceStore, FeatureStore.MODE_FULLEDIT); |
|
596 |
checkData(explorer, sourceStore, true); |
|
597 |
|
|
598 |
explorer.remove(params); |
|
599 |
|
|
600 |
} |
|
601 |
|
|
602 |
} |
org.gvsig.oracle/tags/org.gvsig.oracle-2.0.49/org.gvsig.oracle.provider/src/test/java/org/gvsig/oracle/dal/operations/sql/TestUpdateTableStatistics.java | ||
---|---|---|
1 |
package org.gvsig.oracle.dal.operations.sql; |
|
2 |
|
|
3 |
import java.util.List; |
|
4 |
import junit.framework.TestCase; |
|
5 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
|
6 |
import org.gvsig.fmap.dal.feature.FeatureType; |
|
7 |
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper; |
|
8 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory; |
|
9 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
|
10 |
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase; |
|
11 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.UpdateTableStatisticsOperation; |
|
12 |
import org.gvsig.oracle.dal.TestUtils; |
|
13 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
14 |
import org.slf4j.Logger; |
|
15 |
import org.slf4j.LoggerFactory; |
|
16 |
|
|
17 |
public class TestUpdateTableStatistics extends TestCase { |
|
18 |
|
|
19 |
private static final Logger LOGGER = LoggerFactory.getLogger(TestUpdateTableStatistics.class); |
|
20 |
|
|
21 |
public TestUpdateTableStatistics(String testName) { |
|
22 |
super(testName); |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
protected void setUp() throws Exception { |
|
27 |
super.setUp(); |
|
28 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
29 |
} |
|
30 |
|
|
31 |
@Override |
|
32 |
protected void tearDown() throws Exception { |
|
33 |
super.tearDown(); |
|
34 |
} |
|
35 |
|
|
36 |
// TODO add test methods here. The name must begin with 'test'. For example: |
|
37 |
// public void testHello() {} |
|
38 |
|
|
39 |
public void testUpdateTableStatistics() throws Exception { |
|
40 |
JDBCHelper helper = TestUtils.getJDBCHelper(); |
|
41 |
JDBCSQLBuilderBase sqlbuilder = helper.createSQLBuilder(); |
|
42 |
OperationsFactory operations = helper.getOperations(); |
|
43 |
|
|
44 |
List<String> expectedSQLs = TestUtils.getSQLs("updateTableStatistics.sql"); |
|
45 |
|
|
46 |
FeatureStore sourceStore = TestUtils.openSourceStore1(); |
|
47 |
|
|
48 |
TableReference table = operations.createTableReference( |
|
49 |
"dbtest", |
|
50 |
sqlbuilder.default_schema(), |
Also available in: Unified diff