svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_daldb / src-test / org / gvsig / fmap / dal / store / postgresql / TestPostgreSQL.java @ 29956
History | View | Annotate | Download (5.9 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2009 IVER T.I {{Task}}
|
26 |
*/
|
27 |
|
28 |
/**
|
29 |
*
|
30 |
*/
|
31 |
package org.gvsig.fmap.dal.store.postgresql; |
32 |
|
33 |
import org.cresques.ProjectionLibrary; |
34 |
import org.cresques.impl.CresquesCtsLibrary; |
35 |
import org.gvsig.fmap.dal.DALDbLibrary; |
36 |
import org.gvsig.fmap.dal.DataStoreParameters; |
37 |
import org.gvsig.fmap.dal.exception.DataException; |
38 |
import org.gvsig.fmap.dal.feature.BaseTestFeatureStore; |
39 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
40 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
41 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
42 |
import org.gvsig.fmap.dal.feature.FeatureStoreTransform; |
43 |
import org.gvsig.fmap.dal.feature.FeatureType; |
44 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
45 |
import org.gvsig.fmap.dal.index.spatial.jts.JTSIndexLibrary; |
46 |
import org.gvsig.fmap.dal.store.db.DBStoreLibrary; |
47 |
import org.gvsig.fmap.dal.store.jdbc.JDBCLibrary; |
48 |
import org.gvsig.fmap.geom.Geometry; |
49 |
import org.gvsig.fmap.geom.impl.DefaultGeometryLibrary; |
50 |
import org.gvsig.tools.evaluator.Evaluator; |
51 |
import org.gvsig.tools.evaluator.EvaluatorData; |
52 |
import org.gvsig.tools.evaluator.EvaluatorException; |
53 |
import org.gvsig.tools.evaluator.EvaluatorFieldsInfo; |
54 |
|
55 |
|
56 |
|
57 |
/**
|
58 |
* @author jmvivo
|
59 |
*
|
60 |
*/
|
61 |
// public class TestPostgreSQL extends BaseTestEditableFeatureStore {
|
62 |
public class TestPostgreSQL extends BaseTestFeatureStore { |
63 |
|
64 |
|
65 |
protected void setUp() throws Exception { |
66 |
super.setUp();
|
67 |
// FIXME
|
68 |
// ToolsLocator.registerDefaultPersistenceManager(XMLEntityManager.class);
|
69 |
|
70 |
DefaultGeometryLibrary defGeomLib = new DefaultGeometryLibrary();
|
71 |
defGeomLib.initialize(); |
72 |
|
73 |
ProjectionLibrary projLib = new ProjectionLibrary();
|
74 |
projLib.initialize(); |
75 |
|
76 |
CresquesCtsLibrary cresquesLib = new CresquesCtsLibrary();
|
77 |
cresquesLib.initialize(); |
78 |
|
79 |
DALDbLibrary libDb = new DALDbLibrary();
|
80 |
libDb.initialize(); |
81 |
|
82 |
DBStoreLibrary libDbStore = new DBStoreLibrary();
|
83 |
libDbStore.initialize(); |
84 |
|
85 |
JDBCLibrary libJDBC = new JDBCLibrary();
|
86 |
libJDBC.initialize(); |
87 |
|
88 |
PostgreSQLLibrary pgLib = new PostgreSQLLibrary();
|
89 |
pgLib.initialize(); |
90 |
|
91 |
JTSIndexLibrary jtsIndex = new JTSIndexLibrary();
|
92 |
jtsIndex.initialize(); |
93 |
|
94 |
projLib.postInitialize(); |
95 |
cresquesLib.postInitialize(); |
96 |
defGeomLib.postInitialize(); |
97 |
libDb.postInitialize(); |
98 |
libDbStore.postInitialize(); |
99 |
libJDBC.postInitialize(); |
100 |
pgLib.postInitialize(); |
101 |
jtsIndex.postInitialize(); |
102 |
} |
103 |
|
104 |
public DataStoreParameters getDefaultDataStoreParameters()
|
105 |
throws DataException {
|
106 |
PostgreSQLStoreParameters pgParameters = null;
|
107 |
pgParameters = (PostgreSQLStoreParameters) dataManager |
108 |
.createStoreParameters(PostgreSQLStoreProvider.NAME); |
109 |
|
110 |
pgParameters.setHost("localhost");
|
111 |
pgParameters.setUser("postgres");
|
112 |
pgParameters.setPassword("postgres");
|
113 |
pgParameters.setDBName("gis");
|
114 |
pgParameters.setTable("muni10000_peq");
|
115 |
|
116 |
return pgParameters;
|
117 |
} |
118 |
|
119 |
public boolean hasExplorer() { |
120 |
return true; |
121 |
} |
122 |
|
123 |
public void testLoadMetadata() throws Exception { |
124 |
DataStoreParameters params = this.getDefaultDataStoreParameters();
|
125 |
|
126 |
FeatureStore store = null;
|
127 |
store = (FeatureStore) dataManager.createStore(params); |
128 |
FeatureType fType = store.getDefaultFeatureType(); |
129 |
FeatureAttributeDescriptor geomAttr; |
130 |
|
131 |
|
132 |
|
133 |
if (fType.getDefaultGeometryAttributeIndex() >= 0) { |
134 |
assertNotNull(store.getEnvelope()); |
135 |
geomAttr = fType.getAttributeDescriptor(fType |
136 |
.getDefaultGeometryAttributeIndex()); |
137 |
assertTrue(geomAttr.getGeometryType() == Geometry.TYPES.MULTISURFACE); |
138 |
assertTrue(geomAttr.getGeometrySubType() == Geometry.SUBTYPES.GEOM2D); |
139 |
assertNotNull(store.getDynValue("DefaultSRS"));
|
140 |
|
141 |
} |
142 |
|
143 |
} |
144 |
|
145 |
public void testCloserConnection() throws Exception { |
146 |
|
147 |
DataStoreParameters params = this.getDefaultDataStoreParameters();
|
148 |
|
149 |
FeatureStore store = null;
|
150 |
store = (FeatureStore) dataManager.createStore(params); |
151 |
|
152 |
FeatureQuery query = store.createFeatureQuery(); |
153 |
|
154 |
query.getOrder().add("gid", true); |
155 |
|
156 |
query.setFilter(new Evaluator() {
|
157 |
|
158 |
public Object evaluate(EvaluatorData data) |
159 |
throws EvaluatorException {
|
160 |
// TODO Auto-generated method stub
|
161 |
return Boolean.TRUE; |
162 |
} |
163 |
|
164 |
public String getCQL() { |
165 |
return "true = true"; |
166 |
} |
167 |
|
168 |
public String getDescription() { |
169 |
// TODO Auto-generated method stub
|
170 |
return null; |
171 |
} |
172 |
|
173 |
public String getName() { |
174 |
return "AlwaysTrue"; |
175 |
} |
176 |
|
177 |
public EvaluatorFieldsInfo getFieldsInfo() {
|
178 |
// TODO Auto-generated method stub
|
179 |
return null; |
180 |
} |
181 |
|
182 |
}); |
183 |
|
184 |
FeatureStoreTransform transform = new StringsToLowerTransform();
|
185 |
transform.setFeatureStore(store); |
186 |
|
187 |
store.getTransforms().add(transform); |
188 |
|
189 |
transform = new StringsToLowerTransform();
|
190 |
transform.setFeatureStore(store); |
191 |
|
192 |
store.getTransforms().add(transform); |
193 |
|
194 |
transform = new StringsToLowerTransform();
|
195 |
transform.setFeatureStore(store); |
196 |
|
197 |
store.getTransforms().add(transform); |
198 |
|
199 |
for (int i = 0; i < 30; i++) { |
200 |
// this.fullStoreIteratorTest(store);
|
201 |
|
202 |
this.testIterationFastAndStandart(store, query);
|
203 |
} |
204 |
|
205 |
|
206 |
store.dispose(); |
207 |
|
208 |
} |
209 |
|
210 |
public boolean usesResources() { |
211 |
return true; |
212 |
} |
213 |
|
214 |
public NewFeatureStoreParameters getDefaultNewDataStoreParameters()
|
215 |
throws Exception { |
216 |
// TODO Auto-generated method stub
|
217 |
return null; |
218 |
} |
219 |
} |