root / trunk / org.gvsig.postgresql / org.gvsig.postgresql.provider / src / test / java / org / gvsig / fmap / dal / store / postgresql / TestPostgreSQLWrite.java @ 5
History | View | Annotate | Download (6.72 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 |
|
54 |
|
55 |
|
56 |
/**
|
57 |
* @author jmvivo
|
58 |
*
|
59 |
*/
|
60 |
// public class TestPostgreSQL extends BaseTestEditableFeatureStore {
|
61 |
public class TestPostgreSQLWrite extends BaseTestEditableFeatureStore { |
62 |
|
63 |
|
64 |
private JDBCServerExplorer myExplorer;
|
65 |
private PostgreSQLNewStoreParameters newParams;
|
66 |
|
67 |
@Override
|
68 |
protected void doSetUp() throws Exception { |
69 |
// Initialize wkt geom operation
|
70 |
int wktCode = ToWKT.CODE;
|
71 |
} |
72 |
|
73 |
public DataStoreParameters getDefaultDataStoreParameters()
|
74 |
throws DataException {
|
75 |
PostgreSQLStoreParameters pgParameters = null;
|
76 |
pgParameters = (PostgreSQLStoreParameters) dataManager |
77 |
.createStoreParameters(PostgreSQLStoreProvider.NAME); |
78 |
|
79 |
pgParameters.setHost("localhost");
|
80 |
pgParameters.setUser("postgres");
|
81 |
pgParameters.setPassword("postgres");
|
82 |
pgParameters.setDBName("gis");
|
83 |
pgParameters.setTable("muni10000_peq");
|
84 |
|
85 |
return pgParameters;
|
86 |
} |
87 |
|
88 |
public boolean hasExplorer() { |
89 |
return true; |
90 |
} |
91 |
|
92 |
public void testLoadMetadata() throws Exception { |
93 |
DataStoreParameters params = this.getDefaultDataStoreParameters();
|
94 |
|
95 |
FeatureStore store = null;
|
96 |
store = (FeatureStore) dataManager.createStore(params); |
97 |
FeatureType fType = store.getDefaultFeatureType(); |
98 |
FeatureAttributeDescriptor geomAttr; |
99 |
|
100 |
|
101 |
|
102 |
if (fType.getDefaultGeometryAttributeIndex() >= 0) { |
103 |
assertNotNull(store.getEnvelope()); |
104 |
geomAttr = fType.getAttributeDescriptor(fType |
105 |
.getDefaultGeometryAttributeIndex()); |
106 |
assertTrue(geomAttr.getGeometryType() == Geometry.TYPES.MULTISURFACE); |
107 |
assertTrue(geomAttr.getGeometrySubType() == Geometry.SUBTYPES.GEOM2D); |
108 |
assertNotNull(store.getDynValue("CRS"));
|
109 |
|
110 |
} |
111 |
|
112 |
} |
113 |
|
114 |
public void testCloserConnection() throws Exception { |
115 |
|
116 |
DataStoreParameters params = this.getDefaultDataStoreParameters();
|
117 |
|
118 |
FeatureStore store = null;
|
119 |
store = (FeatureStore) dataManager.createStore(params); |
120 |
|
121 |
FeatureQuery query = store.createFeatureQuery(); |
122 |
|
123 |
query.getOrder().add("gid", true); |
124 |
|
125 |
query.setFilter(new Evaluator() {
|
126 |
|
127 |
public Object evaluate(EvaluatorData data) |
128 |
throws EvaluatorException {
|
129 |
// TODO Auto-generated method stub
|
130 |
return Boolean.TRUE; |
131 |
} |
132 |
|
133 |
public String getSQL() { |
134 |
return "true = true"; |
135 |
} |
136 |
|
137 |
public String getDescription() { |
138 |
// TODO Auto-generated method stub
|
139 |
return null; |
140 |
} |
141 |
|
142 |
public String getName() { |
143 |
return "AlwaysTrue"; |
144 |
} |
145 |
|
146 |
public EvaluatorFieldsInfo getFieldsInfo() {
|
147 |
// TODO Auto-generated method stub
|
148 |
return null; |
149 |
} |
150 |
|
151 |
}); |
152 |
|
153 |
FeatureStoreTransform transform = new StringsToLowerTransform();
|
154 |
transform.setFeatureStore(store); |
155 |
|
156 |
store.getTransforms().add(transform); |
157 |
|
158 |
transform = new StringsToLowerTransform();
|
159 |
transform.setFeatureStore(store); |
160 |
|
161 |
store.getTransforms().add(transform); |
162 |
|
163 |
transform = new StringsToLowerTransform();
|
164 |
transform.setFeatureStore(store); |
165 |
|
166 |
store.getTransforms().add(transform); |
167 |
|
168 |
for (int i = 0; i < 30; i++) { |
169 |
// this.fullStoreIteratorTest(store);
|
170 |
|
171 |
this.testIterationFastAndStandart(store, query);
|
172 |
} |
173 |
|
174 |
|
175 |
store.dispose(); |
176 |
|
177 |
} |
178 |
|
179 |
public boolean usesResources() { |
180 |
return true; |
181 |
} |
182 |
|
183 |
public NewFeatureStoreParameters getDefaultNewDataStoreParameters()
|
184 |
throws Exception { |
185 |
PostgreSQLStoreParameters parameters = (PostgreSQLStoreParameters) this
|
186 |
.getDefaultDataStoreParameters(); |
187 |
|
188 |
FeatureStore store = null;
|
189 |
|
190 |
if (this.myExplorer == null) { |
191 |
store = (FeatureStore) dataManager.createStore(parameters); |
192 |
myExplorer = (JDBCServerExplorer) store.getExplorer(); |
193 |
} |
194 |
if (this.newParams == null) { |
195 |
if (store == null){ |
196 |
store = (FeatureStore) dataManager.createStore(parameters); |
197 |
} |
198 |
|
199 |
newParams = (PostgreSQLNewStoreParameters) myExplorer |
200 |
.getAddParameters(); |
201 |
|
202 |
newParams.setTable(parameters.getTable() + "_test");
|
203 |
FeatureType ftOrg = store.getDefaultFeatureType(); |
204 |
EditableFeatureType ftTrg = (EditableFeatureType) newParams |
205 |
.getDefaultFeatureType(); |
206 |
FeatureAttributeDescriptor org; |
207 |
EditableFeatureAttributeDescriptor trg; |
208 |
Iterator iter = ftOrg.iterator();
|
209 |
while (iter.hasNext()) {
|
210 |
org = (FeatureAttributeDescriptor) iter.next(); |
211 |
trg = ftTrg.add(org.getName(), org.getType()); |
212 |
trg.setAllowNull(org.allowNull()); |
213 |
trg.setDefaultValue(org.getDefaultValue()); |
214 |
trg.setGeometrySubType(org.getGeometrySubType()); |
215 |
trg.setGeometryType(org.getGeometryType()); |
216 |
trg.setIsAutomatic(org.isAutomatic()); |
217 |
trg.setIsPrimaryKey(org.isPrimaryKey()); |
218 |
trg.setIsReadOnly(org.isReadOnly()); |
219 |
trg.setMaximumOccurrences(org.getMaximumOccurrences()); |
220 |
trg.setMinimumOccurrences(org.getMinimumOccurrences()); |
221 |
trg.setPrecision(org.getPrecision()); |
222 |
trg.setSize(org.getSize()); |
223 |
trg.setSRS(org.getSRS()); |
224 |
} |
225 |
ftTrg.setDefaultGeometryAttributeName(ftOrg |
226 |
.getDefaultGeometryAttributeName()); |
227 |
ftTrg.setHasOID(ftOrg.hasOID()); |
228 |
|
229 |
} |
230 |
if (store != null){ |
231 |
store.dispose(); |
232 |
} |
233 |
|
234 |
return this.newParams; |
235 |
} |
236 |
|
237 |
public boolean resourcesNotifyChanges() { |
238 |
return false; |
239 |
} |
240 |
} |