root / branches / v2_0_0_prep / libraries / libFMap_daldb / src-test / org / gvsig / fmap / dal / store / postgresql / TestPostgreSQL.java @ 30580
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.gvsig.fmap.dal.DataStoreParameters; |
34 |
import org.gvsig.fmap.dal.exception.DataException; |
35 |
import org.gvsig.fmap.dal.feature.BaseTestFeatureStore; |
36 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
37 |
import org.gvsig.fmap.dal.feature.FeatureQuery; |
38 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
39 |
import org.gvsig.fmap.dal.feature.FeatureStoreTransform; |
40 |
import org.gvsig.fmap.dal.feature.FeatureType; |
41 |
import org.gvsig.fmap.dal.feature.NewFeatureStoreParameters; |
42 |
import org.gvsig.fmap.geom.Geometry; |
43 |
import org.gvsig.tools.evaluator.Evaluator; |
44 |
import org.gvsig.tools.evaluator.EvaluatorData; |
45 |
import org.gvsig.tools.evaluator.EvaluatorException; |
46 |
import org.gvsig.tools.evaluator.EvaluatorFieldsInfo; |
47 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
48 |
|
49 |
|
50 |
|
51 |
/**
|
52 |
* @author jmvivo
|
53 |
*
|
54 |
*/
|
55 |
// public class TestPostgreSQL extends BaseTestEditableFeatureStore {
|
56 |
public class TestPostgreSQL extends BaseTestFeatureStore { |
57 |
|
58 |
|
59 |
protected void setUp() throws Exception { |
60 |
super.setUp();
|
61 |
// FIXME
|
62 |
// ToolsLocator.registerDefaultPersistenceManager(XMLEntityManager.class);
|
63 |
|
64 |
new DefaultLibrariesInitializer().fullInitialize();
|
65 |
|
66 |
// DefaultGeometryLibrary defGeomLib = new DefaultGeometryLibrary();
|
67 |
// defGeomLib.initialize();
|
68 |
//
|
69 |
// DefaultGeometryOperationLibrary defGeomOpLib = new DefaultGeometryOperationLibrary();
|
70 |
// defGeomOpLib.initialize();
|
71 |
//
|
72 |
// ProjectionLibrary projLib = new ProjectionLibrary();
|
73 |
// projLib.initialize();
|
74 |
//
|
75 |
// CresquesCtsLibrary cresquesLib = new CresquesCtsLibrary();
|
76 |
// cresquesLib.initialize();
|
77 |
//
|
78 |
// DALDbLibrary libDb = new DALDbLibrary();
|
79 |
// libDb.initialize();
|
80 |
//
|
81 |
// DBStoreLibrary libDbStore = new DBStoreLibrary();
|
82 |
// libDbStore.initialize();
|
83 |
//
|
84 |
// JDBCLibrary libJDBC = new JDBCLibrary();
|
85 |
// libJDBC.initialize();
|
86 |
//
|
87 |
// PostgreSQLLibrary pgLib = new PostgreSQLLibrary();
|
88 |
// pgLib.initialize();
|
89 |
//
|
90 |
// JTSIndexLibrary jtsIndex = new JTSIndexLibrary();
|
91 |
// jtsIndex.initialize();
|
92 |
//
|
93 |
// projLib.postInitialize();
|
94 |
// cresquesLib.postInitialize();
|
95 |
// defGeomLib.postInitialize();
|
96 |
// defGeomOpLib.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 |
} |