Revision 19663 trunk/libraries/libDataSourceDBBaseDrivers/src-test/org/gvsig/data/datastores/vectorial/driver/jdbc/DataStoreTest.java
DataStoreTest.java | ||
---|---|---|
5 | 5 |
import java.sql.DriverManager; |
6 | 6 |
import java.sql.SQLException; |
7 | 7 |
import java.sql.Statement; |
8 |
import java.util.Iterator; |
|
8 | 9 |
|
9 | 10 |
import junit.framework.TestCase; |
10 | 11 |
|
... | ... | |
21 | 22 |
import org.gvsig.data.exception.InitializeException; |
22 | 23 |
import org.gvsig.data.exception.OpenException; |
23 | 24 |
import org.gvsig.data.exception.ReadException; |
24 |
import org.gvsig.data.exception.WriteException; |
|
25 | 25 |
import org.gvsig.data.vectorial.IFeature; |
26 | 26 |
import org.gvsig.data.vectorial.IFeatureCollection; |
27 | 27 |
import org.gvsig.data.vectorial.IFeatureStore; |
... | ... | |
193 | 193 |
|
194 | 194 |
|
195 | 195 |
|
196 |
driverTest((IDriverParameters)dp,null,null,false);
|
|
196 |
driverTest((IDriverParameters)dp,null,null,true);
|
|
197 | 197 |
|
198 |
// IFeatureStore fs = createFeatureStore(dp); |
|
199 |
// assertNotNull("Can't create Feature Store", fs); |
|
200 |
// |
|
201 |
// fs.open(); |
|
202 |
// |
|
203 |
// Iterator it; |
|
204 |
// IFeatureCollection fc; |
|
205 |
// Comparable v1,v2; |
|
206 |
// IFeature feature,pfeature; |
|
207 |
// long count; |
|
208 |
// |
|
209 |
// |
|
210 |
// fc = (IFeatureCollection)fs.getDataCollection(); |
|
211 |
// |
|
212 |
// assertEquals(9, fc.size()); |
|
213 |
// |
|
214 |
// fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'",null); |
|
215 |
// |
|
216 |
// assertEquals(2, fc.size()); |
|
217 |
// |
|
218 |
// it = fc.iterator(); |
|
219 |
// count=0; |
|
220 |
// while (it.hasNext()){ |
|
221 |
// feature = (IFeature)it.next(); |
|
222 |
// assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
|
223 |
// count++; |
|
224 |
// } |
|
225 |
// assertEquals("Iteration error",2,count); |
|
226 |
// |
|
227 |
// |
|
228 |
// fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE ASC"); |
|
229 |
// assertEquals(9, fc.size()); |
|
230 |
// it = fc.iterator(); |
|
231 |
// count=0; |
|
232 |
// pfeature = (IFeature)it.next(); |
|
233 |
// count++; |
|
234 |
// while (it.hasNext()){ |
|
235 |
// feature = (IFeature)it.next(); |
|
236 |
// v1 = (Comparable)pfeature.get("NOMBRE"); |
|
237 |
// v2 = (Comparable)feature.get("NOMBRE"); |
|
238 |
// pfeature=feature; |
|
239 |
// assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
|
240 |
// count++; |
|
241 |
// } |
|
242 |
// assertEquals("Iteration error",9,count); |
|
243 |
// |
|
244 |
// |
|
245 |
// fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC"); |
|
246 |
// assertEquals(9, fc.size()); |
|
247 |
// it = fc.iterator(); |
|
248 |
// |
|
249 |
// count=0; |
|
250 |
// pfeature = (IFeature)it.next(); |
|
251 |
// count++; |
|
252 |
// while (it.hasNext()){ |
|
253 |
// feature = (IFeature)it.next(); |
|
254 |
// v1 = (Comparable)pfeature.get("NOMBRE"); |
|
255 |
// v2 = (Comparable)feature.get("NOMBRE"); |
|
256 |
// pfeature=feature; |
|
257 |
// assertTrue("Short error", (v1.compareTo(v1) >= 0)); |
|
258 |
// count++; |
|
259 |
// } |
|
260 |
// assertEquals("Iteration error",9,count); |
|
261 |
// |
|
262 |
// |
|
263 |
// fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE"); |
|
264 |
// |
|
265 |
// assertEquals(2, fc.size()); |
|
266 |
// |
|
267 |
// it = fc.iterator(); |
|
268 |
// |
|
269 |
// count=0; |
|
270 |
// pfeature = (IFeature)it.next(); |
|
271 |
// assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith("b")); |
|
272 |
// count++; |
|
273 |
// while (it.hasNext()){ |
|
274 |
// feature = (IFeature)it.next(); |
|
275 |
// assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
|
276 |
// v1 = (Comparable)pfeature.get("NOMBRE"); |
|
277 |
// v2 = (Comparable)feature.get("NOMBRE"); |
|
278 |
// pfeature=feature; |
|
279 |
// assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
|
280 |
// count++; |
|
281 |
// } |
|
282 |
// assertEquals("Iteration error",2,count); |
|
283 |
// |
|
284 |
// |
|
285 |
// |
|
286 |
// fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc"); |
|
287 |
// assertEquals(9, fc.size()); |
|
288 |
// it = fc.iterator(); |
|
289 |
// count=0; |
|
290 |
// pfeature = (IFeature)it.next(); |
|
291 |
// System.out.println(pfeature.getString("NOMBRE")); |
|
292 |
// count++; |
|
293 |
// while (it.hasNext()){ |
|
294 |
// feature = (IFeature)it.next(); |
|
295 |
// v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase(); |
|
296 |
// v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase(); |
|
297 |
// pfeature=feature; |
|
298 |
// assertTrue("Short error", (v1.compareTo(v2) >= 0)); |
|
299 |
// System.out.println(pfeature.getString("NOMBRE")); |
|
300 |
// count++; |
|
301 |
// } |
|
302 |
// assertEquals("Iteration error",9,count); |
|
303 |
// |
|
304 |
// |
|
305 |
// try { |
|
306 |
// fs.close(); |
|
307 |
// } catch (CloseException e) { |
|
308 |
// e.printStackTrace(); |
|
309 |
// fail("Exception:" + e); |
|
310 |
// } |
|
311 |
// |
|
312 |
// |
|
198 |
IFeatureStore fs = createFeatureStore(dp); |
|
199 |
assertNotNull("Can't create Feature Store", fs); |
|
200 |
|
|
201 |
try { |
|
202 |
fs.open(); |
|
203 |
} catch (OpenException e2) { |
|
204 |
e2.printStackTrace(); |
|
205 |
fail(); |
|
206 |
} |
|
207 |
|
|
208 |
Iterator it; |
|
209 |
IFeatureCollection fc =null; |
|
210 |
Comparable v1,v2; |
|
211 |
IFeature feature,pfeature; |
|
212 |
long count; |
|
213 |
|
|
214 |
|
|
215 |
try { |
|
216 |
fc = (IFeatureCollection)fs.getDataCollection(); |
|
217 |
} catch (ReadException e1) { |
|
218 |
e1.printStackTrace(); |
|
219 |
fail(); |
|
220 |
} |
|
221 |
|
|
222 |
assertEquals(9, fc.size()); |
|
223 |
|
|
224 |
try { |
|
225 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'",null); |
|
226 |
} catch (ReadException e1) { |
|
227 |
e1.printStackTrace(); |
|
228 |
fail(); |
|
229 |
} |
|
230 |
|
|
231 |
assertEquals(2, fc.size()); |
|
232 |
|
|
233 |
it = fc.iterator(); |
|
234 |
count=0; |
|
235 |
while (it.hasNext()){ |
|
236 |
feature = (IFeature)it.next(); |
|
237 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
|
238 |
count++; |
|
239 |
} |
|
240 |
assertEquals("Iteration error",2,count); |
|
241 |
|
|
242 |
|
|
243 |
try { |
|
244 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE ASC"); |
|
245 |
} catch (ReadException e1) { |
|
246 |
e1.printStackTrace(); |
|
247 |
fail(); |
|
248 |
} |
|
249 |
assertEquals(9, fc.size()); |
|
250 |
it = fc.iterator(); |
|
251 |
count=0; |
|
252 |
pfeature = (IFeature)it.next(); |
|
253 |
count++; |
|
254 |
while (it.hasNext()){ |
|
255 |
feature = (IFeature)it.next(); |
|
256 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
|
257 |
v2 = (Comparable)feature.get("NOMBRE"); |
|
258 |
pfeature=feature; |
|
259 |
assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
|
260 |
count++; |
|
261 |
} |
|
262 |
assertEquals("Iteration error",9,count); |
|
263 |
|
|
264 |
|
|
265 |
try { |
|
266 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC"); |
|
267 |
} catch (ReadException e1) { |
|
268 |
e1.printStackTrace(); |
|
269 |
fail(); |
|
270 |
} |
|
271 |
assertEquals(9, fc.size()); |
|
272 |
it = fc.iterator(); |
|
273 |
|
|
274 |
count=0; |
|
275 |
pfeature = (IFeature)it.next(); |
|
276 |
count++; |
|
277 |
while (it.hasNext()){ |
|
278 |
feature = (IFeature)it.next(); |
|
279 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
|
280 |
v2 = (Comparable)feature.get("NOMBRE"); |
|
281 |
pfeature=feature; |
|
282 |
assertTrue("Short error", (v1.compareTo(v1) >= 0)); |
|
283 |
count++; |
|
284 |
} |
|
285 |
assertEquals("Iteration error",9,count); |
|
286 |
|
|
287 |
|
|
288 |
try { |
|
289 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE"); |
|
290 |
} catch (ReadException e1) { |
|
291 |
e1.printStackTrace(); |
|
292 |
fail(); |
|
293 |
} |
|
294 |
|
|
295 |
assertEquals(2, fc.size()); |
|
296 |
|
|
297 |
it = fc.iterator(); |
|
298 |
|
|
299 |
count=0; |
|
300 |
pfeature = (IFeature)it.next(); |
|
301 |
assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith("b")); |
|
302 |
count++; |
|
303 |
while (it.hasNext()){ |
|
304 |
feature = (IFeature)it.next(); |
|
305 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
|
306 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
|
307 |
v2 = (Comparable)feature.get("NOMBRE"); |
|
308 |
pfeature=feature; |
|
309 |
assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
|
310 |
count++; |
|
311 |
} |
|
312 |
assertEquals("Iteration error",2,count); |
|
313 |
|
|
314 |
|
|
315 |
|
|
316 |
try { |
|
317 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc"); |
|
318 |
} catch (ReadException e1) { |
|
319 |
e1.printStackTrace(); |
|
320 |
fail(); |
|
321 |
} |
|
322 |
assertEquals(9, fc.size()); |
|
323 |
it = fc.iterator(); |
|
324 |
count=0; |
|
325 |
pfeature = (IFeature)it.next(); |
|
326 |
System.out.println(pfeature.getString("NOMBRE")); |
|
327 |
count++; |
|
328 |
while (it.hasNext()){ |
|
329 |
feature = (IFeature)it.next(); |
|
330 |
v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase(); |
|
331 |
v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase(); |
|
332 |
pfeature=feature; |
|
333 |
assertTrue("Short error", (v1.compareTo(v2) >= 0)); |
|
334 |
System.out.println(pfeature.getString("NOMBRE")); |
|
335 |
count++; |
|
336 |
} |
|
337 |
assertEquals("Iteration error",9,count); |
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
/// CON EDICION |
|
342 |
|
|
343 |
fs.startEditing(); |
|
344 |
|
|
345 |
IFeature newFeature = fs.createFeature(fs.getDefaultFeatureType()); |
|
346 |
newFeature.set("NOMBRE","BuRjaSOT"); |
|
347 |
newFeature.set("TIPO","MUNICIPIO"); |
|
348 |
fs.insert(newFeature); |
|
349 |
|
|
350 |
|
|
351 |
try { |
|
352 |
fc = (IFeatureCollection)fs.getDataCollection(); |
|
353 |
} catch (ReadException e1) { |
|
354 |
e1.printStackTrace(); |
|
355 |
fail(); |
|
356 |
} |
|
357 |
|
|
358 |
assertEquals(10, fc.size()); |
|
359 |
|
|
360 |
try { |
|
361 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'",null); |
|
362 |
} catch (ReadException e1) { |
|
363 |
e1.printStackTrace(); |
|
364 |
fail(); |
|
365 |
} |
|
366 |
|
|
367 |
assertEquals(3, fc.size()); |
|
368 |
|
|
369 |
it = fc.iterator(); |
|
370 |
count=0; |
|
371 |
while (it.hasNext()){ |
|
372 |
feature = (IFeature)it.next(); |
|
373 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
|
374 |
count++; |
|
375 |
} |
|
376 |
assertEquals("Iteration error",3,count); |
|
377 |
|
|
378 |
|
|
379 |
try { |
|
380 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE ASC"); |
|
381 |
} catch (ReadException e1) { |
|
382 |
e1.printStackTrace(); |
|
383 |
fail(); |
|
384 |
} |
|
385 |
assertEquals(10, fc.size()); |
|
386 |
it = fc.iterator(); |
|
387 |
count=0; |
|
388 |
pfeature = (IFeature)it.next(); |
|
389 |
count++; |
|
390 |
while (it.hasNext()){ |
|
391 |
feature = (IFeature)it.next(); |
|
392 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
|
393 |
v2 = (Comparable)feature.get("NOMBRE"); |
|
394 |
pfeature=feature; |
|
395 |
assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
|
396 |
count++; |
|
397 |
} |
|
398 |
assertEquals("Iteration error",10,count); |
|
399 |
|
|
400 |
|
|
401 |
try { |
|
402 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"NOMBRE DESC"); |
|
403 |
} catch (ReadException e1) { |
|
404 |
e1.printStackTrace(); |
|
405 |
fail(); |
|
406 |
} |
|
407 |
assertEquals(10, fc.size()); |
|
408 |
it = fc.iterator(); |
|
409 |
|
|
410 |
count=0; |
|
411 |
pfeature = (IFeature)it.next(); |
|
412 |
count++; |
|
413 |
while (it.hasNext()){ |
|
414 |
feature = (IFeature)it.next(); |
|
415 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
|
416 |
v2 = (Comparable)feature.get("NOMBRE"); |
|
417 |
pfeature=feature; |
|
418 |
assertTrue("Short error", (v1.compareTo(v1) >= 0)); |
|
419 |
count++; |
|
420 |
} |
|
421 |
assertEquals("Iteration error",10,count); |
|
422 |
|
|
423 |
|
|
424 |
try { |
|
425 |
fc = (IFeatureCollection)fs.getDataCollection(null,"lower(NOMBRE) like 'b%'","NOMBRE"); |
|
426 |
} catch (ReadException e1) { |
|
427 |
e1.printStackTrace(); |
|
428 |
fail(); |
|
429 |
} |
|
430 |
|
|
431 |
assertEquals(3, fc.size()); |
|
432 |
|
|
433 |
it = fc.iterator(); |
|
434 |
|
|
435 |
count=0; |
|
436 |
pfeature = (IFeature)it.next(); |
|
437 |
assertTrue(pfeature.getString("NOMBRE").toLowerCase().startsWith("b")); |
|
438 |
count++; |
|
439 |
while (it.hasNext()){ |
|
440 |
feature = (IFeature)it.next(); |
|
441 |
assertTrue("Filter error",feature.getString("NOMBRE").toLowerCase().startsWith("b")); |
|
442 |
v1 = (Comparable)pfeature.get("NOMBRE"); |
|
443 |
v2 = (Comparable)feature.get("NOMBRE"); |
|
444 |
pfeature=feature; |
|
445 |
assertTrue("Short error", (v1.compareTo(v1) <= 0)); |
|
446 |
count++; |
|
447 |
} |
|
448 |
assertEquals("Iteration error",3,count); |
|
449 |
|
|
450 |
|
|
451 |
|
|
452 |
try { |
|
453 |
fc = (IFeatureCollection)fs.getDataCollection(null,null,"Tipo,lower(NOMBRE) Desc"); |
|
454 |
} catch (ReadException e1) { |
|
455 |
e1.printStackTrace(); |
|
456 |
fail(); |
|
457 |
} |
|
458 |
assertEquals(10, fc.size()); |
|
459 |
it = fc.iterator(); |
|
460 |
count=0; |
|
461 |
pfeature = (IFeature)it.next(); |
|
462 |
System.out.println(pfeature.getString("NOMBRE")); |
|
463 |
count++; |
|
464 |
while (it.hasNext()){ |
|
465 |
feature = (IFeature)it.next(); |
|
466 |
v1 = (Comparable)((String)pfeature.get("NOMBRE")).toLowerCase(); |
|
467 |
v2 = (Comparable)((String)feature.get("NOMBRE")).toLowerCase(); |
|
468 |
pfeature=feature; |
|
469 |
assertTrue("Short error", (v1.compareTo(v2) >= 0)); |
|
470 |
System.out.println(pfeature.getString("NOMBRE")); |
|
471 |
count++; |
|
472 |
} |
|
473 |
assertEquals("Iteration error",10,count); |
|
474 |
|
|
475 |
|
|
476 |
fs.cancelEditing(); |
|
477 |
|
|
478 |
|
|
479 |
|
|
480 |
|
|
481 |
|
|
482 |
|
|
483 |
|
|
484 |
|
|
485 |
|
|
486 |
try { |
|
487 |
fs.close(); |
|
488 |
} catch (CloseException e) { |
|
489 |
e.printStackTrace(); |
|
490 |
fail("Exception:" + e); |
|
491 |
} |
|
492 |
|
|
493 |
|
|
313 | 494 |
deleteTable(dp); |
314 | 495 |
|
315 | 496 |
System.out.println("======= /H2 =============="); |
... | ... | |
388 | 569 |
} |
389 | 570 |
|
390 | 571 |
if (fs.isEditable() && testEdit){ |
391 |
try { |
|
392 |
fs.finishEditing(); |
|
393 |
} catch (WriteException e) { |
|
394 |
e.printStackTrace(); |
|
395 |
fail("Exception: "+e); |
|
396 |
} catch (ReadException e) { |
|
397 |
e.printStackTrace(); |
|
398 |
fail("Exception: "+e); |
|
399 |
} |
|
572 |
// try { |
|
573 |
// fs.finishEditing(); |
|
574 |
fs.cancelEditing(); |
|
575 |
// } catch (WriteException e) { |
|
576 |
// e.printStackTrace(); |
|
577 |
// fail("Exception: "+e); |
|
578 |
// } catch (ReadException e) { |
|
579 |
// e.printStackTrace(); |
|
580 |
// fail("Exception: "+e); |
|
581 |
// } |
|
400 | 582 |
} |
401 | 583 |
try { |
402 | 584 |
fs.close(); |
Also available in: Unified diff