Statistics
| Revision:

root / trunk / libraries / libDataSourceDBBaseDrivers / src-test / org / gvsig / data / datastores / vectorial / db / jdbc / JDBCTest.java @ 19975

History | View | Annotate | Download (3.08 KB)

1
package org.gvsig.data.datastores.vectorial.db.jdbc;
2

    
3
import junit.framework.TestCase;
4

    
5
import org.gvsig.data.DataManager;
6
import org.gvsig.data.IDataStoreParameters;
7
import org.gvsig.data.exception.CloseException;
8
import org.gvsig.data.exception.InitializeException;
9
import org.gvsig.data.exception.OpenException;
10
import org.gvsig.data.exception.ReadException;
11
import org.gvsig.data.exception.WriteException;
12
import org.gvsig.data.vectorial.IFeature;
13
import org.gvsig.data.vectorial.IFeatureCollection;
14
import org.gvsig.data.vectorial.IFeatureStore;
15
import org.gvsig.data.vectorial.IFeatureType;
16
import org.gvsig.data.vectorial.visitor.PrintlnFeaturesVisitor;
17
import org.gvsig.exceptions.BaseException;
18

    
19
public abstract class JDBCTest extends TestCase {
20

    
21
        public JDBCTest() {
22
                super();
23
        }
24

    
25
        protected void storeTest(IDataStoreParameters dp, String filter, String order, boolean testEdit) {
26
                        DataManager dsm=DataManager.getManager();
27

    
28

    
29
                        IFeatureStore fs=null;
30
                        try {
31
                                fs = (IFeatureStore)dsm.createDataStore(dp);
32
                        } catch (InitializeException e) {
33
                                e.printStackTrace();
34
                                fail("Exception:" + e);
35
                        }
36

    
37
                        try {
38
                                fs.open();
39
                        } catch (OpenException e2) {
40
                                e2.printStackTrace();
41
                                fail();
42
                        }
43

    
44
                        if (fs.isEditable() && testEdit) {
45

    
46
                                try {
47
                                        fs.startEditing();
48
                                } catch (ReadException e) {
49
                                        e.printStackTrace();
50
                                        fail();
51
                                }
52

    
53
                                IFeature feature1 = fs.createDefaultFeature(false);
54
                                feature1.set("ID",1);
55
                                IFeature feature2 = fs.createDefaultFeature(false);
56
                                feature2.set("ID",2);
57
                                IFeature feature3 = fs.createDefaultFeature(false);
58
                                feature3.set("ID",3);
59

    
60
                                fs.insert(feature1);
61
                                fs.insert(feature2);
62

    
63
                                fs.update(feature3,feature1);
64
                                fs.delete(feature3);
65
                                fs.delete(feature2);
66
                        }
67

    
68
                        //Mostrar por consola todos los registros.
69
                        IFeatureType ft= fs.getDefaultFeatureType();
70
                        IFeatureCollection featureCollection=null;
71
        //                featureCollection = (IFeatureCollection)fs.getDataCollection();
72
        //                featureCollection = (IFeatureCollection)fs.getDataCollection(ft,"NOMBRE = 'CALPE'",null);
73
        //                featureCollection = (IFeatureCollection)fs.getDataCollection(ft,"AREA > 3.2213163729E7 and AREA < 3.2213163749E7",null);
74
                        try {
75
                                featureCollection = (IFeatureCollection)fs.getDataCollection(ft,filter,order);
76
                        } catch (ReadException e2) {
77
                                // TODO Auto-generated catch block
78
                                e2.printStackTrace();
79
                        }
80

    
81
                        PrintlnFeaturesVisitor visitor=new PrintlnFeaturesVisitor(ft);
82
                        try {
83
                                featureCollection.accept(visitor);
84
                        } catch (BaseException e1) {
85
                                e1.printStackTrace();
86
                                fail("Exception: "+e1);
87
                        }
88
                        featureCollection.dispose();
89

    
90
                        if (fs.isEditable() && testEdit){
91
                                try {
92
                                        fs.finishEditing();
93
        //                                fs.cancelEditing();
94
                                } catch (WriteException e) {
95
                                        e.printStackTrace();
96
                                        fail("Exception: "+e);
97
                                } catch (ReadException e) {
98
                                        e.printStackTrace();
99
                                        fail("Exception: "+e);
100
                                }
101
                        }
102
                        try {
103
                                fs.close();
104
                        } catch (CloseException e) {
105
                                e.printStackTrace();
106
                                fail("Exception: "+e);
107
                        }
108
                        try {
109
                                fs.dispose();
110
                        } catch (CloseException e) {
111
                                // TODO Auto-generated catch block
112
                                e.printStackTrace();
113
                        }
114
                }
115

    
116
}