root / trunk / org.gvsig.postgresql / org.gvsig.postgresql.provider / src / test / java / org / gvsig / postgresql / dal / PostgreSQLBuilderTest.java @ 570
History | View | Annotate | Download (22.8 KB)
1 |
package org.gvsig.postgresql.dal; |
---|---|
2 |
|
3 |
import junit.framework.TestCase; |
4 |
import org.apache.commons.lang3.ArrayUtils; |
5 |
import org.cresques.cts.IProjection; |
6 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
7 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
8 |
import org.gvsig.fmap.crs.CRSFactory; |
9 |
import org.gvsig.fmap.dal.SQLBuilder; |
10 |
import org.gvsig.fmap.dal.SQLBuilder.Privilege; |
11 |
import org.gvsig.fmap.dal.feature.spi.SQLBuilderBase; |
12 |
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference; |
13 |
import org.gvsig.fmap.dal.store.jdbc2.spi.operations.OperationsFactoryBase; |
14 |
import org.gvsig.fmap.geom.DataTypes; |
15 |
import org.gvsig.fmap.geom.Geometry; |
16 |
import org.gvsig.fmap.geom.GeometryLocator; |
17 |
import org.gvsig.fmap.geom.GeometryManager; |
18 |
import org.gvsig.fmap.geom.primitive.Polygon; |
19 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
20 |
|
21 |
public class PostgreSQLBuilderTest extends TestCase { |
22 |
|
23 |
public PostgreSQLBuilderTest(String testName) { |
24 |
super(testName);
|
25 |
} |
26 |
|
27 |
@Override
|
28 |
protected void setUp() throws Exception { |
29 |
super.setUp();
|
30 |
new DefaultLibrariesInitializer().fullInitialize();
|
31 |
} |
32 |
|
33 |
@Override
|
34 |
protected void tearDown() throws Exception { |
35 |
super.tearDown();
|
36 |
} |
37 |
|
38 |
private SQLBuilder createSQLBuilder() {
|
39 |
return new PostgreSQLBuilder(new PostgreSQLHelper(null)); |
40 |
} |
41 |
|
42 |
public void testCalulateEnvelopeOfColumn() throws Exception { |
43 |
|
44 |
TableReference table = new OperationsFactoryBase.DefaultTableReference("master","dbo","test1", null); |
45 |
String columnName = "the_geom"; |
46 |
|
47 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
48 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
49 |
|
50 |
sqlbuilder.select().column().value( |
51 |
expbuilder.as_geometry( |
52 |
expbuilder.ST_ExtentAggregate( |
53 |
expbuilder.column(columnName) |
54 |
) |
55 |
) |
56 |
); |
57 |
//sqlbuilder.select().group_by(expbuilder.column(columnName));
|
58 |
sqlbuilder.select().from().table() |
59 |
.database(table.getDatabase()) |
60 |
.schema(table.getSchema()) |
61 |
.name(table.getTable()); |
62 |
sqlbuilder.select().from().subquery(table.getSubquery()); |
63 |
|
64 |
sqlbuilder.select().where().and( |
65 |
expbuilder.not_is_null(expbuilder.column(columnName)) |
66 |
); |
67 |
|
68 |
System.out.println("# Test:: testCalulateEnvelopeOfColumn"); |
69 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
70 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
71 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
72 |
assertEquals( |
73 |
"SELECT ST_AsBinary(ST_Extent(\"the_geom\")) FROM \"master\".\"dbo\".\"test1\" WHERE ( (\"the_geom\") IS NOT NULL )",
|
74 |
sqlbuilder.toString() |
75 |
); |
76 |
assertEquals( |
77 |
"[the_geom]",
|
78 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
79 |
); |
80 |
assertEquals( |
81 |
"[]",
|
82 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
83 |
); |
84 |
} |
85 |
|
86 |
public void testCalulateEnvelope() throws Exception { |
87 |
GeometryManager geometryManager = GeometryLocator.getGeometryManager(); |
88 |
IProjection proj = CRSFactory.getCRS("EPSG:4326");
|
89 |
|
90 |
Polygon limit = geometryManager.createPolygon(Geometry.SUBTYPES.GEOM2D);
|
91 |
limit.addVertex(0, 0); |
92 |
limit.addVertex(0, 100); |
93 |
limit.addVertex(100, 100); |
94 |
limit.addVertex(100, 0); |
95 |
limit.addVertex(0, 0); |
96 |
|
97 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
98 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
99 |
|
100 |
sqlbuilder.select().column().value( |
101 |
expbuilder.as_geometry( |
102 |
expbuilder.ST_ExtentAggregate( |
103 |
expbuilder.column("the_geom")
|
104 |
) |
105 |
) |
106 |
).as("envelope");
|
107 |
sqlbuilder.select().from().table().database("master").schema("dbo").name("test1"); |
108 |
sqlbuilder.select().where().set( |
109 |
expbuilder.ST_Intersects( |
110 |
expbuilder.ST_Envelope( |
111 |
expbuilder.column("the_geom")
|
112 |
), |
113 |
expbuilder.geometry(limit, proj) |
114 |
) |
115 |
); |
116 |
sqlbuilder.select().where().and( |
117 |
expbuilder.custom("x = 27")
|
118 |
); |
119 |
|
120 |
System.out.println("# Test:: testCalulateEnvelope"); |
121 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
122 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
123 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
124 |
assertEquals( |
125 |
"SELECT ST_AsBinary(ST_Extent(\"the_geom\")) AS \"envelope\" FROM \"master\".\"dbo\".\"test1\" WHERE (ST_Intersects((ST_Envelope(\"the_geom\")), (ST_GeomFromWKB(('\\x000000000300000001000000050000000000000000000000000000000000000000000000004059000000000000405900000000000040590000000000004059000000000000000000000000000000000000000000000000000000000000'::bytea), (4326)))) AND x = 27)",
|
126 |
sqlbuilder.toString() |
127 |
); |
128 |
assertEquals( |
129 |
"[the_geom]",
|
130 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
131 |
); |
132 |
assertEquals( |
133 |
"[]",
|
134 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
135 |
); |
136 |
} |
137 |
|
138 |
public void testCount() throws Exception { |
139 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
140 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
141 |
|
142 |
sqlbuilder.select().column().value(sqlbuilder.count().all()); |
143 |
sqlbuilder.select().from().table().database("master").schema("dbo").name("test1"); |
144 |
sqlbuilder.select().from().subquery(null);
|
145 |
sqlbuilder.select().where().set( expbuilder.custom("pp = 200"));
|
146 |
|
147 |
System.out.println("# Test:: testCount"); |
148 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
149 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
150 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
151 |
|
152 |
//# Test:: testCount
|
153 |
//# SQL:: SELECT COUNT(*) FROM "test1" WHERE pp = 200
|
154 |
//# Variables:: []
|
155 |
//# Parametros:: []
|
156 |
|
157 |
assertEquals( |
158 |
"SELECT COUNT(*) FROM \"master\".\"dbo\".\"test1\" WHERE pp = 200",
|
159 |
sqlbuilder.toString() |
160 |
); |
161 |
assertEquals( |
162 |
"[]",
|
163 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
164 |
); |
165 |
assertEquals( |
166 |
"[]",
|
167 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
168 |
); |
169 |
} |
170 |
|
171 |
public void testCreateTable() throws Exception { |
172 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
173 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
174 |
|
175 |
sqlbuilder.create_table().table().database("master").schema("dbo").name("test1"); |
176 |
sqlbuilder.create_table().add_column( |
177 |
"name",
|
178 |
DataTypes.STRING, |
179 |
45,
|
180 |
0,
|
181 |
false,
|
182 |
false,
|
183 |
true,
|
184 |
false,
|
185 |
null
|
186 |
); |
187 |
sqlbuilder.create_table().add_column( |
188 |
"id",
|
189 |
DataTypes.INT, |
190 |
0,
|
191 |
0,
|
192 |
true,
|
193 |
false,
|
194 |
false,
|
195 |
true,
|
196 |
0
|
197 |
); |
198 |
sqlbuilder.create_table().add_column( |
199 |
"geom",
|
200 |
DataTypes.GEOMETRY, |
201 |
0,
|
202 |
0,
|
203 |
false,
|
204 |
false,
|
205 |
true,
|
206 |
false,
|
207 |
null
|
208 |
); |
209 |
|
210 |
|
211 |
// 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
|
212 |
System.out.println("# Test:: testCreateTable"); |
213 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
214 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
215 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
216 |
assertEquals( |
217 |
"CREATE TABLE \"master\".\"dbo\".\"test1\" (\"name\" VARCHAR(45) DEFAULT NULL NULL, \"id\" SERIAL PRIMARY KEY ); SELECT AddGeometryColumn('dbo' , 'test1' , 'geom', null , 'GEOMETRY' , 2, TRUE)",
|
218 |
sqlbuilder.toString() |
219 |
); |
220 |
assertEquals( |
221 |
"[]",
|
222 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
223 |
); |
224 |
assertEquals( |
225 |
"[]",
|
226 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
227 |
); |
228 |
} |
229 |
|
230 |
public void testDropTable() throws Exception { |
231 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
232 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
233 |
|
234 |
sqlbuilder.drop_table().table().database("master").schema("dbo").name("test1"); |
235 |
|
236 |
// DROP TABLE "test1"
|
237 |
|
238 |
System.out.println("# Test:: testDropTable"); |
239 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
240 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
241 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
242 |
assertEquals( |
243 |
"DROP TABLE \"master\".\"dbo\".\"test1\"",
|
244 |
sqlbuilder.toString() |
245 |
); |
246 |
assertEquals( |
247 |
"[]",
|
248 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
249 |
); |
250 |
assertEquals( |
251 |
"[]",
|
252 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
253 |
); |
254 |
} |
255 |
|
256 |
public void testFetchFeatureProviderByReference() throws Exception { |
257 |
SQLBuilder sqlbuilder = new SQLBuilderBase();
|
258 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
259 |
|
260 |
String value = "yoyo"; |
261 |
sqlbuilder.select().column().name("name");
|
262 |
sqlbuilder.select().column().name("id");
|
263 |
sqlbuilder.select().column().name("geom").as_geometry();
|
264 |
sqlbuilder.select().from().table().database("master").schema("dbo").name("test1"); |
265 |
sqlbuilder.select().where().set( |
266 |
expbuilder.eq( |
267 |
expbuilder.column("name"),
|
268 |
expbuilder.parameter(value).as_constant() |
269 |
) |
270 |
); |
271 |
sqlbuilder.select().limit(1);
|
272 |
|
273 |
// SELECT "name", "id", ST_AsBinary("geom") FROM "master"."dbo"."test1" WHERE ( ("name") = (?) ) LIMIT 1
|
274 |
|
275 |
System.out.println("# Test:: testFetchFeatureProviderByReference"); |
276 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
277 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
278 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
279 |
assertEquals( |
280 |
"SELECT \"name\", \"id\", ST_AsBinary(\"geom\") FROM \"master\".\"dbo\".\"test1\" WHERE ( (\"name\") = (?) ) LIMIT 1",
|
281 |
sqlbuilder.toString() |
282 |
); |
283 |
assertEquals( |
284 |
"[geom, id, name]",
|
285 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
286 |
); |
287 |
assertEquals( |
288 |
"['yoyo']",
|
289 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
290 |
); |
291 |
} |
292 |
|
293 |
public void testFetchFeatureType() throws Exception { |
294 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
295 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
296 |
|
297 |
sqlbuilder.select().column().all(); |
298 |
sqlbuilder.select().from().table().database("master").schema("dbo").name("test1"); |
299 |
sqlbuilder.select().limit(1);
|
300 |
|
301 |
System.out.println("# Test:: testFetchFeatureType"); |
302 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
303 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
304 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
305 |
|
306 |
//# Test:: testFetchFeatureType
|
307 |
//# SQL:: SELECT * FROM "test1" LIMIT 1
|
308 |
//# Variables:: []
|
309 |
//# Parametros:: []
|
310 |
|
311 |
assertEquals( |
312 |
"SELECT * FROM \"master\".\"dbo\".\"test1\" LIMIT 1",
|
313 |
sqlbuilder.toString() |
314 |
); |
315 |
assertEquals( |
316 |
"[]",
|
317 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
318 |
); |
319 |
assertEquals( |
320 |
"[]",
|
321 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
322 |
); |
323 |
} |
324 |
|
325 |
public void testPerformDeletes() throws Exception { |
326 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
327 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
328 |
|
329 |
sqlbuilder.delete().table().database("master").schema("dbo").name("test1"); |
330 |
sqlbuilder.delete().where().and( |
331 |
expbuilder.eq( |
332 |
expbuilder.column("id1"),
|
333 |
expbuilder.parameter("id1").as_variable()
|
334 |
) |
335 |
); |
336 |
sqlbuilder.delete().where().and( |
337 |
expbuilder.eq( |
338 |
expbuilder.column("id2"),
|
339 |
expbuilder.parameter("id2").as_variable()
|
340 |
) |
341 |
); |
342 |
|
343 |
// DELETE FROM "test1" WHERE ( ("id1") = (?) ) AND ( ("id2") = (?) )
|
344 |
|
345 |
System.out.println("# Test:: testPerformDeletes"); |
346 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
347 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
348 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
349 |
assertEquals( |
350 |
"DELETE FROM \"master\".\"dbo\".\"test1\" WHERE (( (\"id1\") = (?) ) AND ( (\"id2\") = (?) ))",
|
351 |
sqlbuilder.toString() |
352 |
); |
353 |
assertEquals( |
354 |
"[id1, id2]",
|
355 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
356 |
); |
357 |
assertEquals( |
358 |
"[\"id1\", \"id2\"]",
|
359 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
360 |
); |
361 |
} |
362 |
|
363 |
public void testPerformInserts1() throws Exception { |
364 |
IProjection proj = CRSFactory.getCRS("EPSG:4326");
|
365 |
|
366 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
367 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
368 |
|
369 |
sqlbuilder.insert().table().database("master").schema("dbo").name("test1"); |
370 |
sqlbuilder.insert().column().name("id").with_value(expbuilder.parameter("id")); |
371 |
sqlbuilder.insert().column().name("name").with_value(expbuilder.parameter("name")); |
372 |
sqlbuilder.insert().column().name("geom").with_value(expbuilder.parameter("geom").as_geometry_variable().srs(proj)); |
373 |
|
374 |
System.out.println("# Test:: testPerformInserts1"); |
375 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
376 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
377 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
378 |
assertEquals( |
379 |
"INSERT INTO \"master\".\"dbo\".\"test1\" ( \"id\", \"name\", \"geom\" ) VALUES ( ?, ?, ST_GeomFromWKB((?), (4326)) )",
|
380 |
sqlbuilder.toString() |
381 |
); |
382 |
assertEquals( |
383 |
"[geom, id, name]",
|
384 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
385 |
); |
386 |
assertEquals( |
387 |
"[\"id\", \"name\", \"geom\"]",
|
388 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
389 |
); |
390 |
} |
391 |
|
392 |
public void testPerformInserts2() throws Exception { |
393 |
IProjection proj = CRSFactory.getCRS("EPSG:4326");
|
394 |
|
395 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
396 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
397 |
|
398 |
sqlbuilder.insert().table().database("master").schema("dbo").name("test1"); |
399 |
sqlbuilder.insert().column().name("id").with_value(expbuilder.parameter("id")); |
400 |
sqlbuilder.insert().column().name("name").with_value(expbuilder.parameter("name")); |
401 |
sqlbuilder.insert().column().name("geom").with_value(expbuilder.parameter("geom").as_geometry_variable().srs(proj)); |
402 |
|
403 |
System.out.println("# Test:: testPerformInserts2"); |
404 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
405 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
406 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
407 |
assertEquals( |
408 |
"INSERT INTO \"master\".\"dbo\".\"test1\" ( \"id\", \"name\", \"geom\" ) VALUES ( ?, ?, ST_GeomFromWKB((?), (4326)) )",
|
409 |
sqlbuilder.toString() |
410 |
); |
411 |
assertEquals( |
412 |
"[geom, id, name]",
|
413 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
414 |
); |
415 |
assertEquals( |
416 |
"[\"id\", \"name\", \"geom\"]",
|
417 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
418 |
); |
419 |
} |
420 |
|
421 |
public void testPerformUpdates1() throws Exception { |
422 |
IProjection proj = CRSFactory.getCRS("EPSG:4326");
|
423 |
|
424 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
425 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
426 |
|
427 |
sqlbuilder.update().table().database("master").schema("dbo").name("test1"); |
428 |
sqlbuilder.update().where().and( |
429 |
expbuilder.eq( |
430 |
expbuilder.column("id"),
|
431 |
expbuilder.parameter("id").as_variable()
|
432 |
) |
433 |
); |
434 |
sqlbuilder.update().column().name("name").with_value(expbuilder.parameter("name")); |
435 |
sqlbuilder.update().column().name("geom").with_value(
|
436 |
expbuilder.parameter("geom").as_geometry_variable().srs(proj)
|
437 |
); |
438 |
|
439 |
System.out.println("# Test:: testPerformUpdates"); |
440 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
441 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
442 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
443 |
assertEquals( |
444 |
"UPDATE \"master\".\"dbo\".\"test1\" SET \"name\" = ?, \"geom\" = ST_GeomFromWKB((?), (4326)) WHERE ( (\"id\") = (?) )",
|
445 |
sqlbuilder.toString() |
446 |
); |
447 |
assertEquals( |
448 |
"[geom, id, name]",
|
449 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
450 |
); |
451 |
assertEquals( |
452 |
"[\"name\", \"geom\", \"id\"]",
|
453 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
454 |
); |
455 |
} |
456 |
|
457 |
public void testPerformUpdates2() throws Exception { |
458 |
IProjection proj = CRSFactory.getCRS("EPSG:4326");
|
459 |
|
460 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
461 |
GeometryExpressionBuilder expbuilder = sqlbuilder.expression(); |
462 |
|
463 |
sqlbuilder.update().table().database("master").schema("dbo").name("test1"); |
464 |
sqlbuilder.update().where().and( |
465 |
expbuilder.eq( |
466 |
expbuilder.column("id"),
|
467 |
expbuilder.parameter("id").as_variable()
|
468 |
) |
469 |
); |
470 |
sqlbuilder.update().column().name("name").with_value(expbuilder.parameter("name")); |
471 |
sqlbuilder.update().column().name("geom").with_value(
|
472 |
expbuilder.parameter("geom").as_geometry_variable()
|
473 |
.srs(expbuilder.parameter().value(proj)) |
474 |
); |
475 |
|
476 |
System.out.println("# Test:: testPerformUpdates"); |
477 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
478 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
479 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
480 |
assertEquals( |
481 |
"UPDATE \"master\".\"dbo\".\"test1\" SET \"name\" = ?, \"geom\" = ST_GeomFromWKB((?), (?)) WHERE ( (\"id\") = (?) )",
|
482 |
sqlbuilder.toString() |
483 |
); |
484 |
assertEquals( |
485 |
"[geom, id, name]",
|
486 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
487 |
); |
488 |
assertEquals( |
489 |
"[\"name\", \"geom\", 4326, \"id\"]",
|
490 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
491 |
); |
492 |
} |
493 |
|
494 |
public void testGrant1() throws Exception { |
495 |
|
496 |
SQLBuilder sqlbuilder = createSQLBuilder(); |
497 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
498 |
|
499 |
sqlbuilder.grant().table().database("master").schema("dbo").name("test1"); |
500 |
sqlbuilder.grant().role("prueba").select().insert().update();
|
501 |
sqlbuilder.grant().role("gis").all();
|
502 |
|
503 |
|
504 |
System.out.println("# Test:: testGrant1"); |
505 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
506 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
507 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
508 |
assertEquals( |
509 |
"",
|
510 |
sqlbuilder.toString() |
511 |
); |
512 |
assertEquals( |
513 |
"[]",
|
514 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
515 |
); |
516 |
assertEquals( |
517 |
"[]",
|
518 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
519 |
); |
520 |
} |
521 |
|
522 |
public void testGrant2() throws Exception { |
523 |
|
524 |
SQLBuilder sqlbuilder = new SQLBuilderBase();
|
525 |
ExpressionBuilder expbuilder = sqlbuilder.expression(); |
526 |
|
527 |
sqlbuilder.grant().table().database("master").schema("dbo").name("test1"); |
528 |
sqlbuilder.grant().role("prueba").privilege(Privilege.SELECT)
|
529 |
.privilege(Privilege.INSERT) |
530 |
.privilege(Privilege.UPDATE); |
531 |
sqlbuilder.grant().role("gis").privilege(Privilege.ALL);
|
532 |
|
533 |
|
534 |
System.out.println("# Test:: testGrant2"); |
535 |
System.out.println("# SQL:: " + sqlbuilder.toString()); |
536 |
System.out.println("# Variables:: " + ArrayUtils.toString(sqlbuilder.variables_names())); |
537 |
System.out.println("# Parametros:: " + ArrayUtils.toString(sqlbuilder.parameters_names())); |
538 |
assertEquals( |
539 |
"",
|
540 |
sqlbuilder.toString() |
541 |
); |
542 |
assertEquals( |
543 |
"[]",
|
544 |
ArrayUtils.toString(sqlbuilder.variables_names()) |
545 |
); |
546 |
assertEquals( |
547 |
"[]",
|
548 |
ArrayUtils.toString(sqlbuilder.parameters_names()) |
549 |
); |
550 |
} |
551 |
|
552 |
|
553 |
} |