Revision 20920
trunk/libraries/libFMap_dataDB/src-test/org/gvsig/data/datastores/vectorial/db/jdbc/h2/SHP2H2FeaturesVisitor.java | ||
---|---|---|
9 | 9 |
import java.sql.Statement; |
10 | 10 |
import java.util.Iterator; |
11 | 11 |
|
12 |
import org.gvsig.data.datastores.vectorial.db.jdbc.WKBParser2; |
|
12 | 13 |
import org.gvsig.data.datastores.vectorial.db.jdbc.h2.H2StoreParameters; |
13 | 14 |
import org.gvsig.data.vectorial.IFeature; |
14 | 15 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
15 | 16 |
import org.gvsig.data.vectorial.IFeatureType; |
16 | 17 |
import org.gvsig.data.vectorial.visitor.FeaturesVisitor; |
17 | 18 |
import org.gvsig.exceptions.BaseException; |
19 |
import org.gvsig.fmap.geom.Geometry; |
|
18 | 20 |
|
19 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
20 |
import com.iver.cit.gvsig.fmap.drivers.WKBParser2; |
|
21 |
import com.vividsolutions.jts.io.WKBWriter; |
|
21 | 22 |
|
23 |
|
|
22 | 24 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
23 | 25 |
* |
24 | 26 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
... | ... | |
142 | 144 |
} else if (type.equals(IFeatureAttributeDescriptor.TYPE_STRING)) { |
143 | 145 |
pst.setString(i+2, feature.getString(i)); |
144 | 146 |
} else if (type.equals(IFeatureAttributeDescriptor.TYPE_GEOMETRY)) { |
145 |
IGeometry geom =(IGeometry)feature.getGeometry(i);
|
|
147 |
Geometry geom =(Geometry)feature.getGeometry(i);
|
|
146 | 148 |
if (geom != null){ |
147 |
pst.setBytes( i+2, geom.toWKB());
|
|
149 |
pst.setBytes( i+2, new WKBWriter().write(geom.toJTSGeometry()));
|
|
148 | 150 |
}else{ |
149 | 151 |
System.out.print("Geometry null!!!"); |
150 | 152 |
pst.setObject(i+2, null); |
... | ... | |
158 | 160 |
} |
159 | 161 |
catch(SQLException except){ |
160 | 162 |
throw new RuntimeException(except); |
161 |
|
|
162 |
}catch(IOException except){ |
|
163 |
throw new RuntimeException(except); |
|
164 |
|
|
165 | 163 |
} |
166 | 164 |
} |
167 | 165 |
|
trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresql/PostgresqlFeature.java | ||
---|---|---|
4 | 4 |
|
5 | 5 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCFeature; |
6 | 6 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCStore; |
7 |
import org.gvsig.data.datastores.vectorial.db.jdbc.h2.H2Feature; |
|
8 | 7 |
import org.gvsig.data.exception.DataException; |
9 | 8 |
import org.gvsig.data.exception.ReadException; |
10 | 9 |
import org.gvsig.data.vectorial.IFeature; |
... | ... | |
12 | 11 |
import org.gvsig.data.vectorial.IFeatureID; |
13 | 12 |
import org.gvsig.data.vectorial.IFeatureType; |
14 | 13 |
import org.gvsig.data.vectorial.IsNotFeatureSettingException; |
14 |
import org.gvsig.fmap.geom.Geometry; |
|
15 | 15 |
import org.postgis.PGgeometry; |
16 | 16 |
|
17 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
18 | 17 |
|
19 | 18 |
|
20 |
|
|
21 | 19 |
public class PostgresqlFeature extends JDBCFeature{ |
22 | 20 |
|
23 | 21 |
/** |
... | ... | |
50 | 48 |
* @see org.gvsig.data.datastores.vectorial.db.jdbc.JDBCFeature#loadValueFromResulset(java.sql.ResultSet, org.gvsig.data.vectorial.IFeatureAttributeDescriptor) |
51 | 49 |
*/ |
52 | 50 |
protected void loadValueFromResulset(ResultSet rs, IFeatureAttributeDescriptor attr) throws ReadException { |
53 |
IGeometry geom = null;
|
|
51 |
Geometry geom = null; |
|
54 | 52 |
String name = attr.getName(); |
55 | 53 |
|
56 | 54 |
try { |
trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresql/PostgresqlFeaturesWriter.java | ||
---|---|---|
27 | 27 |
import org.gvsig.data.vectorial.IFeatureStore; |
28 | 28 |
import org.gvsig.data.vectorial.IFeatureType; |
29 | 29 |
import org.gvsig.data.vectorial.INewFeatureStoreParameters; |
30 |
import org.gvsig.fmap.geom.Geometry; |
|
30 | 31 |
|
31 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
32 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
33 | 32 |
import com.vividsolutions.jts.io.WKBWriter; |
34 | 33 |
|
35 | 34 |
public class PostgresqlFeaturesWriter extends JDBCFeaturesWriter { |
... | ... | |
290 | 289 |
/** @deprecated ??? |
291 | 290 |
* |
292 | 291 |
*/ |
293 |
public boolean canWriteGeometry(int gvSIGgeometryType) { |
|
294 |
switch (gvSIGgeometryType) { |
|
295 |
case FShape.POINT: |
|
296 |
return true; |
|
297 |
case FShape.LINE: |
|
298 |
return true; |
|
299 |
case FShape.POLYGON: |
|
300 |
return true; |
|
301 |
case FShape.ARC: |
|
302 |
return false; |
|
303 |
case FShape.ELLIPSE: |
|
304 |
return false; |
|
305 |
case FShape.MULTIPOINT: |
|
306 |
return true; |
|
307 |
case FShape.TEXT: |
|
308 |
return false; |
|
309 |
} |
|
310 |
return false; |
|
311 |
} |
|
292 |
// public boolean canWriteGeometry(int gvSIGgeometryType) {
|
|
293 |
// switch (gvSIGgeometryType) {
|
|
294 |
// case FShape.POINT:
|
|
295 |
// return true;
|
|
296 |
// case FShape.LINE:
|
|
297 |
// return true;
|
|
298 |
// case FShape.POLYGON:
|
|
299 |
// return true;
|
|
300 |
// case FShape.ARC:
|
|
301 |
// return false;
|
|
302 |
// case FShape.ELLIPSE:
|
|
303 |
// return false;
|
|
304 |
// case FShape.MULTIPOINT:
|
|
305 |
// return true;
|
|
306 |
// case FShape.TEXT:
|
|
307 |
// return false;
|
|
308 |
// }
|
|
309 |
// return false;
|
|
310 |
// }
|
|
312 | 311 |
|
313 | 312 |
|
314 | 313 |
/** @deprecated ??? |
... | ... | |
461 | 460 |
} |
462 | 461 |
|
463 | 462 |
if (attr.getDataType() == IFeatureAttributeDescriptor.TYPE_GEOMETRY){ |
464 |
IGeometry geom =(IGeometry)feature.get(attr.ordinal());
|
|
463 |
Geometry geom =(Geometry)feature.get(attr.ordinal());
|
|
465 | 464 |
ps.setBytes( |
466 | 465 |
paramIndex, wkbWriter.write(geom.toJTSGeometry()) |
467 | 466 |
); |
trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresql/PostGIS2Geometry.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import java.sql.SQLException; |
4 | 4 |
|
5 |
import org.gvsig.fmap.geom.GeometryFactory; |
|
6 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
|
5 | 7 |
import org.postgis.Geometry; |
6 | 8 |
import org.postgis.LineString; |
7 | 9 |
import org.postgis.LinearRing; |
... | ... | |
11 | 13 |
import org.postgis.Point; |
12 | 14 |
import org.postgis.Polygon; |
13 | 15 |
|
14 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
|
15 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
16 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
|
17 |
|
|
18 | 16 |
/** |
19 | 17 |
* Codigo recogido (en parte) de la lista de desarrollo de gvSIG |
20 | 18 |
* Enviado por: MAU ingmau00 en gmail.com |
... | ... | |
28 | 26 |
public class PostGIS2Geometry { |
29 | 27 |
|
30 | 28 |
|
31 |
public static IGeometry getGeneralPath(PGgeometry geom) throws
|
|
29 |
public static org.gvsig.fmap.geom.Geometry getGeneralPath(PGgeometry geom) throws
|
|
32 | 30 |
SQLException{ |
33 | 31 |
|
34 | 32 |
|
35 | 33 |
|
36 | 34 |
GeneralPathX gp = new GeneralPathX(); |
37 |
IGeometry resultGeom = null;
|
|
35 |
org.gvsig.fmap.geom.Geometry resultGeom = null;
|
|
38 | 36 |
if (geom.getGeoType() == Geometry.POINT) { |
39 | 37 |
Point p = (Point) geom.getGeometry(); |
40 |
resultGeom = ShapeFactory.createPoint2D(p.x, p.y);
|
|
38 |
resultGeom = GeometryFactory.createPoint2D(p.x, p.y);
|
|
41 | 39 |
|
42 | 40 |
} else if ( geom.getGeoType() == Geometry.LINESTRING) { |
43 | 41 |
gp = lineString2GP((LineString) geom.getGeometry()); |
... | ... | |
47 | 45 |
for (int j = 0; j < mls.numLines(); j++) { |
48 | 46 |
gp.append(lineString2GP(mls.getLine(j)), false); |
49 | 47 |
} |
50 |
resultGeom = ShapeFactory.createPolyline2D(gp);
|
|
48 |
resultGeom = GeometryFactory.createPolyline2D(gp);
|
|
51 | 49 |
} else if (geom.getGeoType() == Geometry.POLYGON ) { |
52 | 50 |
gp = polygon2GP((Polygon) geom.getGeometry()); |
53 |
resultGeom = ShapeFactory.createPolygon2D(gp);
|
|
51 |
resultGeom = GeometryFactory.createPolygon2D(gp);
|
|
54 | 52 |
} else if (geom.getGeoType() == Geometry.MULTIPOLYGON) { |
55 | 53 |
MultiPolygon mp = (MultiPolygon) geom.getGeometry(); |
56 | 54 |
|
57 | 55 |
for (int i = 0; i < mp.numPolygons(); i++) { |
58 | 56 |
gp.append(polygon2GP(mp.getPolygon(i)), false); |
59 | 57 |
} |
60 |
resultGeom = ShapeFactory.createPolygon2D(gp);
|
|
58 |
resultGeom = GeometryFactory.createPolygon2D(gp);
|
|
61 | 59 |
} else if (geom.getGeoType() == Geometry.GEOMETRYCOLLECTION) { |
62 | 60 |
//FIXME: Falta Implementar!!! |
63 | 61 |
throw new RuntimeException("geometryCollections not supported by this driver"); |
trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2Feature.java | ||
---|---|---|
13 | 13 |
import org.gvsig.data.vectorial.IFeatureID; |
14 | 14 |
import org.gvsig.data.vectorial.IFeatureType; |
15 | 15 |
import org.gvsig.data.vectorial.IsNotFeatureSettingException; |
16 |
import org.gvsig.fmap.geom.Geometry; |
|
16 | 17 |
|
17 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
18 |
|
|
19 |
|
|
20 |
|
|
21 | 18 |
public class H2Feature extends JDBCFeature{ |
22 | 19 |
|
23 | 20 |
H2Feature(IFeatureType featureType, JDBCStore store, ResultSet rs) throws ReadException { |
... | ... | |
39 | 36 |
} |
40 | 37 |
|
41 | 38 |
protected void loadValueFromResulset(ResultSet rs, IFeatureAttributeDescriptor attr) throws ReadException { |
42 |
IGeometry geom;
|
|
39 |
Geometry geom; |
|
43 | 40 |
String name = attr.getName(); |
44 | 41 |
try{ |
45 | 42 |
if (attr.getDataType().equals(IFeatureAttributeDescriptor.TYPE_GEOMETRY)) { |
trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2FeaturesWriter.java | ||
---|---|---|
1 | 1 |
package org.gvsig.data.datastores.vectorial.db.jdbc.h2; |
2 | 2 |
|
3 |
import java.sql.Connection; |
|
4 | 3 |
import java.sql.DatabaseMetaData; |
5 | 4 |
import java.sql.PreparedStatement; |
6 | 5 |
import java.sql.ResultSet; |
... | ... | |
9 | 8 |
import java.util.Iterator; |
10 | 9 |
|
11 | 10 |
import org.gvsig.data.IDataStoreParameters; |
12 |
import org.gvsig.data.datastores.vectorial.ISelectiveWriter; |
|
13 | 11 |
import org.gvsig.data.datastores.vectorial.db.DBAttributeDescriptor; |
14 | 12 |
import org.gvsig.data.datastores.vectorial.db.DBFeatureType; |
15 | 13 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCFeature; |
16 | 14 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCFeaturesWriter; |
17 | 15 |
import org.gvsig.data.datastores.vectorial.db.jdbc.JDBCTypes; |
18 |
import org.gvsig.data.exception.InitializeException; |
|
19 | 16 |
import org.gvsig.data.exception.InitializeWriterException; |
20 | 17 |
import org.gvsig.data.exception.ReadException; |
21 | 18 |
import org.gvsig.data.exception.WriteException; |
... | ... | |
24 | 21 |
import org.gvsig.data.vectorial.IFeatureStore; |
25 | 22 |
import org.gvsig.data.vectorial.IFeatureType; |
26 | 23 |
import org.gvsig.data.vectorial.INewFeatureStoreParameters; |
24 |
import org.gvsig.fmap.geom.Geometry; |
|
27 | 25 |
|
28 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
29 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
30 | 26 |
import com.vividsolutions.jts.io.WKBWriter; |
31 | 27 |
|
32 | 28 |
class H2FeaturesWriter extends JDBCFeaturesWriter{ |
... | ... | |
242 | 238 |
} |
243 | 239 |
|
244 | 240 |
|
245 |
public boolean canWriteGeometry(int gvSIGgeometryType) { |
|
246 |
switch (gvSIGgeometryType) { |
|
247 |
case FShape.POINT: |
|
248 |
return true; |
|
249 |
case FShape.LINE: |
|
250 |
return true; |
|
251 |
case FShape.POLYGON: |
|
252 |
return true; |
|
253 |
case FShape.ARC: |
|
254 |
return false; |
|
255 |
case FShape.ELLIPSE: |
|
256 |
return false; |
|
257 |
case FShape.MULTIPOINT: |
|
258 |
return true; |
|
259 |
case FShape.TEXT: |
|
260 |
return false; |
|
261 |
} |
|
262 |
return false; |
|
263 |
} |
|
241 |
// public boolean canWriteGeometry(int gvSIGgeometryType) {
|
|
242 |
// switch (gvSIGgeometryType) {
|
|
243 |
// case FShape.POINT:
|
|
244 |
// return true;
|
|
245 |
// case FShape.LINE:
|
|
246 |
// return true;
|
|
247 |
// case FShape.POLYGON:
|
|
248 |
// return true;
|
|
249 |
// case FShape.ARC:
|
|
250 |
// return false;
|
|
251 |
// case FShape.ELLIPSE:
|
|
252 |
// return false;
|
|
253 |
// case FShape.MULTIPOINT:
|
|
254 |
// return true;
|
|
255 |
// case FShape.TEXT:
|
|
256 |
// return false;
|
|
257 |
// }
|
|
258 |
// return false;
|
|
259 |
// }
|
|
264 | 260 |
|
265 | 261 |
|
266 | 262 |
private PreparedStatement getUpdateFeatureStatement(DBFeatureType dbFeatureType) throws SQLException{ |
... | ... | |
318 | 314 |
} |
319 | 315 |
|
320 | 316 |
if (attr.getDataType() == IFeatureAttributeDescriptor.TYPE_GEOMETRY){ |
321 |
IGeometry geom =(IGeometry)feature.get(attr.ordinal());
|
|
317 |
Geometry geom =(Geometry)feature.get(attr.ordinal());
|
|
322 | 318 |
ps.setBytes( |
323 | 319 |
paramIndex, wkbWriter.write(geom.toJTSGeometry()) |
324 | 320 |
); |
trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2Utils.java | ||
---|---|---|
18 | 18 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
19 | 19 |
import org.gvsig.data.vectorial.IsNotAttributeSettingException; |
20 | 20 |
|
21 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
22 | 21 |
|
23 | 22 |
public class H2Utils { |
24 | 23 |
|
... | ... | |
392 | 391 |
|
393 | 392 |
|
394 | 393 |
|
395 |
static void initializeTableEPSG_and_shapeType(Connection conn,String tableID, DBFeatureType dbld) throws ReadException { |
|
396 |
try { |
|
397 |
Statement stAux = conn.createStatement(); |
|
394 |
// static void initializeTableEPSG_and_shapeType(Connection conn,String tableID, DBFeatureType dbld) throws ReadException { |
|
395 |
// try { |
|
396 |
// Statement stAux = conn.createStatement(); |
|
397 |
// |
|
398 |
//// String sql = "SELECT * FROM GEOMETRY_COLUMNS WHERE F_TABLE_NAME = '" |
|
399 |
//// + getTableName() + "' AND F_GEOMETRY_COLUMN = '" + getLyrDef().getFieldGeometry() + "'"; |
|
400 |
// String sql= "SELECT SRID("+dbld.getDefaultGeometry()+"), GeometryType("+dbld.getDefaultGeometry()+") FROM "+tableID +" WHERE "+dbld.getDefaultGeometry()+" is not null LIMIT 1"; |
|
401 |
// |
|
402 |
// ResultSet rs = stAux.executeQuery(sql); |
|
403 |
// if(!rs.next()){ |
|
404 |
// dbld.setDefaultSRS(""); |
|
405 |
// dbld.setGeometryTypes(new int[]{FShape.MULTI}); |
|
406 |
// return; |
|
407 |
// } |
|
408 |
// dbld.setDefaultSRS("EPSG:"+rs.getInt(1)); |
|
409 |
// |
|
410 |
// String geometryType = rs.getString(2); |
|
411 |
// int shapeType = FShape.MULTI; |
|
412 |
// if (geometryType.compareToIgnoreCase("Point") == 0) |
|
413 |
// shapeType = FShape.POINT; |
|
414 |
// else if (geometryType.compareToIgnoreCase("LineString") == 0) |
|
415 |
// shapeType = FShape.LINE; |
|
416 |
// else if (geometryType.compareToIgnoreCase("Polygon") == 0) |
|
417 |
// shapeType = FShape.POLYGON; |
|
418 |
// else if (geometryType.compareToIgnoreCase("MultiPoint") == 0) |
|
419 |
// shapeType = FShape.POINT; |
|
420 |
// else if (geometryType.compareToIgnoreCase("MultiLineString") == 0) |
|
421 |
// shapeType = FShape.LINE; |
|
422 |
// else if (geometryType.compareToIgnoreCase("MultiPolygon") == 0) |
|
423 |
// shapeType = FShape.POLYGON; |
|
424 |
// |
|
425 |
// dbld.setGeometryTypes(new int[]{shapeType}); |
|
426 |
// rs.close(); |
|
427 |
// |
|
428 |
// } catch (java.sql.SQLException e) { |
|
429 |
// dbld.setDefaultSRS(""); |
|
430 |
// dbld.setGeometryTypes(new int[]{FShape.MULTI}); |
|
431 |
// throw new ReadException("H2Utils.getTableEPSG_and_shapeType",e); |
|
432 |
// } |
|
433 |
// |
|
434 |
// } |
|
398 | 435 |
|
399 |
// String sql = "SELECT * FROM GEOMETRY_COLUMNS WHERE F_TABLE_NAME = '" |
|
400 |
// + getTableName() + "' AND F_GEOMETRY_COLUMN = '" + getLyrDef().getFieldGeometry() + "'"; |
|
401 |
String sql= "SELECT SRID("+dbld.getDefaultGeometry()+"), GeometryType("+dbld.getDefaultGeometry()+") FROM "+tableID +" WHERE "+dbld.getDefaultGeometry()+" is not null LIMIT 1"; |
|
402 |
|
|
403 |
ResultSet rs = stAux.executeQuery(sql); |
|
404 |
if(!rs.next()){ |
|
405 |
dbld.setDefaultSRS(""); |
|
406 |
dbld.setGeometryTypes(new int[]{FShape.MULTI}); |
|
407 |
return; |
|
408 |
} |
|
409 |
dbld.setDefaultSRS("EPSG:"+rs.getInt(1)); |
|
410 |
|
|
411 |
String geometryType = rs.getString(2); |
|
412 |
int shapeType = FShape.MULTI; |
|
413 |
if (geometryType.compareToIgnoreCase("Point") == 0) |
|
414 |
shapeType = FShape.POINT; |
|
415 |
else if (geometryType.compareToIgnoreCase("LineString") == 0) |
|
416 |
shapeType = FShape.LINE; |
|
417 |
else if (geometryType.compareToIgnoreCase("Polygon") == 0) |
|
418 |
shapeType = FShape.POLYGON; |
|
419 |
else if (geometryType.compareToIgnoreCase("MultiPoint") == 0) |
|
420 |
shapeType = FShape.POINT; |
|
421 |
else if (geometryType.compareToIgnoreCase("MultiLineString") == 0) |
|
422 |
shapeType = FShape.LINE; |
|
423 |
else if (geometryType.compareToIgnoreCase("MultiPolygon") == 0) |
|
424 |
shapeType = FShape.POLYGON; |
|
425 |
|
|
426 |
dbld.setGeometryTypes(new int[]{shapeType}); |
|
427 |
rs.close(); |
|
428 |
|
|
429 |
} catch (java.sql.SQLException e) { |
|
430 |
dbld.setDefaultSRS(""); |
|
431 |
dbld.setGeometryTypes(new int[]{FShape.MULTI}); |
|
432 |
throw new ReadException("H2Utils.getTableEPSG_and_shapeType",e); |
|
433 |
} |
|
434 |
|
|
435 |
} |
|
436 |
|
|
437 | 436 |
static String getConnectionResourceID(String dbUrl,String dbUser){ |
438 | 437 |
return H2Store.CONNECTION_STRING+";"+dbUrl+";"+dbUser; |
439 | 438 |
|
trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresqlbin/PostgresqlBinFeature.java | ||
---|---|---|
20 | 20 |
import org.gvsig.data.vectorial.IFeatureType; |
21 | 21 |
import org.gvsig.data.vectorial.IsNotFeatureSettingException; |
22 | 22 |
|
23 |
import com.iver.cit.gvsig.fmap.drivers.XTypes; |
|
24 | 23 |
|
25 |
|
|
26 |
|
|
27 | 24 |
public class PostgresqlBinFeature extends JDBCFeature{ |
28 | 25 |
|
29 | 26 |
|
trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresqlbin/PostgresqlBinStoreUtils.java | ||
---|---|---|
8 | 8 |
|
9 | 9 |
import org.gvsig.data.datastores.vectorial.db.DBAttributeDescriptor; |
10 | 10 |
import org.gvsig.data.datastores.vectorial.db.DBFeatureType; |
11 |
import org.gvsig.data.datastores.vectorial.db.jdbc.WKBParser2; |
|
11 | 12 |
import org.gvsig.data.datastores.vectorial.db.jdbc.exception.JDBCDriverNotFoundException; |
12 | 13 |
import org.gvsig.data.datastores.vectorial.db.jdbc.exception.SQLException; |
13 | 14 |
import org.gvsig.data.datastores.vectorial.db.jdbc.postgresql.PostgresqlStore; |
... | ... | |
20 | 21 |
import org.gvsig.data.vectorial.IFeatureAttributeDescriptor; |
21 | 22 |
import org.gvsig.data.vectorial.IsNotAttributeSettingException; |
22 | 23 |
|
23 |
import com.iver.cit.gvsig.fmap.drivers.WKBParser2; |
|
24 | 24 |
import com.vividsolutions.jts.io.WKBWriter; |
25 | 25 |
|
26 | 26 |
public class PostgresqlBinStoreUtils { |
trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/jdbc/postgresqlbin/XTypes.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 26-oct-2005 |
|
3 |
* |
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
5 |
* |
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
21 |
* |
|
22 |
* For more information, contact: |
|
23 |
* |
|
24 |
* Generalitat Valenciana |
|
25 |
* Conselleria d'Infraestructures i Transport |
|
26 |
* Av. Blasco Ib??ez, 50 |
|
27 |
* 46010 VALENCIA |
|
28 |
* SPAIN |
|
29 |
* |
|
30 |
* +34 963862235 |
|
31 |
* gvsig@gva.es |
|
32 |
* www.gvsig.gva.es |
|
33 |
* |
|
34 |
* or |
|
35 |
* |
|
36 |
* IVER T.I. S.A |
|
37 |
* Salamanca 50 |
|
38 |
* 46005 Valencia |
|
39 |
* Spain |
|
40 |
* |
|
41 |
* +34 963163400 |
|
42 |
* dac@iver.es |
|
43 |
*/ |
|
44 |
package org.gvsig.data.datastores.vectorial.db.jdbc.postgresqlbin; |
|
45 |
|
|
46 |
import java.sql.Types; |
|
47 |
|
|
48 |
public class XTypes { |
|
49 |
public final static double NUM_msSecs2000 = 9.466776E11; |
|
50 |
public final static int POINT2D = 100; |
|
51 |
|
|
52 |
public final static int LINE2D = 101; |
|
53 |
|
|
54 |
public final static int POLYGON2D = 102; |
|
55 |
|
|
56 |
public final static int MULTI2D = 103; |
|
57 |
|
|
58 |
public static String fieldTypeToString(int fieldType) { |
|
59 |
String aux = "text"; // Por defecto. |
|
60 |
switch (fieldType) { |
|
61 |
case Types.SMALLINT: |
|
62 |
aux = "integer"; |
|
63 |
break; |
|
64 |
case Types.INTEGER: |
|
65 |
aux = "integer"; |
|
66 |
break; |
|
67 |
case Types.BIGINT: |
|
68 |
aux = "integer"; |
|
69 |
break; |
|
70 |
case Types.BOOLEAN: |
|
71 |
aux = "boolean"; |
|
72 |
break; |
|
73 |
case Types.DECIMAL: |
|
74 |
aux = "numeric"; |
|
75 |
break; |
|
76 |
case Types.DOUBLE: |
|
77 |
aux = "float8"; |
|
78 |
break; |
|
79 |
case Types.FLOAT: |
|
80 |
aux = "float"; |
|
81 |
break; |
|
82 |
case Types.CHAR: |
|
83 |
aux = "char"; |
|
84 |
break; |
|
85 |
case Types.VARCHAR: |
|
86 |
aux = "text"; |
|
87 |
break; |
|
88 |
case Types.LONGVARCHAR: |
|
89 |
aux = "text"; |
|
90 |
break; |
|
91 |
|
|
92 |
case POINT2D: |
|
93 |
aux = "POINT"; |
|
94 |
break; |
|
95 |
case LINE2D: |
|
96 |
aux = "MULTILINESTRING"; |
|
97 |
break; |
|
98 |
case POLYGON2D: |
|
99 |
aux = "MULTIPOLYGON"; |
|
100 |
break; |
|
101 |
case MULTI2D: |
|
102 |
aux = "GEOMETRY"; |
|
103 |
break; |
|
104 |
|
|
105 |
} |
|
106 |
|
|
107 |
return aux; |
|
108 |
} |
|
109 |
|
|
110 |
// /** |
|
111 |
// * @param fieldId |
|
112 |
// * @throws SQLException |
|
113 |
// */ |
|
114 |
// public static Value getValue(ResultSet rs, int fieldId) throws SQLException { |
|
115 |
// byte[] data; |
|
116 |
// data = rs.getBytes(fieldId); |
|
117 |
// Value val = null; |
|
118 |
// ResultSetMetaData metaData = rs.getMetaData(); |
|
119 |
// if (data == null) |
|
120 |
// val = ValueFactory.createNullValue(); |
|
121 |
// else { |
|
122 |
// ByteBuffer buf = ByteBuffer.wrap(data); |
|
123 |
// if (metaData.getColumnType(fieldId) == Types.VARCHAR) { |
|
124 |
// val = ValueFactory.createValue(rs.getString(fieldId)); |
|
125 |
// }else if (metaData.getColumnType(fieldId) == Types.FLOAT) { |
|
126 |
// val = ValueFactory.createValue(buf.getFloat()); |
|
127 |
// }else if (metaData.getColumnType(fieldId) == Types.DOUBLE) { |
|
128 |
// val = ValueFactory.createValue(buf.getDouble()); |
|
129 |
// }else if (metaData.getColumnType(fieldId) == Types.INTEGER){ |
|
130 |
// val = ValueFactory.createValue(buf.getInt()); |
|
131 |
// }else if (metaData.getColumnType(fieldId) == Types.SMALLINT){ |
|
132 |
// val = ValueFactory.createValue(buf.getShort()); |
|
133 |
// }else if (metaData.getColumnType(fieldId) == Types.TINYINT){ |
|
134 |
// val = ValueFactory.createValue(buf.getShort()); |
|
135 |
// }else if (metaData.getColumnType(fieldId) == Types.BIGINT){ |
|
136 |
// val = ValueFactory.createValue(buf.getLong()); |
|
137 |
// }else if (metaData.getColumnType(fieldId) == Types.BIT || metaData.getColumnType(fieldId) == Types.BOOLEAN ){ |
|
138 |
// val = ValueFactory.createValue(rs.getBoolean(fieldId)); |
|
139 |
// }else if (metaData.getColumnType(fieldId) == Types.DATE){ |
|
140 |
// val = ValueFactory.createValue(rs.getDate(fieldId)); |
|
141 |
// }else if (metaData.getColumnType(fieldId) == Types.TIME){ |
|
142 |
// val = ValueFactory.createValue(rs.getTime(fieldId)); |
|
143 |
// }else if (metaData.getColumnType(fieldId) == Types.TIMESTAMP){ |
|
144 |
// val = ValueFactory.createValue(rs.getTimestamp(fieldId)); |
|
145 |
// } |
|
146 |
// |
|
147 |
// } |
|
148 |
// return val; |
|
149 |
// } |
|
150 |
// |
|
151 |
// public static void updateValue(ResultSet rs, int fieldId_ceroBased, |
|
152 |
// Value val) throws SQLException { |
|
153 |
// if (val instanceof NullValue) |
|
154 |
// return; |
|
155 |
// // byte[] data; |
|
156 |
// ResultSetMetaData metaData = rs.getMetaData(); |
|
157 |
// int fieldId = fieldId_ceroBased + 1; |
|
158 |
// // System.out.println("EScritrua: " + metaData.isDefinitelyWritable(1)); |
|
159 |
// switch (val.getSQLType()) { |
|
160 |
// case Types.VARCHAR: |
|
161 |
// case Types.LONGVARCHAR: |
|
162 |
// // Para evitar escribir en el campo geometria: |
|
163 |
// if (metaData.getColumnType(fieldId) == Types.OTHER) |
|
164 |
// return; |
|
165 |
// StringValue valStr = (StringValue) val; |
|
166 |
// rs.updateString(fieldId, valStr.getValue()); |
|
167 |
// // System.out.println("Field " + fieldId + " :" + |
|
168 |
// // metaData.getColumnTypeName(fieldId)); |
|
169 |
// break; |
|
170 |
// case Types.FLOAT: |
|
171 |
// FloatValue vFloat = (FloatValue) val; |
|
172 |
// rs.updateFloat(fieldId, vFloat.getValue()); |
|
173 |
// break; |
|
174 |
// case Types.DOUBLE: |
|
175 |
// DoubleValue vDouble = (DoubleValue) val; |
|
176 |
// rs.updateDouble(fieldId, vDouble.getValue()); |
|
177 |
// break; |
|
178 |
// case Types.INTEGER: |
|
179 |
// IntValue vInt = (IntValue) val; |
|
180 |
// rs.updateInt(fieldId, vInt.getValue()); |
|
181 |
// case Types.SMALLINT: |
|
182 |
// ShortValue vShort = (ShortValue) val; |
|
183 |
// rs.updateShort(fieldId, vShort.shortValue()); |
|
184 |
// break; |
|
185 |
// case Types.BIGINT: |
|
186 |
// LongValue vLong = (LongValue) val; |
|
187 |
// rs.updateLong(fieldId, vLong.getValue()); |
|
188 |
// break; |
|
189 |
// case Types.BIT: |
|
190 |
// case Types.BOOLEAN: |
|
191 |
// BooleanValue vBool = (BooleanValue) val; |
|
192 |
// rs.updateBoolean(fieldId, vBool.getValue()); |
|
193 |
// break; |
|
194 |
// case Types.DATE: |
|
195 |
// DateValue vDate = (DateValue) val; |
|
196 |
// rs.updateDate(fieldId, vDate.getValue()); |
|
197 |
// break; |
|
198 |
// case Types.TIME: |
|
199 |
// TimeValue vTime = (TimeValue) val; |
|
200 |
// rs.updateTime(fieldId, vTime.getValue()); |
|
201 |
// break; |
|
202 |
// case Types.TIMESTAMP: |
|
203 |
// TimestampValue vTimeStamp = (TimestampValue) val; |
|
204 |
// rs.updateTimestamp(fieldId, vTimeStamp.getValue()); |
|
205 |
// break; |
|
206 |
// |
|
207 |
// default: |
|
208 |
// System.err.println("Tipo no soportado:" |
|
209 |
// + metaData.getColumnType(fieldId) + ". Field:" + fieldId |
|
210 |
// + ": " + metaData.getColumnName(fieldId)); |
|
211 |
// // throw new UnsupportedOperationException(); |
|
212 |
// |
|
213 |
// } |
|
214 |
// } |
|
215 |
|
|
216 |
} |
Also available in: Unified diff