svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dataDB / src-test / org / gvsig / data / datastores / vectorial / db / DBTest.java @ 20973
History | View | Annotate | Download (3.33 KB)
1 |
package org.gvsig.data.datastores.vectorial.db; |
---|---|
2 |
|
3 |
import junit.framework.TestCase; |
4 |
|
5 |
import org.gvsig.data.CloseException; |
6 |
import org.gvsig.data.DataException; |
7 |
import org.gvsig.data.DataManager; |
8 |
import org.gvsig.data.IDataStoreParameters; |
9 |
import org.gvsig.data.InitializeException; |
10 |
import org.gvsig.data.OpenException; |
11 |
import org.gvsig.data.ReadException; |
12 |
import org.gvsig.data.WriteException; |
13 |
import org.gvsig.data.vectorial.IFeature; |
14 |
import org.gvsig.data.vectorial.IFeatureCollection; |
15 |
import org.gvsig.data.vectorial.IFeatureStore; |
16 |
import org.gvsig.data.vectorial.IFeatureType; |
17 |
import org.gvsig.data.vectorial.IsNotFeatureSettingException; |
18 |
import org.gvsig.data.vectorial.visitor.PrintlnFeaturesVisitor; |
19 |
import org.gvsig.exceptions.BaseException; |
20 |
|
21 |
public abstract class DBTest extends TestCase { |
22 |
|
23 |
public DBTest() {
|
24 |
super();
|
25 |
} |
26 |
|
27 |
protected void storeTest(IDataStoreParameters dp, String filter, String order, boolean testEdit) { |
28 |
DataManager dsm=DataManager.getManager(); |
29 |
|
30 |
|
31 |
IFeatureStore fs=null;
|
32 |
try {
|
33 |
fs = (IFeatureStore)dsm.createDataStore(dp); |
34 |
} catch (InitializeException e) {
|
35 |
e.printStackTrace(); |
36 |
fail("Exception:" + e);
|
37 |
} |
38 |
|
39 |
try {
|
40 |
fs.open(); |
41 |
} catch (OpenException e2) {
|
42 |
e2.printStackTrace(); |
43 |
fail(); |
44 |
} |
45 |
|
46 |
if (fs.isEditable() && testEdit) {
|
47 |
|
48 |
try {
|
49 |
fs.startEditing(); |
50 |
} catch (ReadException e) {
|
51 |
e.printStackTrace(); |
52 |
fail(); |
53 |
} |
54 |
try{
|
55 |
IFeature feature1 = fs.createDefaultFeature(false);
|
56 |
feature1.editing(); |
57 |
feature1.set("ID",1); |
58 |
IFeature feature2 = fs.createDefaultFeature(false);
|
59 |
feature2.editing(); |
60 |
feature2.set("ID",2); |
61 |
IFeature feature3 = fs.createDefaultFeature(false);
|
62 |
feature3.editing(); |
63 |
feature3.set("ID",3); |
64 |
|
65 |
|
66 |
fs.insert(feature1); |
67 |
fs.insert(feature2); |
68 |
feature1.editing(); |
69 |
feature1.set(1,111111); |
70 |
fs.update(feature1); |
71 |
fs.delete(feature3); |
72 |
fs.delete(feature2); |
73 |
}catch (DataException e) {
|
74 |
e.printStackTrace(); |
75 |
fail(); |
76 |
} |
77 |
} |
78 |
|
79 |
//Mostrar por consola todos los registros.
|
80 |
IFeatureType ft= fs.getDefaultFeatureType(); |
81 |
IFeatureCollection featureCollection=null;
|
82 |
// featureCollection = (IFeatureCollection)fs.getDataCollection();
|
83 |
// featureCollection = (IFeatureCollection)fs.getDataCollection(ft,"NOMBRE = 'CALPE'",null);
|
84 |
// featureCollection = (IFeatureCollection)fs.getDataCollection(ft,"AREA > 3.2213163729E7 and AREA < 3.2213163749E7",null);
|
85 |
try {
|
86 |
featureCollection = (IFeatureCollection)fs.getDataCollection(ft,filter,order); |
87 |
} catch (ReadException e2) {
|
88 |
// TODO Auto-generated catch block
|
89 |
e2.printStackTrace(); |
90 |
} |
91 |
|
92 |
PrintlnFeaturesVisitor visitor=new PrintlnFeaturesVisitor(ft);
|
93 |
try {
|
94 |
featureCollection.accept(visitor); |
95 |
} catch (BaseException e1) {
|
96 |
e1.printStackTrace(); |
97 |
fail("Exception: "+e1);
|
98 |
} |
99 |
featureCollection.dispose(); |
100 |
|
101 |
if (fs.isEditable() && testEdit){
|
102 |
try {
|
103 |
fs.finishEditing(); |
104 |
// fs.cancelEditing();
|
105 |
} catch (WriteException e) {
|
106 |
e.printStackTrace(); |
107 |
fail("Exception: "+e);
|
108 |
} catch (ReadException e) {
|
109 |
e.printStackTrace(); |
110 |
fail("Exception: "+e);
|
111 |
} |
112 |
} |
113 |
try {
|
114 |
fs.close(); |
115 |
} catch (CloseException e) {
|
116 |
e.printStackTrace(); |
117 |
fail("Exception: "+e);
|
118 |
} |
119 |
try {
|
120 |
fs.dispose(); |
121 |
} catch (CloseException e) {
|
122 |
// TODO Auto-generated catch block
|
123 |
e.printStackTrace(); |
124 |
} |
125 |
} |
126 |
|
127 |
} |