Revision 20058
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresql/PostgresqlFeatureCollection.java | ||
---|---|---|
31 | 31 |
private String totalOrder; |
32 | 32 |
private int fetchSize=5000; |
33 | 33 |
|
34 |
PostgresqlFeatureCollection(PostgresqlStore store,IFeatureType type, String filter, String order) {
|
|
34 |
PostgresqlFeatureCollection(JDBCStore store,IFeatureType type, String filter, String order) {
|
|
35 | 35 |
this.store=store; |
36 | 36 |
this.featureType=(DBFeatureType)type; |
37 | 37 |
this.filter=filter; |
... | ... | |
220 | 220 |
IFeature feature=null; |
221 | 221 |
try { |
222 | 222 |
if(rs.next()){ |
223 |
feature = PostgresqlStoreUtils.createFeature(this.store, this.rs, this.featureType);
|
|
223 |
feature = this.store.createFeatureFromResulset(this.rs, this.featureType);
|
|
224 | 224 |
} else { |
225 | 225 |
rs.close(); |
226 | 226 |
// rs.getStatement().close(); |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresql/PostgresqlFeatureCollectionEditingFiltered.java | ||
---|---|---|
114 | 114 |
protected class PostgresIterator implements Iterator{ |
115 | 115 |
private Iterator dbIter; |
116 | 116 |
private Iterator mIter; |
117 |
public PostgresIterator(JDBCStore store,DBFeatureType featureType,String sql, int fetchSize,FeatureManager featureManager) throws ReadException{
|
|
117 |
public PostgresIterator(PostgresqlStore store,DBFeatureType featureType,String sql, int fetchSize,FeatureManager featureManager) throws ReadException{
|
|
118 | 118 |
this.dbIter = new IteratorDB(store,featureType,sql,fetchSize,featureManager); |
119 | 119 |
this.mIter = new IteratorMemory(featureType,featureManager); |
120 | 120 |
} |
... | ... | |
139 | 139 |
private boolean nextChecked=false; |
140 | 140 |
private IFeature feature; |
141 | 141 |
private ResultSet rs; |
142 |
private JDBCStore store;
|
|
142 |
private PostgresqlStore store;
|
|
143 | 143 |
private DBFeatureType featureType; |
144 | 144 |
private boolean rsEOF=false; |
145 | 145 |
private FeatureManager featureManager; |
... | ... | |
149 | 149 |
private int index; |
150 | 150 |
|
151 | 151 |
|
152 |
public IteratorDB(JDBCStore store, DBFeatureType featureType,String sql,int fetchSize, FeatureManager featureManager) throws ReadException{
|
|
152 |
public IteratorDB(PostgresqlStore store, DBFeatureType featureType,String sql,int fetchSize, FeatureManager featureManager) throws ReadException{
|
|
153 | 153 |
this.store = store; |
154 | 154 |
this.featureType = featureType; |
155 | 155 |
this.featureManager= featureManager; |
... | ... | |
230 | 230 |
IFeature feature=null; |
231 | 231 |
try { |
232 | 232 |
if(rs.next()){ |
233 |
feature=PostgresqlStoreUtils.createFeature(this.store, this.rs, featureType);
|
|
233 |
feature=this.store.createFeatureFromResulset(this.rs, featureType);
|
|
234 | 234 |
} |
235 | 235 |
} catch (java.sql.SQLException e) { |
236 | 236 |
throw new RuntimeException( |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresql/PostgresqlFeatureCollectionEditing.java | ||
---|---|---|
109 | 109 |
private ResultSet rs; |
110 | 110 |
private boolean nextChecked=false; |
111 | 111 |
private IFeature feature; |
112 |
private JDBCStore store;
|
|
112 |
private PostgresqlStore store;
|
|
113 | 113 |
private DBFeatureType featureType; |
114 | 114 |
private String sql; |
115 | 115 |
private int fetchSize; |
... | ... | |
118 | 118 |
private long position; |
119 | 119 |
private boolean rsEOF=false; |
120 | 120 |
|
121 |
public PostgresIterator(JDBCStore store, DBFeatureType featureType,String sql,int fetchSize) throws ReadException{
|
|
121 |
public PostgresIterator(PostgresqlStore store, DBFeatureType featureType,String sql,int fetchSize) throws ReadException{
|
|
122 | 122 |
this.sql = sql; |
123 | 123 |
this.store = store; |
124 | 124 |
this.featureType = featureType; |
... | ... | |
201 | 201 |
IFeature feature=null; |
202 | 202 |
try { |
203 | 203 |
if(rs.next()){ |
204 |
feature=PostgresqlStoreUtils.createFeature(this.store, this.rs, featureType);
|
|
204 |
feature=this.store.createFeatureFromResulset(this.rs, featureType);
|
|
205 | 205 |
} |
206 | 206 |
} catch (java.sql.SQLException e) { |
207 | 207 |
throw new RuntimeException( |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresql/PostgresqlFeaturesWriter.java | ||
---|---|---|
20 | 20 |
import org.gvsig.data.datastores.vectorial.db.DBAttributeDescriptor; |
21 | 21 |
import org.gvsig.data.datastores.vectorial.db.DBFeatureType; |
22 | 22 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCAttributeDescriptor; |
23 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCFeature; |
|
23 | 24 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCFeaturesWriter; |
25 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCStore; |
|
24 | 26 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCTypes; |
25 | 27 |
import org.gvsig.data.exception.InitializeException; |
26 | 28 |
import org.gvsig.data.exception.InitializeWriterException; |
... | ... | |
43 | 45 |
DBFeatureType featureType; |
44 | 46 |
boolean bCreateTable=false; |
45 | 47 |
private String toEncode; |
46 |
PostgresqlStore store;
|
|
48 |
JDBCStore store;
|
|
47 | 49 |
PostgresqlStoreParameters parameters; |
48 | 50 |
|
49 | 51 |
private PreparedStatement insertSt; |
... | ... | |
55 | 57 |
} |
56 | 58 |
|
57 | 59 |
public void init(IFeatureStore store) { |
58 |
this.store = (PostgresqlStore)store; |
|
59 |
this.parameters=(PostgresqlStoreParameters)store.getParameters(); |
|
60 |
PostgresqlStore pgStore = (PostgresqlStore)store; |
|
61 |
this.store = pgStore; |
|
62 |
this.parameters=pgStore.getParametersPostgresql(); |
|
60 | 63 |
|
61 | 64 |
this.featureType = (DBFeatureType)this.store.getDefaultFeatureType(); |
62 |
conex = this.store.getConnection();
|
|
65 |
conex = pgStore.getConnection();
|
|
63 | 66 |
|
64 | 67 |
} |
65 | 68 |
|
... | ... | |
448 | 451 |
StringBuffer sqlBuf = new StringBuffer("DELETE FROM " |
449 | 452 |
+ this.parameters.tableID() + " WHERE "); |
450 | 453 |
String sql = null; |
451 |
sqlBuf.append(PostgresqlStoreUtils.getFilterForID(dbFeatureType, feature));
|
|
454 |
sqlBuf.append(((JDBCFeature)feature).getFilterForID());
|
|
452 | 455 |
sql = sqlBuf.toString(); |
453 | 456 |
|
454 | 457 |
return sql; |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresql/PostgresqlFeatureCollectionWithFeatureID.java | ||
---|---|---|
10 | 10 |
|
11 | 11 |
public class PostgresqlFeatureCollectionWithFeatureID extends AbstractJDBCDataFeatureCollectionWithFeatureID { |
12 | 12 |
|
13 |
PostgresqlFeatureCollectionWithFeatureID(FeatureManager fm,PostgresqlStore store,IFeatureType type, String filter,String order) throws ReadException {
|
|
13 |
PostgresqlFeatureCollectionWithFeatureID(FeatureManager fm,JDBCStore store,IFeatureType type, String filter,String order) throws ReadException {
|
|
14 | 14 |
init(fm, store, type, filter, order); |
15 | 15 |
} |
16 | 16 |
|
17 | 17 |
public IFeatureCollection newBaseDataFeatureCollection(JDBCStore store, IFeatureType featureType, String filter, String order) { |
18 |
return new PostgresqlFeatureCollection((PostgresqlStore)store,this.featureType,filter,order);
|
|
18 |
return new PostgresqlFeatureCollection((JDBCStore)store,this.featureType,filter,order);
|
|
19 | 19 |
} |
20 | 20 |
|
21 | 21 |
} |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresql/PostgresqlStore.java | ||
---|---|---|
3 | 3 |
import java.lang.ref.WeakReference; |
4 | 4 |
import java.sql.Connection; |
5 | 5 |
import java.sql.ResultSet; |
6 |
import java.sql.Statement; |
|
7 |
import java.util.ArrayList; |
|
8 |
import java.util.List; |
|
6 |
import java.util.Iterator; |
|
9 | 7 |
import java.util.Locale; |
10 | 8 |
|
11 | 9 |
import org.gvsig.data.IDataCollection; |
12 | 10 |
import org.gvsig.data.IDataExplorer; |
13 | 11 |
import org.gvsig.data.IDataStoreParameters; |
14 | 12 |
import org.gvsig.data.datastores.vectorial.db.DBFeatureType; |
13 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCAttributeDescriptor; |
|
14 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCFeature; |
|
15 | 15 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCFeaturesWriter; |
16 | 16 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCStore; |
17 | 17 |
import org.gvsig.data.exception.CloseException; |
... | ... | |
20 | 20 |
import org.gvsig.data.exception.ReadException; |
21 | 21 |
import org.gvsig.data.spatialprovisional.IExtent; |
22 | 22 |
import org.gvsig.data.vectorial.IFeature; |
23 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
|
23 | 24 |
import org.gvsig.data.vectorial.IFeatureCollection; |
24 |
import org.gvsig.data.vectorial.IFeatureID; |
|
25 | 25 |
import org.gvsig.data.vectorial.IFeatureType; |
26 | 26 |
import org.gvsig.metadata.IMetadata; |
27 |
import org.gvsig.metadata.IMetadataManager; |
|
28 |
import org.gvsig.metadata.MetadataManager; |
|
27 |
import org.postgis.PGgeometry; |
|
29 | 28 |
|
29 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
30 |
|
|
30 | 31 |
public class PostgresqlStore extends JDBCStore{ |
31 | 32 |
public static final String CONNECTION_STRING = "postgresql"; |
32 | 33 |
public static String DATASTORE_NAME = "PostgresqlStore"; |
33 | 34 |
protected static Locale ukLocale = new Locale("en", "UK"); // English, UK version |
34 |
private DBFeatureType featureType; |
|
35 |
protected IMetadata metadata; |
|
36 |
PostgresqlStoreParameters getParametersPostgresql(){ |
|
35 |
PostgresqlStoreParameters getParametersPostgresql(){ |
|
37 | 36 |
return (PostgresqlStoreParameters)this.parameters; |
38 | 37 |
} |
39 | 38 |
|
... | ... | |
133 | 132 |
return coll; |
134 | 133 |
} |
135 | 134 |
|
136 |
public IFeature getFeatureByID(IFeatureID id) throws ReadException { |
|
137 |
return getFeatureByID(featureType,((PostgresqlFeatureID)id).getKey()); |
|
138 |
} |
|
139 |
public IFeature getFeatureByID(IFeatureType featureType2, Object[] featureKey) throws ReadException{ |
|
140 |
if (useSqlSource){ |
|
141 |
throw new ReadException(this.getName(), |
|
142 |
new UnsupportedOperationException("Unsuported featureByID in sqlSource mode")); |
|
143 |
} |
|
144 |
ResultSet rs=null; |
|
145 |
try{ |
|
146 |
this.open(); |
|
147 |
Statement st=this.getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); |
|
148 |
String sql = this.getSqlSelectPart() + " WHERE "+ PostgresqlStoreUtils.getFilterForID(this.featureType, featureKey); |
|
149 |
rs=st.executeQuery(sql); |
|
150 |
if (rs.isLast()) { |
|
151 |
|
|
152 |
return null; |
|
153 |
}else{ |
|
154 |
if(rs.next()){ |
|
155 |
return PostgresqlStoreUtils.createFeature(this, rs, this.featureType); |
|
156 |
} |
|
157 |
|
|
158 |
} |
|
159 |
|
|
160 |
} catch (java.sql.SQLException e) { |
|
161 |
e.printStackTrace(); |
|
162 |
throw new ReadException(this.getName(), e); |
|
163 |
} finally{ |
|
164 |
if (rs != null) |
|
165 |
try { |
|
166 |
rs.close(); |
|
167 |
} catch (java.sql.SQLException e) { |
|
168 |
// TODO ????? |
|
169 |
e.printStackTrace(); |
|
170 |
} |
|
171 |
} |
|
172 |
return null; |
|
173 |
} |
|
174 | 135 |
protected Connection getConnection(){ |
175 | 136 |
// FIXME: OJO REsource manager |
176 | 137 |
return this.connection; |
... | ... | |
248 | 209 |
return writer; |
249 | 210 |
} |
250 | 211 |
|
212 |
public IDataExplorer getExplorer() { |
|
213 |
// TODO Auto-generated method stub |
|
214 |
return null; |
|
215 |
} |
|
216 |
|
|
251 | 217 |
public IMetadata getMetadata() { |
252 | 218 |
if (metadata==null){ |
253 |
IMetadataManager manager=MetadataManager.getManager(); |
|
254 |
metadata=manager.create(DATASTORE_NAME); |
|
255 |
//TODO: Apadir los meteadatos |
|
219 |
IMetadata tmp=super.getMetadata(); |
|
220 |
|
|
221 |
return tmp; |
|
222 |
}else{ |
|
223 |
return super.getMetadata(); |
|
256 | 224 |
} |
257 |
return metadata; |
|
258 |
} |
|
259 | 225 |
|
260 |
|
|
261 |
public IFeatureType getDefaultFeatureType() { |
|
262 |
// TODO Auto-generated method stub |
|
263 |
return this.featureType; |
|
264 | 226 |
} |
265 | 227 |
|
266 | 228 |
|
267 |
public Object getDefaultLabelingStrategy() { |
|
268 |
// TODO Auto-generated method stub |
|
269 |
return null; |
|
270 |
} |
|
229 |
protected void loadValueFromResulset(ResultSet rs, IFeature feature, IFeatureAttributeDescriptor attr) throws ReadException { |
|
230 |
IGeometry geom = null; |
|
231 |
String name = attr.getName(); |
|
232 |
try { |
|
233 |
if (attr.getDataType().equals(IFeatureAttributeDescriptor.TYPE_GEOMETRY)) { |
|
271 | 234 |
|
272 |
|
|
273 |
public Object getDefaultLegend() { |
|
274 |
// TODO Auto-generated method stub |
|
275 |
return null; |
|
235 |
PGgeometry data =(PGgeometry)rs.getObject(name); |
|
236 |
if (data == null) { |
|
237 |
geom = null; |
|
238 |
} else{ |
|
239 |
geom = PostGIS2Geometry.getGeneralPath(data); |
|
240 |
} |
|
241 |
feature.setGeometry(name,geom); |
|
242 |
} else { |
|
243 |
feature.set(name, rs.getObject(name)); |
|
244 |
} |
|
245 |
} catch (java.sql.SQLException e) { |
|
246 |
throw new ReadException("CreateFeature",e); |
|
247 |
} |
|
276 | 248 |
} |
277 | 249 |
|
278 | 250 |
|
279 |
public List getFeatureTypes() { |
|
280 |
ArrayList list = new ArrayList(); |
|
281 |
list.add(this.featureType); |
|
282 |
return list; |
|
251 |
protected IFeature newFeatureInstance(DBFeatureType featureType, Object[] pk) { |
|
252 |
return new PostgresqlFeature(featureType,this,pk); |
|
283 | 253 |
} |
284 | 254 |
|
285 | 255 |
|
286 |
public boolean isWithDefaultLegend() { |
|
287 |
// TODO Auto-generated method stub |
|
288 |
return false; |
|
256 |
IFeature createFeatureFromResulset(ResultSet rs, DBFeatureType featureType2) throws ReadException { |
|
257 |
return this.createFeature(rs, featureType2); |
|
289 | 258 |
} |
290 | 259 |
|
291 | 260 |
|
292 |
public IDataExplorer getExplorer() { |
|
293 |
// TODO Auto-generated method stub |
|
294 |
return null; |
|
295 |
} |
|
296 |
|
|
297 | 261 |
} |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresql/PostgresqlStoreUtils.java | ||
---|---|---|
284 | 284 |
} |
285 | 285 |
|
286 | 286 |
|
287 |
static String getFilterForID(DBFeatureType fType, IFeature feature){ |
|
288 |
return getFilterForID(fType, getPkFromFeature(feature,fType)); |
|
289 |
} |
|
290 | 287 |
|
291 |
static String getFilterForID(DBFeatureType fType, Object[] featureKey){ |
|
292 |
//TODO: Ojo para los multiples |
|
293 |
if (fType.getFieldsId().length != 1) |
|
294 |
throw new UnsupportedOperationException("ID fields > 1"); |
|
295 |
String id =fType.getFieldsId()[0]; |
|
296 |
return id + " = " + objectToSqlString(featureKey[0]); |
|
297 |
} |
|
298 | 288 |
|
299 |
static String objectToSqlString(Object obj){ |
|
300 |
if (obj instanceof String){ |
|
301 |
return "'"+ scapeString((String)obj) +"'"; |
|
302 |
} else if (obj == null){ |
|
303 |
return "null"; |
|
304 |
}else{ |
|
305 |
// OJO con otros tipos!! |
|
306 |
return obj.toString(); |
|
307 |
} |
|
308 |
|
|
309 |
} |
|
310 |
|
|
311 |
static String scapeString(String str){ |
|
312 |
return str.replace("'", "''"); |
|
313 |
} |
|
314 |
|
|
315 |
|
|
316 |
|
|
317 | 289 |
static Connection getConnection(String dbUrl, String dbUser, String dbPass) throws InitializeException { |
318 | 290 |
//TODO: Aqu? habria que implementar la llamada |
319 | 291 |
// al Resource Manager para comprobar si ya hay |
... | ... | |
350 | 322 |
|
351 | 323 |
|
352 | 324 |
|
353 |
protected static Object[] getPkFromResulset(ResultSet rs, DBFeatureType featureType) throws java.sql.SQLException{ |
|
354 |
String[] fieldsId = featureType.getFieldsId(); |
|
355 |
Object[] result = new Object[fieldsId.length]; |
|
356 |
for (int i=0;i<fieldsId.length;i++){ |
|
357 |
result[i] = rs.getObject(fieldsId[i]); |
|
358 |
} |
|
359 |
return result; |
|
360 | 325 |
|
361 |
} |
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
protected static Object[] getPkFromFeature(IFeature feature, DBFeatureType featureType){ |
|
366 |
String[] fieldsId = featureType.getFieldsId(); |
|
367 |
Object[] result = new Object[fieldsId.length]; |
|
368 |
for (int i=0;i<fieldsId.length;i++){ |
|
369 |
result[i] = feature.get(fieldsId[i]); |
|
370 |
} |
|
371 |
return result; |
|
372 |
|
|
373 |
} |
|
374 |
|
|
375 |
static IFeature createFeature(JDBCStore store,ResultSet rs,DBFeatureType featureType) throws ReadException{ |
|
376 |
|
|
377 |
JDBCFeature feature=null; |
|
378 |
|
|
379 |
|
|
380 |
Object[] pk; |
|
381 |
try { |
|
382 |
pk = getPkFromResulset(rs, featureType); |
|
383 |
|
|
384 |
feature=new PostgresqlFeature(featureType,store,pk); |
|
385 |
|
|
386 |
Iterator iter = featureType.iterator(); |
|
387 |
IGeometry geom = null; |
|
388 |
while (iter.hasNext()) { |
|
389 |
IFeatureAttributeDescriptor fad=(IFeatureAttributeDescriptor)iter.next(); |
|
390 |
if (fad.getDataType().equals(IFeatureAttributeDescriptor.TYPE_GEOMETRY)) { |
|
391 |
|
|
392 |
PGgeometry data =(PGgeometry)rs.getObject(fad.getName()); |
|
393 |
if (data == null) { |
|
394 |
geom = null; |
|
395 |
} else{ |
|
396 |
geom = PostGIS2Geometry.getGeneralPath(data); |
|
397 |
} |
|
398 |
feature.setGeometry(fad.getName(),geom); |
|
399 |
} else { |
|
400 |
feature.set(fad.getName(), rs.getObject(fad.getName())); |
|
401 |
} |
|
402 |
|
|
403 |
} |
|
404 |
return feature; |
|
405 |
} catch (java.sql.SQLException e) { |
|
406 |
throw new ReadException("CreateFeature",e); |
|
407 |
} |
|
408 |
} |
|
409 |
|
|
410 | 326 |
static String addLimitsToSQL(String aSql,int fetchSize,int page){ |
411 | 327 |
return aSql+ " limit " + fetchSize + " offset " + (fetchSize*page); |
412 | 328 |
} |
413 | 329 |
|
330 |
static String getDefaultSchema(Connection conn, String catalog) throws InitializeException { |
|
331 |
//TODO |
|
332 |
return null; |
|
333 |
} |
|
414 | 334 |
|
415 | 335 |
} |
416 | 336 |
|
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2Utils.java | ||
---|---|---|
27 | 27 |
import com.vividsolutions.jts.io.WKBWriter; |
28 | 28 |
|
29 | 29 |
public class H2Utils { |
30 |
private static WKBParser2 wkbParser = new WKBParser2(); |
|
31 | 30 |
|
32 |
static String getFilterForID(DBFeatureType fType, IFeature feature){ |
|
33 |
return getFilterForID(fType, getPkFromFeature(feature,fType)); |
|
34 |
} |
|
35 | 31 |
|
36 |
static String getFilterForID(DBFeatureType fType, Object[] featureKey){ |
|
37 |
//TODO: Ojo para los multiples |
|
38 |
if (fType.getFieldsId().length != 1) |
|
39 |
throw new UnsupportedOperationException("ID fields > 1"); |
|
40 |
String id =fType.getFieldsId()[0]; |
|
41 |
return id + " = " + objectToSqlString(featureKey[0]); |
|
42 |
} |
|
43 | 32 |
|
44 | 33 |
static String getDefaultSchema(Connection conn, String catalog) throws InitializeException { |
45 | 34 |
String sql= "SELECT * FROM INFORMATION_SCHEMA.SCHEMATA WHERE IS_DEFAULT = TRUE"; |
... | ... | |
78 | 67 |
|
79 | 68 |
} |
80 | 69 |
return schema; |
81 |
|
|
82 | 70 |
} |
83 | 71 |
|
84 | 72 |
private static void loadFieldsToFeatureType(Connection conn,H2StoreParameters params,DBFeatureType featureType) throws ReadException{ |
... | ... | |
187 | 175 |
JDBCAttributeDescriptor column= new JDBCAttributeDescriptor(); |
188 | 176 |
try { |
189 | 177 |
column.setName(rsMetadata.getColumnName(colIndex)); |
178 |
column.setCaseSensitive(rsMetadata.isCaseSensitive(colIndex)); |
|
190 | 179 |
column.setSqlType(rsMetadata.getColumnType(colIndex)); |
191 |
switch (rsMetadata.getColumnType(colIndex)) { |
|
180 |
column.setAllowNull(rsMetadata.isNullable(colIndex) == ResultSetMetaData.columnNullable); |
|
181 |
column.setAutoIncrement(rsMetadata.isAutoIncrement(colIndex)); |
|
182 |
column.setReadOnly(rsMetadata.isReadOnly(colIndex)); |
|
183 |
column.setWritable(rsMetadata.isWritable(colIndex)); |
|
184 |
column.setClassName(rsMetadata.getColumnClassName(colIndex)); |
|
185 |
column.setCatalogName(rsMetadata.getCatalogName(colIndex)); |
|
186 |
column.setDefinitelyWritable(rsMetadata.isDefinitelyWritable(colIndex)); |
|
187 |
column.setLabel(rsMetadata.getColumnLabel(colIndex)); |
|
188 |
column.setSchemaName(rsMetadata.getSchemaName(colIndex)); |
|
189 |
column.setTableName(rsMetadata.getTableName(colIndex)); |
|
190 |
column.setCatalogName(rsMetadata.getCatalogName(colIndex)); |
|
191 |
column.setSqlTypeName(rsMetadata.getColumnTypeName(colIndex)); |
|
192 |
column.setSearchable(rsMetadata.isSearchable(colIndex)); |
|
193 |
column.setSigned(rsMetadata.isSigned(colIndex)); |
|
194 |
column.setCurrency(rsMetadata.isCurrency(colIndex)); |
|
195 |
column.setPrecision(rsMetadata.getPrecision(colIndex)); |
|
196 |
column.setSize(rsMetadata.getColumnDisplaySize(colIndex)); switch (rsMetadata.getColumnType(colIndex)) { |
|
192 | 197 |
case java.sql.Types.INTEGER: |
193 | 198 |
column.setType(IFeatureAttributeDescriptor.TYPE_INT); |
194 | 199 |
break; |
... | ... | |
197 | 202 |
break; |
198 | 203 |
case java.sql.Types.REAL: |
199 | 204 |
column.setType(IFeatureAttributeDescriptor.TYPE_DOUBLE); |
200 |
// column.setPrecision(rsMetadata.getInt("DECIMAL_DIGITS")); |
|
201 | 205 |
break; |
202 | 206 |
case java.sql.Types.DOUBLE: |
203 | 207 |
column.setType(IFeatureAttributeDescriptor.TYPE_DOUBLE); |
204 |
// column.setPrecision(rsMetadata.getInt("DECIMAL_DIGITS")); |
|
205 | 208 |
break; |
206 | 209 |
case java.sql.Types.CHAR: |
207 | 210 |
column.setType(IFeatureAttributeDescriptor.TYPE_STRING); |
208 |
column.setSize(rsMetadata.getColumnDisplaySize(colIndex)); |
|
209 | 211 |
break; |
210 | 212 |
case java.sql.Types.VARCHAR: |
211 | 213 |
column.setType(IFeatureAttributeDescriptor.TYPE_STRING); |
212 |
column.setSize(rsMetadata.getColumnDisplaySize(colIndex)); |
|
213 | 214 |
break; |
214 | 215 |
case java.sql.Types.FLOAT: |
215 | 216 |
column.setType(IFeatureAttributeDescriptor.TYPE_FLOAT); |
216 |
column.setSize(rsMetadata.getColumnDisplaySize(colIndex)); |
|
217 | 217 |
break; |
218 | 218 |
case java.sql.Types.DECIMAL: |
219 | 219 |
column.setType(IFeatureAttributeDescriptor.TYPE_FLOAT); |
220 |
column.setSize(rsMetadata.getColumnDisplaySize(colIndex)); |
|
221 |
// column.setPrecision(rsMetadata.getInt("DECIMAL_DIGITS")); |
|
222 | 220 |
break; |
223 | 221 |
case java.sql.Types.DATE: |
224 | 222 |
column.setType(IFeatureAttributeDescriptor.TYPE_DATE); |
... | ... | |
396 | 394 |
return conn; |
397 | 395 |
} |
398 | 396 |
|
399 |
static Object[] getPkFromResulset(ResultSet rs, DBFeatureType featureType) throws java.sql.SQLException{ |
|
400 |
String[] fieldsId = featureType.getFieldsId(); |
|
401 |
Object[] result = new Object[fieldsId.length]; |
|
402 |
for (int i=0;i<fieldsId.length;i++){ |
|
403 |
result[i] = rs.getObject(fieldsId[i]); |
|
404 |
} |
|
405 |
return result; |
|
406 | 397 |
|
407 |
} |
|
408 |
|
|
409 |
static Object[] getPkFromFeature(IFeature feature, DBFeatureType featureType){ |
|
410 |
String[] fieldsId = featureType.getFieldsId(); |
|
411 |
Object[] result = new Object[fieldsId.length]; |
|
412 |
for (int i=0;i<fieldsId.length;i++){ |
|
413 |
result[i] = feature.get(fieldsId[i]); |
|
414 |
} |
|
415 |
return result; |
|
416 |
|
|
417 |
} |
|
418 |
|
|
419 |
static IFeature createFeature(JDBCStore store,ResultSet rs,IFeatureType featureType) throws ReadException{ |
|
420 |
|
|
421 |
JDBCFeature feature=null; |
|
422 |
|
|
423 |
if (featureType == null){ |
|
424 |
featureType = store.getDefaultFeatureType(); |
|
425 |
} |
|
426 |
|
|
427 |
|
|
428 |
Object[] pk; |
|
429 |
try { |
|
430 |
pk = getPkFromResulset(rs, (DBFeatureType) store.getDefaultFeatureType()); |
|
431 |
|
|
432 |
feature=new H2Feature(featureType,store,pk); |
|
433 |
|
|
434 |
Iterator iter = featureType.iterator(); |
|
435 |
IGeometry geom = null; |
|
436 |
while (iter.hasNext()) { |
|
437 |
IFeatureAttributeDescriptor fad=(IFeatureAttributeDescriptor)iter.next(); |
|
438 |
if (fad.getDataType().equals(IFeatureAttributeDescriptor.TYPE_GEOMETRY)) { |
|
439 |
byte[] data = rs.getBytes(fad.getName()); |
|
440 |
|
|
441 |
if (data == null) { |
|
442 |
geom = null; |
|
443 |
} else{ |
|
444 |
geom = wkbParser.parse(data); |
|
445 |
} |
|
446 |
// feature.setDefaultGeometry(geom); |
|
447 |
feature.setGeometry(fad.getName(),geom); |
|
448 |
} else { |
|
449 |
feature.set(fad.getName(), rs.getObject(fad.getName())); |
|
450 |
} |
|
451 |
|
|
452 |
} |
|
453 |
return feature; |
|
454 |
} catch (java.sql.SQLException e) { |
|
455 |
throw new ReadException("CreateFeature",e); |
|
456 |
} |
|
457 |
} |
|
458 |
|
|
459 |
static String objectToSqlString(Object obj){ |
|
460 |
if (obj instanceof String){ |
|
461 |
return "'"+ scapeString((String)obj) +"'"; |
|
462 |
} else if (obj == null){ |
|
463 |
return "null"; |
|
464 |
}else{ |
|
465 |
// OJO con otros tipos!! |
|
466 |
return obj.toString(); |
|
467 |
} |
|
468 |
|
|
469 |
} |
|
470 |
|
|
471 |
static String scapeString(String str){ |
|
472 |
return str.replace("'", "''"); |
|
473 |
} |
|
474 |
|
|
475 | 398 |
} |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2FeatureCollection.java | ||
---|---|---|
21 | 21 |
import com.iver.cit.gvsig.fmap.drivers.WKBParser2; |
22 | 22 |
|
23 | 23 |
public class H2FeatureCollection extends AbstractJDBCDataFeatureCollection { |
24 |
protected IFeatureType featureType;
|
|
24 |
protected DBFeatureType featureType;
|
|
25 | 25 |
protected String filter; |
26 | 26 |
protected String totalFilter; |
27 | 27 |
protected H2Store store; |
... | ... | |
31 | 31 |
private String sqlCount; |
32 | 32 |
private String totalOrder; |
33 | 33 |
|
34 |
H2FeatureCollection(H2Store store,IFeatureType type, String filter, String order) {
|
|
34 |
H2FeatureCollection(H2Store store,DBFeatureType type, String filter, String order) {
|
|
35 | 35 |
this.store=store; |
36 | 36 |
this.featureType=type; |
37 | 37 |
this.filter=filter; |
... | ... | |
137 | 137 |
|
138 | 138 |
protected class H2Iterator implements Iterator{ |
139 | 139 |
private ResultSet rs; |
140 |
private JDBCStore store;
|
|
141 |
private IFeatureType featureType;
|
|
140 |
private H2Store store;
|
|
141 |
private DBFeatureType featureType;
|
|
142 | 142 |
|
143 |
public H2Iterator(JDBCStore store,IFeatureType featureType ,ResultSet rs){
|
|
143 |
public H2Iterator(H2Store store,DBFeatureType featureType ,ResultSet rs){
|
|
144 | 144 |
this.rs = rs; |
145 | 145 |
this.store = store; |
146 | 146 |
this.featureType = featureType; |
... | ... | |
178 | 178 |
IFeature feature=null; |
179 | 179 |
try { |
180 | 180 |
if(rs.next()){ |
181 |
feature = H2Utils.createFeature(this.store, this.rs, this.featureType);
|
|
181 |
feature = this.store.createFeatureFromResulset(this.rs, this.featureType);
|
|
182 | 182 |
} else { |
183 | 183 |
rs.close(); |
184 | 184 |
rs.getStatement().close(); |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2FeatureCollectionEditingFiltered.java | ||
---|---|---|
115 | 115 |
protected class H2Iterator implements Iterator{ |
116 | 116 |
private Iterator dbIter; |
117 | 117 |
private Iterator mIter; |
118 |
public H2Iterator(JDBCStore store, ResultSet rs, DBFeatureType featureType,FeatureManager fm){
|
|
118 |
public H2Iterator(H2Store store, ResultSet rs, DBFeatureType featureType,FeatureManager fm){
|
|
119 | 119 |
this.dbIter = new H2IteratorDB(store,rs,featureType,fm); |
120 | 120 |
this.mIter = new H2IteratorMemory(featureType,fm); |
121 | 121 |
} |
... | ... | |
142 | 142 |
private boolean nextChecked=false; |
143 | 143 |
private IFeature feature; |
144 | 144 |
private ResultSet rs; |
145 |
private JDBCStore store;
|
|
145 |
private H2Store store;
|
|
146 | 146 |
private DBFeatureType featureType; |
147 | 147 |
private boolean rsEOF=false; |
148 | 148 |
private FeatureManager featureManager; |
149 | 149 |
|
150 |
public H2IteratorDB(JDBCStore store, ResultSet rs, DBFeatureType featureType, FeatureManager featureManager){
|
|
150 |
public H2IteratorDB(H2Store store, ResultSet rs, DBFeatureType featureType, FeatureManager featureManager){
|
|
151 | 151 |
this.store = store; |
152 | 152 |
this.rs = rs; |
153 | 153 |
this.featureType = featureType; |
... | ... | |
216 | 216 |
IFeature feature=null; |
217 | 217 |
try { |
218 | 218 |
if(rs.next()){ |
219 |
feature=H2Utils.createFeature(this.store, this.rs, featureType);
|
|
219 |
feature=this.store.createFeatureFromResulset(this.rs, featureType);
|
|
220 | 220 |
} |
221 | 221 |
} catch (java.sql.SQLException e) { |
222 | 222 |
throw new RuntimeException( |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2FeatureCollectionEditing.java | ||
---|---|---|
112 | 112 |
private boolean nextChecked=false; |
113 | 113 |
private IFeature feature; |
114 | 114 |
private ResultSet rs; |
115 |
private JDBCStore store;
|
|
115 |
private H2Store store;
|
|
116 | 116 |
private DBFeatureType featureType; |
117 | 117 |
private boolean rsEOF=false; |
118 | 118 |
|
119 |
public H2Iterator(JDBCStore store, ResultSet rs, DBFeatureType featureType){
|
|
119 |
public H2Iterator(H2Store store, ResultSet rs, DBFeatureType featureType){
|
|
120 | 120 |
this.store = store; |
121 | 121 |
this.rs = rs; |
122 | 122 |
this.featureType = featureType; |
... | ... | |
188 | 188 |
IFeature feature=null; |
189 | 189 |
try { |
190 | 190 |
if(rs.next()){ |
191 |
feature=H2Utils.createFeature(this.store, this.rs, featureType);
|
|
191 |
feature=this.store.createFeatureFromResulset(this.rs, featureType);
|
|
192 | 192 |
} |
193 | 193 |
} catch (java.sql.SQLException e) { |
194 | 194 |
throw new RuntimeException( |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2FeaturesWriter.java | ||
---|---|---|
20 | 20 |
import org.gvsig.data.datastores.vectorial.db.DBAttributeDescriptor; |
21 | 21 |
import org.gvsig.data.datastores.vectorial.db.DBFeatureType; |
22 | 22 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCAttributeDescriptor; |
23 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCFeature; |
|
23 | 24 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCFeaturesWriter; |
24 | 25 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCStore; |
25 | 26 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCTypes; |
... | ... | |
44 | 45 |
DBFeatureType featureType; |
45 | 46 |
boolean bCreateTable=false; |
46 | 47 |
private String toEncode; |
47 |
H2Store store;
|
|
48 |
JDBCStore store;
|
|
48 | 49 |
H2StoreParameters parameters; |
49 | 50 |
|
50 | 51 |
private PreparedStatement insertSt; |
... | ... | |
57 | 58 |
} |
58 | 59 |
|
59 | 60 |
public void init(IFeatureStore store) { |
60 |
this.store = (H2Store)store; |
|
61 |
H2Store h2Store = (H2Store)store; |
|
62 |
this.store = h2Store; |
|
63 |
|
|
61 | 64 |
this.parameters=(H2StoreParameters)store.getParameters(); |
62 | 65 |
|
63 | 66 |
this.featureType = (DBFeatureType)this.store.getDefaultFeatureType(); |
64 |
conex = this.store.getConnection();
|
|
67 |
conex = h2Store.getConnection();
|
|
65 | 68 |
} |
66 | 69 |
|
67 | 70 |
public void postProcess() throws OpenException, WriteException { |
... | ... | |
95 | 98 |
System.out.println("sqlCreate =" + sqlCreate); |
96 | 99 |
st.execute(sqlCreate); |
97 | 100 |
|
98 |
// conex.commit(); |
|
99 | 101 |
} |
100 | 102 |
|
101 |
// fieldManager = new JdbcFieldManager(((ConnectionJDBC)conex).getConnection(), lyrDef.getTableName()); |
|
102 | 103 |
|
103 | 104 |
} catch (SQLException e) { |
104 | 105 |
e.printStackTrace(); |
105 |
// throw new InitializeWriterException(getName(),e); |
|
106 | 106 |
} |
107 |
|
|
108 |
// ResultSet rsAux; |
|
109 |
// try { |
|
110 |
//// conex.setAutoCommit(false); |
|
111 |
//// alterTable(); |
|
112 |
// |
|
113 |
//// rsAux = st.executeQuery("SHOW server_encoding;"); |
|
114 |
//// rsAux.next(); |
|
115 |
//// String serverEncoding = rsAux.getString(1); |
|
116 |
//// System.out.println("Server encoding = " + serverEncoding); |
|
117 |
// // st.execute("SET CLIENT_ENCODING TO 'UNICODE';"); |
|
118 |
// // Intentamos convertir nuestras cadenas a ese encode. |
|
119 |
//// setEncoding(serverEncoding); |
|
120 |
// } catch (SQLException e) { |
|
121 |
// throw new InitializeWriterException("H2",e); |
|
122 |
// } |
|
123 | 107 |
} |
124 | 108 |
|
125 | 109 |
public void deleteFeature(IFeature feature) throws WriteException { |
126 | 110 |
Statement st; |
127 |
String sqlDelete = getSqlDeleteFeature(featureType, feature); |
|
111 |
String sqlDelete = getSqlDeleteFeature(featureType, (JDBCFeature)feature);
|
|
128 | 112 |
System.out.println("sql = " + sqlDelete); |
129 | 113 |
try { |
130 | 114 |
st = this.conex.createStatement(); |
... | ... | |
378 | 362 |
|
379 | 363 |
} |
380 | 364 |
|
381 |
public String getSqlDeleteFeature(DBFeatureType dbFeatureType, IFeature feature) {
|
|
365 |
public String getSqlDeleteFeature(DBFeatureType dbFeatureType, JDBCFeature feature) {
|
|
382 | 366 |
StringBuffer sqlBuf = new StringBuffer("DELETE FROM " |
383 | 367 |
+ this.parameters.tableID() + " WHERE "); |
384 | 368 |
String sql = null; |
385 |
sqlBuf.append(H2Utils.getFilterForID(dbFeatureType, feature));
|
|
369 |
sqlBuf.append(((JDBCFeature)feature).getFilterForID());
|
|
386 | 370 |
sql = sqlBuf.toString(); |
387 | 371 |
|
388 | 372 |
return sql; |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2FeatureCollectionWithFeatureID.java | ||
---|---|---|
1 | 1 |
package org.gvsig.data.datastores.vectorial.db.jdbc.h2; |
2 | 2 |
|
3 |
import org.gvsig.data.datastores.vectorial.db.DBFeatureType; |
|
3 | 4 |
import org.gvsig.data.datastores.vectorial.db.jdbc.AbstractJDBCDataFeatureCollectionWithFeatureID; |
4 | 5 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCStore; |
5 | 6 |
import org.gvsig.data.exception.ReadException; |
... | ... | |
9 | 10 |
|
10 | 11 |
|
11 | 12 |
public class H2FeatureCollectionWithFeatureID extends AbstractJDBCDataFeatureCollectionWithFeatureID { |
12 |
H2FeatureCollectionWithFeatureID(FeatureManager fm,H2Store store,IFeatureType type, String filter,String order) throws ReadException {
|
|
13 |
H2FeatureCollectionWithFeatureID(FeatureManager fm,JDBCStore store,IFeatureType type, String filter,String order) throws ReadException {
|
|
13 | 14 |
init(fm, store, type,filter, order); |
14 | 15 |
} |
15 | 16 |
|
16 | 17 |
public IFeatureCollection newBaseDataFeatureCollection(JDBCStore store, IFeatureType featureType, String filter, String order) { |
17 |
return new H2FeatureCollection((H2Store)store,this.featureType,filter,order); |
|
18 |
return new H2FeatureCollection((H2Store)store,(DBFeatureType)this.featureType,filter,order);
|
|
18 | 19 |
} |
19 | 20 |
|
20 | 21 |
} |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2Store.java | ||
---|---|---|
3 | 3 |
import java.lang.ref.WeakReference; |
4 | 4 |
import java.sql.Connection; |
5 | 5 |
import java.sql.ResultSet; |
6 |
import java.sql.Statement; |
|
7 |
import java.util.ArrayList; |
|
8 |
import java.util.List; |
|
6 |
import java.sql.SQLException; |
|
9 | 7 |
import java.util.Locale; |
10 | 8 |
|
11 | 9 |
import org.gvsig.data.IDataCollection; |
... | ... | |
14 | 12 |
import org.gvsig.data.datastores.vectorial.db.DBFeatureType; |
15 | 13 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCFeaturesWriter; |
16 | 14 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCStore; |
15 |
import org.gvsig.data.datastores.vectorial.db.jdbc.WKBParser2; |
|
17 | 16 |
import org.gvsig.data.exception.CloseException; |
18 | 17 |
import org.gvsig.data.exception.InitializeException; |
19 | 18 |
import org.gvsig.data.exception.OpenException; |
20 | 19 |
import org.gvsig.data.exception.ReadException; |
21 | 20 |
import org.gvsig.data.spatialprovisional.IExtent; |
22 | 21 |
import org.gvsig.data.vectorial.IFeature; |
22 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
|
23 | 23 |
import org.gvsig.data.vectorial.IFeatureCollection; |
24 |
import org.gvsig.data.vectorial.IFeatureID; |
|
25 | 24 |
import org.gvsig.data.vectorial.IFeatureType; |
26 | 25 |
import org.gvsig.metadata.IMetadata; |
27 |
import org.gvsig.metadata.IMetadataManager; |
|
28 |
import org.gvsig.metadata.MetadataManager; |
|
29 | 26 |
|
27 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
28 |
|
|
30 | 29 |
public class H2Store extends JDBCStore{ |
31 | 30 |
public static final String CONNECTION_STRING = "h2"; |
32 | 31 |
public static String DATASTORE_NAME = "H2Store"; |
33 |
protected static Locale ukLocale = new Locale("en", "UK"); // English, UK version |
|
34 |
public DBFeatureType featureType; |
|
35 |
protected IMetadata metadata; |
|
32 |
private static WKBParser2 wkbParser = new WKBParser2(); |
|
36 | 33 |
|
37 |
|
|
38 |
|
|
39 |
public H2StoreParameters getParametersH2(){ |
|
34 |
protected static Locale ukLocale = new Locale("en", "UK"); // English, UK version |
|
35 |
public H2StoreParameters getParametersH2(){ |
|
40 | 36 |
return (H2StoreParameters)this.parameters; |
41 | 37 |
} |
42 | 38 |
|
... | ... | |
120 | 116 |
|
121 | 117 |
IFeatureCollection coll; |
122 | 118 |
if (featureManager == null){ |
123 |
coll=new H2FeatureCollection(this,type,filter,order); |
|
119 |
coll=new H2FeatureCollection(this,(DBFeatureType)type,filter,order);
|
|
124 | 120 |
}else{ |
125 | 121 |
if ((order != null && order != "")){ |
126 | 122 |
coll=new H2FeatureCollectionWithFeatureID(featureManager,this,type,filter,order); |
... | ... | |
139 | 135 |
return coll; |
140 | 136 |
} |
141 | 137 |
|
142 |
public IFeature getFeatureByID(IFeatureID id) throws ReadException { |
|
143 |
return getFeatureByID(featureType,((H2FeatureID)id).getKey()); |
|
144 |
} |
|
145 |
|
|
146 |
public IFeature getFeatureByID(IFeatureType featureType2, Object[] featureKey) throws ReadException { |
|
147 |
if (useSqlSource){ |
|
148 |
throw new ReadException(this.getName(), |
|
149 |
new UnsupportedOperationException("Unsuported featureByID in sqlSource mode")); |
|
150 |
} |
|
151 |
ResultSet rs=null; |
|
152 |
try{ |
|
153 |
this.open(); |
|
154 |
Statement st=this.getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); |
|
155 |
String sql = this.getSqlSelectPart() + " WHERE "+ H2Utils.getFilterForID(this.featureType, featureKey); |
|
156 |
rs=st.executeQuery(sql); |
|
157 |
if (rs.isLast()) { |
|
158 |
|
|
159 |
return null; |
|
160 |
}else{ |
|
161 |
if(rs.next()){ |
|
162 |
return H2Utils.createFeature(this, rs, this.featureType); |
|
163 |
} |
|
164 |
|
|
165 |
} |
|
166 |
|
|
167 |
} catch (java.sql.SQLException e) { |
|
168 |
e.printStackTrace(); |
|
169 |
throw new ReadException(DATASTORE_NAME, e); |
|
170 |
} finally{ |
|
171 |
if (rs != null) |
|
172 |
try { |
|
173 |
rs.close(); |
|
174 |
} catch (java.sql.SQLException e) { |
|
175 |
// TODO ????? |
|
176 |
e.printStackTrace(); |
|
177 |
} |
|
178 |
} |
|
179 |
return null; |
|
180 |
} |
|
181 |
|
|
182 | 138 |
protected Connection getConnection(){ |
183 | 139 |
// FIXME: OJO REsource manager |
184 | 140 |
return this.connection; |
... | ... | |
257 | 213 |
return writer; |
258 | 214 |
} |
259 | 215 |
|
216 |
public IDataExplorer getExplorer() { |
|
217 |
// TODO Auto-generated method stub |
|
218 |
return null; |
|
219 |
} |
|
260 | 220 |
public IMetadata getMetadata() { |
261 | 221 |
if (metadata==null){ |
262 |
IMetadataManager manager=MetadataManager.getManager(); |
|
263 |
metadata=manager.create(DATASTORE_NAME); |
|
264 |
//TODO: Apadir los meteadatos |
|
222 |
IMetadata tmp=super.getMetadata(); |
|
223 |
|
|
224 |
return tmp; |
|
225 |
}else{ |
|
226 |
return super.getMetadata(); |
|
265 | 227 |
} |
266 |
return metadata; |
|
267 |
} |
|
268 | 228 |
|
269 |
|
|
270 |
public IFeatureType getDefaultFeatureType() { |
|
271 |
// TODO Auto-generated method stub |
|
272 |
return this.featureType; |
|
273 | 229 |
} |
274 | 230 |
|
231 |
static String getConnectionResourceID(String dbUrl,String dbUser){ |
|
232 |
return H2Store.CONNECTION_STRING+";"+dbUrl+";"+dbUser; |
|
275 | 233 |
|
276 |
public Object getDefaultLabelingStrategy() { |
|
277 |
// TODO Auto-generated method stub |
|
278 |
return null; |
|
279 | 234 |
} |
280 | 235 |
|
236 |
protected void loadValueFromResulset(ResultSet rs, IFeature feature, IFeatureAttributeDescriptor attr) throws ReadException { |
|
237 |
IGeometry geom; |
|
238 |
String name = attr.getName(); |
|
239 |
try{ |
|
240 |
if (attr.getDataType().equals(IFeatureAttributeDescriptor.TYPE_GEOMETRY)) { |
|
241 |
byte[] data = rs.getBytes(name); |
|
281 | 242 |
|
282 |
public Object getDefaultLegend() { |
|
283 |
// TODO Auto-generated method stub |
|
284 |
return null; |
|
285 |
} |
|
243 |
if (data == null) { |
|
244 |
geom = null; |
|
245 |
} else{ |
|
246 |
geom = wkbParser.parse(data); |
|
247 |
} |
|
248 |
// feature.setDefaultGeometry(geom); |
|
249 |
feature.setGeometry(name,geom); |
|
250 |
} else { |
|
251 |
feature.set(name, rs.getObject(name)); |
|
252 |
} |
|
253 |
} catch (SQLException e) { |
|
254 |
throw new ReadException(this.getName(),e); |
|
255 |
} |
|
286 | 256 |
|
287 | 257 |
|
288 |
public List getFeatureTypes() { |
|
289 |
ArrayList list = new ArrayList(); |
|
290 |
list.add(this.featureType); |
|
291 |
return list; |
|
292 | 258 |
} |
293 | 259 |
|
294 | 260 |
|
295 |
public boolean isWithDefaultLegend() { |
|
296 |
// TODO Auto-generated method stub |
|
297 |
return false; |
|
261 |
protected IFeature newFeatureInstance(DBFeatureType featureType, Object[] pk) { |
|
262 |
return new H2Feature(featureType,this,pk); |
|
298 | 263 |
} |
299 | 264 |
|
300 |
public IDataExplorer getExplorer() { |
|
301 |
// TODO Auto-generated method stub |
|
302 |
return null; |
|
265 |
IFeature createFeatureFromResulset(ResultSet rs, DBFeatureType featureType2) throws ReadException { |
|
266 |
return this.createFeature(rs, featureType2); |
|
303 | 267 |
} |
268 |
|
|
304 | 269 |
} |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresqlbin/PostgresqlBinStore.java | ||
---|---|---|
1 | 1 |
package org.gvsig.data.datastores.vectorial.db.jdbc.postgresqlbin; |
2 | 2 |
|
3 | 3 |
import java.lang.ref.WeakReference; |
4 |
import java.math.BigDecimal; |
|
5 |
import java.nio.ByteBuffer; |
|
4 | 6 |
import java.sql.Connection; |
7 |
import java.sql.Date; |
|
5 | 8 |
import java.sql.ResultSet; |
9 |
import java.sql.SQLException; |
|
6 | 10 |
import java.sql.Statement; |
11 |
import java.sql.Timestamp; |
|
12 |
import java.sql.Types; |
|
7 | 13 |
import java.util.ArrayList; |
8 | 14 |
import java.util.List; |
9 | 15 |
import java.util.Locale; |
... | ... | |
11 | 17 |
import org.gvsig.data.IDataCollection; |
12 | 18 |
import org.gvsig.data.IDataExplorer; |
13 | 19 |
import org.gvsig.data.datastores.vectorial.db.DBFeatureType; |
20 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCAttributeDescriptor; |
|
14 | 21 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCFeaturesWriter; |
15 | 22 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCStore; |
23 |
import org.gvsig.data.datastores.vectorial.db.jdbc.postgresql.PostGIS2Geometry; |
|
16 | 24 |
import org.gvsig.data.datastores.vectorial.db.jdbc.postgresql.PostgresqlFeatureID; |
17 | 25 |
import org.gvsig.data.datastores.vectorial.db.jdbc.postgresql.PostgresqlStore; |
18 | 26 |
import org.gvsig.data.datastores.vectorial.db.jdbc.postgresql.PostgresqlStoreParameters; |
... | ... | |
23 | 31 |
import org.gvsig.data.exception.ReadException; |
24 | 32 |
import org.gvsig.data.spatialprovisional.IExtent; |
25 | 33 |
import org.gvsig.data.vectorial.IFeature; |
34 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
|
26 | 35 |
import org.gvsig.data.vectorial.IFeatureCollection; |
27 | 36 |
import org.gvsig.data.vectorial.IFeatureID; |
28 | 37 |
import org.gvsig.data.vectorial.IFeatureType; |
29 | 38 |
import org.gvsig.metadata.IMetadata; |
30 |
import org.gvsig.metadata.IMetadataManager; |
|
31 |
import org.gvsig.metadata.MetadataManager; |
|
39 |
import org.postgis.PGgeometry; |
|
32 | 40 |
|
41 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
42 |
import com.iver.cit.gvsig.fmap.drivers.XTypes; |
|
43 |
|
|
33 | 44 |
public class PostgresqlBinStore extends PostgresqlStore{ |
34 | 45 |
public static final String CONNECTION_STRING = "postgresql"; |
35 | 46 |
public static String DATASTORE_NAME = "PostgresqlStore"; |
36 | 47 |
protected static Locale ukLocale = new Locale("en", "UK"); // English, UK version |
37 |
private DBFeatureType featureType; |
|
38 |
protected IMetadata metadata; |
|
39 |
|
|
40 |
PostgresqlBinStoreParameters getParametersPostgresql(){ |
|
48 |
PostgresqlBinStoreParameters getParametersPostgresql(){ |
|
41 | 49 |
return (PostgresqlBinStoreParameters)this.parameters; |
42 | 50 |
} |
43 | 51 |
|
... | ... | |
97 | 105 |
ResultSet rs=null; |
98 | 106 |
try{ |
99 | 107 |
this.open(); |
108 |
|
|
100 | 109 |
Statement st=this.getConnection().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); |
101 |
String sql = this.getSqlSelectPart() + " WHERE "+ PostgresqlBinStoreUtils.getFliterForID(this.featureType, featureKey); |
|
102 |
rs=st.executeQuery(sql); |
|
110 |
String sql = this.getSqlSelectPart() + " WHERE "+ this.getFilterForID(this.featureType, featureKey); |
|
111 |
String cursorName = PostgresqlBinStoreUtils.createCursorName(); |
|
112 |
String mSql="BEGIN"; |
|
113 |
st.execute(mSql); |
|
114 |
mSql="declare " + cursorName + " binary cursor for " + sql; |
|
115 |
st.execute(mSql); |
|
116 |
rs=st.executeQuery("fetch 1 in "+ cursorName); |
|
103 | 117 |
if (rs.isLast()) { |
104 | 118 |
|
105 | 119 |
return null; |
106 | 120 |
}else{ |
107 | 121 |
if(rs.next()){ |
108 |
return PostgresqlBinStoreUtils.createFeature(this, rs, this.featureType);
|
|
122 |
return this.createFeature(rs, this.featureType);
|
|
109 | 123 |
} |
110 | 124 |
|
111 | 125 |
} |
... | ... | |
160 | 174 |
return null; |
161 | 175 |
} |
162 | 176 |
|
163 |
public IMetadata getMetadata() { |
|
164 |
if (metadata==null){ |
|
165 |
IMetadataManager manager=MetadataManager.getManager(); |
|
166 |
metadata=manager.create(DATASTORE_NAME); |
|
167 |
//TODO: Apadir los meteadatos |
|
168 |
} |
|
169 |
return metadata; |
|
170 |
} |
|
171 |
|
|
172 |
|
|
173 | 177 |
public IDataExplorer getExplorer() { |
174 | 178 |
// TODO Auto-generated method stub |
175 | 179 |
return null; |
... | ... | |
181 | 185 |
// return super.isEditable(); |
182 | 186 |
} |
183 | 187 |
|
188 |
protected void loadValueFromResulset(ResultSet rs, IFeature feature, IFeatureAttributeDescriptor attr) throws ReadException { |
|
189 |
String name = attr.getName(); |
|
190 |
Object value = null; |
|
191 |
try { |
|
192 |
value = getFieldValueFromBinaryCursor(rs, (JDBCAttributeDescriptor)attr); |
|
193 |
if (attr.getDataType().equals(IFeatureAttributeDescriptor.TYPE_GEOMETRY)) { |
|
194 |
feature.setGeometry(name,value); |
|
195 |
} else { |
|
196 |
feature.set(name, value); |
|
197 |
} |
|
198 |
} catch (java.sql.SQLException e) { |
|
199 |
throw new ReadException("CreateFeature",e); |
|
200 |
} |
|
201 |
} |
|
184 | 202 |
|
203 |
public IMetadata getMetadata() { |
|
204 |
if (metadata==null){ |
|
205 |
IMetadata tmp=super.getMetadata(); |
|
206 |
|
|
207 |
return tmp; |
|
208 |
}else{ |
|
209 |
return super.getMetadata(); |
|
210 |
} |
|
211 |
|
|
212 |
} |
|
213 |
|
|
214 |
static Object getFieldValueFromBinaryCursor(ResultSet aRs, JDBCAttributeDescriptor attrDescriptor) throws java.sql.SQLException { |
|
215 |
int fieldId = attrDescriptor.ordinal(); |
|
216 |
int sqlType = attrDescriptor.getSqlType(); |
|
217 |
byte[] byteBuf = aRs.getBytes(fieldId+1); |
|
218 |
if (byteBuf == null) |
|
219 |
return null; |
|
220 |
else { |
|
221 |
|
|
222 |
ByteBuffer buf = ByteBuffer.wrap(byteBuf); |
|
223 |
|
|
224 |
if (attrDescriptor.getDataType().equals(IFeatureAttributeDescriptor.TYPE_GEOMETRY)){ |
|
225 |
if (attrDescriptor.getDataType() == IFeatureAttributeDescriptor.TYPE_GEOMETRY){ |
|
226 |
if (byteBuf == null) |
|
227 |
return null; |
|
228 |
// return wkbParser.parse(byteBuf); |
|
229 |
return null; |
|
230 |
} |
|
231 |
|
|
232 |
} |
|
233 |
|
|
234 |
switch (sqlType) { |
|
235 |
case Types.VARCHAR: |
|
236 |
//FIXME Error |
|
237 |
return aRs.getString(fieldId); |
|
238 |
// return new String(buf.toString()); |
|
239 |
case Types.FLOAT: |
|
240 |
return new Float(buf.getFloat()); |
|
241 |
case Types.DOUBLE: |
|
242 |
return new Double(buf.getDouble()); |
|
243 |
case Types.REAL: |
|
244 |
return new Float(buf.getFloat()); |
|
245 |
case Types.INTEGER: |
|
246 |
return new Integer(buf.getInt()); |
|
247 |
case Types.BIGINT: |
|
248 |
return new Long(buf.getLong()); |
|
249 |
case Types.BIT: |
|
250 |
return new Boolean(byteBuf[0] == 1); |
|
251 |
case Types.BOOLEAN: |
|
252 |
return new Boolean(aRs.getBoolean(fieldId)); |
|
253 |
case Types.DATE: |
|
254 |
long daysAfter2000 = buf.getInt() + 1; |
|
255 |
long msecs = daysAfter2000*24*60*60*1000; |
|
256 |
long real_msecs_date1 = (long) (XTypes.NUM_msSecs2000 + msecs); |
|
257 |
Date realDate1 = new Date(real_msecs_date1); |
|
258 |
return realDate1; |
|
259 |
case Types.TIME: |
|
260 |
// TODO: |
|
261 |
// throw new RuntimeException("TIME type not implemented yet"); |
|
262 |
return "NOT IMPLEMENTED YET"; |
|
263 |
case Types.TIMESTAMP: |
|
264 |
double segsReferredTo2000 = buf.getDouble(); |
|
265 |
long real_msecs = (long) (XTypes.NUM_msSecs2000 + segsReferredTo2000*1000); |
|
266 |
Timestamp valTimeStamp = new Timestamp(real_msecs); |
|
267 |
return valTimeStamp; |
|
268 |
case Types.NUMERIC: |
|
269 |
// System.out.println(metaData.getColumnName(fieldId) + " " |
|
270 |
// + metaData.getColumnClassName(fieldId)); |
|
271 |
short ndigits = buf.getShort(); |
|
272 |
short weight = buf.getShort(); |
|
273 |
short sign = buf.getShort(); |
|
274 |
short dscale = buf.getShort(); |
|
275 |
String strAux; |
|
276 |
if (sign == 0) |
|
277 |
strAux = "+"; |
|
278 |
else |
|
279 |
strAux = "-"; |
|
280 |
|
|
281 |
for (int iDigit = 0; iDigit < ndigits; iDigit++) { |
|
282 |
short digit = buf.getShort(); |
|
283 |
strAux = strAux + digit; |
|
284 |
if (iDigit == weight) |
|
285 |
strAux = strAux + "."; |
|
286 |
|
|
287 |
} |
|
288 |
strAux = strAux + "0"; |
|
289 |
BigDecimal dec; |
|
290 |
dec = new BigDecimal(strAux); |
|
291 |
// System.out.println(ndigits + "_" + weight + "_" + dscale |
|
292 |
// + "_" + strAux); |
|
293 |
// System.out.println(strAux + " Big= " + dec); |
|
294 |
return new Double(dec.doubleValue()); |
|
295 |
|
|
296 |
|
|
297 |
default: |
|
298 |
//TODO ??? |
|
299 |
throw new RuntimeException("Unsuported Type"); |
|
300 |
} |
|
301 |
|
|
302 |
} |
|
303 |
} |
|
304 |
|
|
305 |
protected Object[] getPkFromResulsetBinary(ResultSet rs, DBFeatureType featureType) throws SQLException { |
|
306 |
String[] fieldsId = featureType.getFieldsId(); |
|
307 |
Object[] result = new Object[fieldsId.length]; |
|
308 |
for (int i=0;i<fieldsId.length;i++){ |
|
309 |
result[i] = getFieldValueFromBinaryCursor( |
|
310 |
rs, |
|
311 |
(JDBCAttributeDescriptor)featureType.get( |
|
312 |
featureType.getFieldIndex(fieldsId[i]) |
|
313 |
) |
|
314 |
); |
|
315 |
|
|
316 |
} |
|
317 |
return result; |
|
318 |
} |
|
319 |
|
|
320 |
IFeature createFeatureFromResulset(ResultSet rs, DBFeatureType featureType2) throws ReadException { |
|
321 |
return this.createFeature(rs, featureType2); |
|
322 |
} |
|
323 |
|
|
185 | 324 |
} |
trunk/libraries/libDataSourceDBBaseDrivers/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresqlbin/PostgresqlBinStoreUtils.java | ||
---|---|---|
41 | 41 |
private static int cursorCount=0; |
42 | 42 |
private static String baseCursorName=null; |
43 | 43 |
|
44 |
|
|
45 |
static IFeature createFeatureFromBinaryCursor(JDBCStore store, ResultSet rs, DBFeatureType featureType) throws ReadException { |
|
46 |
|
|
47 |
PostgresqlBinFeature feature=null; |
|
48 |
|
|
49 |
|
|
50 |
Object[] pk; |
|
51 |
try { |
|
52 |
pk = getPkFromResulsetBinary(rs, featureType); |
|
53 |
|
|
54 |
feature=new PostgresqlBinFeature(featureType,store,pk); |
|
55 |
|
|
56 |
Iterator iter = featureType.iterator(); |
|
57 |
IGeometry geom = null; |
|
58 |
while (iter.hasNext()) { |
|
59 |
JDBCAttributeDescriptor fad=(JDBCAttributeDescriptor)iter.next(); |
|
60 |
feature.set(fad.getName(), getFieldValueFromBinaryCursor(rs, fad)); |
|
61 |
} |
|
62 |
|
|
63 |
return feature; |
|
64 |
} catch (java.sql.SQLException e) { |
|
65 |
throw new ReadException("CreateFeature",e); |
|
66 |
} |
|
67 |
} |
|
68 |
|
|
69 | 44 |
static Connection getConnection(String dbUrl, String dbUser, String dbPass) throws InitializeException { |
70 | 45 |
//TODO: Aqu? habria que implementar la llamada |
71 | 46 |
// al Resource Manager para comprobar si ya hay |
... | ... | |
100 | 75 |
|
101 | 76 |
} |
102 | 77 |
|
103 |
static Object getFieldValueFromBinaryCursor(ResultSet aRs, JDBCAttributeDescriptor attrDescriptor) throws java.sql.SQLException { |
|
104 |
int fieldId = attrDescriptor.ordinal(); |
|
105 |
int sqlType = attrDescriptor.getSqlType(); |
|
106 |
byte[] byteBuf = aRs.getBytes(fieldId+1); |
|
107 |
if (byteBuf == null) |
|
108 |
return null; |
|
109 |
else { |
|
110 |
ByteBuffer buf = ByteBuffer.wrap(byteBuf); |
|
111 | 78 |
|
112 |
switch (sqlType) { |
|
113 |
case Types.VARCHAR: |
|
114 |
//FIXME Error |
|
115 |
return aRs.getString(fieldId); |
|
116 |
// return new String(buf.toString()); |
|
117 |
case Types.FLOAT: |
|
118 |
return new Float(buf.getFloat()); |
|
119 |
case Types.DOUBLE: |
|
120 |
return new Double(buf.getDouble()); |
|
121 |
case Types.REAL: |
|
122 |
return new Float(buf.getFloat()); |
|
123 |
case Types.INTEGER: |
|
124 |
return new Integer(buf.getInt()); |
|
125 |
case Types.BIGINT: |
|
126 |
return new Long(buf.getLong()); |
|
127 |
case Types.BIT: |
|
128 |
return new Boolean(byteBuf[0] == 1); |
|
129 |
case Types.BOOLEAN: |
|
130 |
return new Boolean(aRs.getBoolean(fieldId)); |
|
131 |
case Types.DATE: |
|
132 |
long daysAfter2000 = buf.getInt() + 1; |
|
133 |
long msecs = daysAfter2000*24*60*60*1000; |
|
134 |
long real_msecs_date1 = (long) (XTypes.NUM_msSecs2000 + msecs); |
|
135 |
Date realDate1 = new Date(real_msecs_date1); |
|
136 |
return realDate1; |
|
137 |
case Types.TIME: |
|
138 |
// TODO: |
|
139 |
// throw new RuntimeException("TIME type not implemented yet"); |
|
140 |
return "NOT IMPLEMENTED YET"; |
|
141 |
case Types.TIMESTAMP: |
|
142 |
double segsReferredTo2000 = buf.getDouble(); |
|
143 |
long real_msecs = (long) (XTypes.NUM_msSecs2000 + segsReferredTo2000*1000); |
|
144 |
Timestamp valTimeStamp = new Timestamp(real_msecs); |
|
145 |
return valTimeStamp; |
|
146 |
case Types.NUMERIC: |
|
147 |
// System.out.println(metaData.getColumnName(fieldId) + " " |
|
148 |
// + metaData.getColumnClassName(fieldId)); |
|
149 |
short ndigits = buf.getShort(); |
|
150 |
short weight = buf.getShort(); |
|
151 |
short sign = buf.getShort(); |
|
152 |
short dscale = buf.getShort(); |
|
153 |
String strAux; |
|
154 |
if (sign == 0) |
|
155 |
strAux = "+"; |
|
156 |
else |
|
157 |
strAux = "-"; |
|
158 |
|
|
159 |
for (int iDigit = 0; iDigit < ndigits; iDigit++) { |
|
160 |
short digit = buf.getShort(); |
|
161 |
strAux = strAux + digit; |
|
162 |
if (iDigit == weight) |
|
163 |
strAux = strAux + "."; |
|
164 |
|
|
165 |
} |
|
166 |
strAux = strAux + "0"; |
|
167 |
BigDecimal dec; |
|
168 |
dec = new BigDecimal(strAux); |
|
169 |
// System.out.println(ndigits + "_" + weight + "_" + dscale |
|
170 |
// + "_" + strAux); |
|
171 |
// System.out.println(strAux + " Big= " + dec); |
|
172 |
return new Double(dec.doubleValue()); |
|
173 |
|
|
174 |
|
|
175 |
default: |
|
176 |
if (attrDescriptor.getDataType() == IFeatureAttributeDescriptor.TYPE_GEOMETRY){ |
|
177 |
if (byteBuf == null) |
|
178 |
return null; |
|
179 |
return wkbParser.parse(byteBuf); |
|
180 |
} |
|
181 |
return null; |
|
182 |
} |
|
183 |
|
|
184 |
} |
|
185 |
} |
|
186 |
|
|
187 |
|
|
188 |
static Object[] getPkFromResulsetBinary(ResultSet rs, DBFeatureType featureType) throws java.sql.SQLException{ |
|
189 |
String[] fieldsId = featureType.getFieldsId(); |
|
190 |
Object[] result = new Object[fieldsId.length]; |
|
191 |
for (int i=0;i<fieldsId.length;i++){ |
|
192 |
result[i] = getFieldValueFromBinaryCursor( |
|
193 |
rs, |
|
194 |
(JDBCAttributeDescriptor)featureType.get( |
|
195 |
featureType.getFieldIndex(fieldsId[i]) |
|
196 |
) |
|
197 |
); |
|
198 |
|
|
199 |
} |
|
200 |
return result; |
|
201 |
|
|
202 |
} |
|
203 |
|
|
204 |
|
|
205 |
static IFeature createFeature(JDBCStore store,ResultSet rs,DBFeatureType featureType) throws ReadException{ |
|
206 |
|
|
207 |
JDBCFeature feature=null; |
|
208 |
|
|
209 |
|
|
210 |
Object[] pk; |
|
211 |
try { |
|
212 |
pk = getPkFromResulset(rs, featureType); |
|
213 |
|
|
214 |
feature=new PostgresqlBinFeature(featureType,store,pk); |
|
215 |
|
|
216 |
Iterator iter = featureType.iterator(); |
|
217 |
IGeometry geom = null; |
|
218 |
while (iter.hasNext()) { |
|
219 |
IFeatureAttributeDescriptor fad=(IFeatureAttributeDescriptor)iter.next(); |
|
220 |
if (fad.getDataType().equals(IFeatureAttributeDescriptor.TYPE_GEOMETRY)) { |
|
221 |
byte[] data = rs.getBytes(fad.getName()); |
|
222 |
|
|
223 |
if (data == null) { |
|
224 |
geom = null; |
|
225 |
} else{ |
|
226 |
geom = wkbParser.parse(data); |
|
227 |
} |
|
228 |
feature.setGeometry(fad.getName(),geom); |
|
229 |
} else { |
|
230 |
feature.set(fad.getName(), rs.getObject(fad.getName())); |
|
231 |
} |
|
232 |
|
|
233 |
} |
|
234 |
return feature; |
|
235 |
} catch (java.sql.SQLException e) { |
|
236 |
throw new ReadException("CreateFeature",e); |
|
237 |
} |
|
238 |
} |
|
239 |
|
|
240 | 79 |
static String addLimitsToSQL(String aSql,int fetchSize,int page){ |
241 | 80 |
return aSql+ " limit " + fetchSize + " offset " + (fetchSize*page); |
242 | 81 |
} |
... | ... | |
369 | 208 |
|
370 | 209 |
} |
371 | 210 |
|
372 |
|
|
373 |
static String getFliterForID(DBFeatureType featureType, Object[] featureKey) { |
|
374 |
// TODO Auto-generated method stub |
|
375 |
return null; |
|
376 |
} |
|
377 |
|
|
378 |
|
|
379 |
|
|
380 |
protected static String getFliterForID(DBFeatureType fType, IFeature feature){ |
|
381 |
return getFliterForID(fType, getPkFromFeature(feature,fType)); |
|
382 |
} |
|
383 |
|
|
384 |
|
|
385 |
protected static Object[] getPkFromResulset(ResultSet rs, DBFeatureType featureType) throws java.sql.SQLException{ |
|
386 |
String[] fieldsId = featureType.getFieldsId(); |
|
387 |
Object[] result = new Object[fieldsId.length]; |
|
388 |
for (int i=0;i<fieldsId.length;i++){ |
|
389 |
result[i] = rs.getObject(fieldsId[i]); |
|
390 |
} |
|
391 |
return result; |
|
392 |
|
|
393 |
} |
|
394 |
|
|
395 |
|
|
396 |
|
|
397 |
protected static Object[] getPkFromFeature(IFeature feature, DBFeatureType featureType){ |
|
398 |
String[] fieldsId = featureType.getFieldsId(); |
|
399 |
Object[] result = new Object[fieldsId.length]; |
|
400 |
for (int i=0;i<fieldsId.length;i++){ |
|
401 |
result[i] = feature.get(fieldsId[i]); |
|
402 |
} |
|
403 |
return result; |
|
404 |
|
|
405 |
} |
|
406 |
|
|
407 | 211 |
static String getJDBCUrl(String host, String db, String port) { |
408 | 212 |
String url; |
409 | 213 |
url = "jdbc:postgresql://"+host+":" + port +"/"+db; |
Also available in: Unified diff