root / branches / v2_0_0_prep / libraries / libFMap_daldb / src-test / org / gvsig / fmap / dal / store / postgresql / TestPostgreSQLWrite.java @ 30580
History | View | Annotate | Download (7.86 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 java.util.Iterator; |
34 |
|
35 |
import org.gvsig.fmap.dal.DataStoreParameters; |
36 |
import org.gvsig.fmap.dal.exception.DataException; |
37 |
import org.gvsig.fmap.dal.feature.BaseTestEditableFeatureStore; |
38 |
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor; |
39 |
import org.gvsig.fmap.dal.feature.EditableFeatureType; |
40 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
41 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
42 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
43 |
import org.gvsig.fmap.dal.feature.FeatureStoreTransform; |
44 |
import org.gvsig.fmap.dal.feature.FeatureType; |
45 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
46 |
import org.gvsig.fmap.dal.store.jdbc.JDBCServerExplorer; |
47 |
import org.gvsig.fmap.geom.Geometry; |
48 |
import org.gvsig.fmap.geom.operation.towkt.ToWKT; |
49 |
import org.gvsig.tools.evaluator.Evaluator; |
50 |
import org.gvsig.tools.evaluator.EvaluatorData; |
51 |
import org.gvsig.tools.evaluator.EvaluatorException; |
52 |
import org.gvsig.tools.evaluator.EvaluatorFieldsInfo; |
53 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
54 |
|
55 |
|
56 |
|
57 |
/**
|
58 |
* @author jmvivo
|
59 |
*
|
60 |
*/
|
61 |
// public class TestPostgreSQL extends BaseTestEditableFeatureStore {
|
62 |
public class TestPostgreSQLWrite extends BaseTestEditableFeatureStore { |
63 |
|
64 |
|
65 |
private JDBCServerExplorer myExplorer;
|
66 |
private PostgreSQLNewStoreParameters newParams;
|
67 |
|
68 |
protected void setUp() throws Exception { |
69 |
super.setUp();
|
70 |
// FIXME
|
71 |
// ToolsLocator.registerDefaultPersistenceManager(XMLEntityManager.class);
|
72 |
|
73 |
new DefaultLibrariesInitializer().fullInitialize();
|
74 |
|
75 |
// DefaultGeometryLibrary defGeomLib = new DefaultGeometryLibrary();
|
76 |
// defGeomLib.initialize();
|
77 |
//
|
78 |
//
|
79 |
// ProjectionLibrary projLib = new ProjectionLibrary();
|
80 |
// projLib.initialize();
|
81 |
//
|
82 |
// CresquesCtsLibrary cresquesLib = new CresquesCtsLibrary();
|
83 |
// cresquesLib.initialize();
|
84 |
//
|
85 |
// DALDbLibrary libDb = new DALDbLibrary();
|
86 |
// libDb.initialize();
|
87 |
//
|
88 |
// DBStoreLibrary libDbStore = new DBStoreLibrary();
|
89 |
// libDbStore.initialize();
|
90 |
//
|
91 |
// JDBCLibrary libJDBC = new JDBCLibrary();
|
92 |
// libJDBC.initialize();
|
93 |
//
|
94 |
// PostgreSQLLibrary pgLib = new PostgreSQLLibrary();
|
95 |
// pgLib.initialize();
|
96 |
//
|
97 |
// JTSIndexLibrary jtsIndex = new JTSIndexLibrary();
|
98 |
// jtsIndex.initialize();
|
99 |
//
|
100 |
// projLib.postInitialize();
|
101 |
// cresquesLib.postInitialize();
|
102 |
// defGeomLib.postInitialize();
|
103 |
|
104 |
// Initialize wkt geom operation
|
105 |
int wktCode = ToWKT.CODE;
|
106 |
|
107 |
// libDb.postInitialize();
|
108 |
// libDbStore.postInitialize();
|
109 |
// libJDBC.postInitialize();
|
110 |
// pgLib.postInitialize();
|
111 |
// jtsIndex.postInitialize();
|
112 |
} |
113 |
|
114 |
public DataStoreParameters getDefaultDataStoreParameters()
|
115 |
throws DataException {
|
116 |
PostgreSQLStoreParameters pgParameters = null;
|
117 |
pgParameters = (PostgreSQLStoreParameters) dataManager |
118 |
.createStoreParameters(PostgreSQLStoreProvider.NAME); |
119 |
|
120 |
pgParameters.setHost("localhost");
|
121 |
pgParameters.setUser("postgres");
|
122 |
pgParameters.setPassword("postgres");
|
123 |
pgParameters.setDBName("gis");
|
124 |
pgParameters.setTable("muni10000_peq");
|
125 |
|
126 |
return pgParameters;
|
127 |
} |
128 |
|
129 |
public boolean hasExplorer() { |
130 |
return true; |
131 |
} |
132 |
|
133 |
public void testLoadMetadata() throws Exception { |
134 |
DataStoreParameters params = this.getDefaultDataStoreParameters();
|
135 |
|
136 |
FeatureStore store = null;
|
137 |
store = (FeatureStore) dataManager.createStore(params); |
138 |
FeatureType fType = store.getDefaultFeatureType(); |
139 |
FeatureAttributeDescriptor geomAttr; |
140 |
|
141 |
|
142 |
|
143 |
if (fType.getDefaultGeometryAttributeIndex() >= 0) { |
144 |
assertNotNull(store.getEnvelope()); |
145 |
geomAttr = fType.getAttributeDescriptor(fType |
146 |
.getDefaultGeometryAttributeIndex()); |
147 |
assertTrue(geomAttr.getGeometryType() == Geometry.TYPES.MULTISURFACE); |
148 |
assertTrue(geomAttr.getGeometrySubType() == Geometry.SUBTYPES.GEOM2D); |
149 |
assertNotNull(store.getDynValue("DefaultSRS"));
|
150 |
|
151 |
} |
152 |
|
153 |
} |
154 |
|
155 |
public void testCloserConnection() throws Exception { |
156 |
|
157 |
DataStoreParameters params = this.getDefaultDataStoreParameters();
|
158 |
|
159 |
FeatureStore store = null;
|
160 |
store = (FeatureStore) dataManager.createStore(params); |
161 |
|
162 |
FeatureQuery query = store.createFeatureQuery(); |
163 |
|
164 |
query.getOrder().add("gid", true); |
165 |
|
166 |
query.setFilter(new Evaluator() {
|
167 |
|
168 |
public Object evaluate(EvaluatorData data) |
169 |
throws EvaluatorException {
|
170 |
// TODO Auto-generated method stub
|
171 |
return Boolean.TRUE; |
172 |
} |
173 |
|
174 |
public String getCQL() { |
175 |
return "true = true"; |
176 |
} |
177 |
|
178 |
public String getDescription() { |
179 |
// TODO Auto-generated method stub
|
180 |
return null; |
181 |
} |
182 |
|
183 |
public String getName() { |
184 |
return "AlwaysTrue"; |
185 |
} |
186 |
|
187 |
public EvaluatorFieldsInfo getFieldsInfo() {
|
188 |
// TODO Auto-generated method stub
|
189 |
return null; |
190 |
} |
191 |
|
192 |
}); |
193 |
|
194 |
FeatureStoreTransform transform = new StringsToLowerTransform();
|
195 |
transform.setFeatureStore(store); |
196 |
|
197 |
store.getTransforms().add(transform); |
198 |
|
199 |
transform = new StringsToLowerTransform();
|
200 |
transform.setFeatureStore(store); |
201 |
|
202 |
store.getTransforms().add(transform); |
203 |
|
204 |
transform = new StringsToLowerTransform();
|
205 |
transform.setFeatureStore(store); |
206 |
|
207 |
store.getTransforms().add(transform); |
208 |
|
209 |
for (int i = 0; i < 30; i++) { |
210 |
// this.fullStoreIteratorTest(store);
|
211 |
|
212 |
this.testIterationFastAndStandart(store, query);
|
213 |
} |
214 |
|
215 |
|
216 |
store.dispose(); |
217 |
|
218 |
} |
219 |
|
220 |
public boolean usesResources() { |
221 |
return true; |
222 |
} |
223 |
|
224 |
public NewFeatureStoreParameters getDefaultNewDataStoreParameters()
|
225 |
throws Exception { |
226 |
PostgreSQLStoreParameters parameters = (PostgreSQLStoreParameters) this
|
227 |
.getDefaultDataStoreParameters(); |
228 |
|
229 |
FeatureStore store = null;
|
230 |
|
231 |
if (this.myExplorer == null) { |
232 |
store = (FeatureStore) dataManager.createStore(parameters); |
233 |
myExplorer = (JDBCServerExplorer) store.getExplorer(); |
234 |
} |
235 |
if (this.newParams == null) { |
236 |
if (store == null){ |
237 |
store = (FeatureStore) dataManager.createStore(parameters); |
238 |
} |
239 |
|
240 |
newParams = (PostgreSQLNewStoreParameters) myExplorer |
241 |
.getAddParameters(); |
242 |
|
243 |
newParams.setTable(parameters.getTable() + "_test");
|
244 |
FeatureType ftOrg = store.getDefaultFeatureType(); |
245 |
EditableFeatureType ftTrg = (EditableFeatureType) newParams |
246 |
.getDefaultFeatureType(); |
247 |
FeatureAttributeDescriptor org; |
248 |
EditableFeatureAttributeDescriptor trg; |
249 |
Iterator iter = ftOrg.iterator();
|
250 |
while (iter.hasNext()) {
|
251 |
org = (FeatureAttributeDescriptor) iter.next(); |
252 |
trg = ftTrg.add(org.getName(), org.getDataType()); |
253 |
trg.setAllowNull(org.allowNull()); |
254 |
trg.setDefaultValue(org.getDefaultValue()); |
255 |
trg.setGeometrySubType(org.getGeometrySubType()); |
256 |
trg.setGeometryType(org.getGeometryType()); |
257 |
trg.setIsAutomatic(org.isAutomatic()); |
258 |
trg.setIsPrimaryKey(org.isPrimaryKey()); |
259 |
trg.setIsReadOnly(org.isReadOnly()); |
260 |
trg.setMaximumOccurrences(org.getMaximumOccurrences()); |
261 |
trg.setMinimumOccurrences(org.getMinimumOccurrences()); |
262 |
trg.setPrecision(org.getPrecision()); |
263 |
trg.setSize(org.getSize()); |
264 |
trg.setSRS(org.getSRS()); |
265 |
} |
266 |
ftTrg.setDefaultGeometryAttributeName(ftOrg |
267 |
.getDefaultGeometryAttributeName()); |
268 |
ftTrg.setHasOID(ftOrg.hasOID()); |
269 |
|
270 |
} |
271 |
if (store != null){ |
272 |
store.dispose(); |
273 |
} |
274 |
|
275 |
return this.newParams; |
276 |
} |
277 |
|
278 |
public boolean resourcesNotifyChanges() { |
279 |
return false; |
280 |
} |
281 |
} |