Revision 20920 trunk/libraries/libFMap_dataDB/src/org/gvsig/data/datastores/vectorial/db/jdbc/h2/H2Utils.java
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 |
|
Also available in: Unified diff