Revision 43114 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/operations/FetchFeatureTypeOperation.java
FetchFeatureTypeOperation.java | ||
---|---|---|
65 | 65 |
return true; |
66 | 66 |
} |
67 | 67 |
|
68 |
protected String getDatabase() { |
|
69 |
return this.dbname; |
|
70 |
} |
|
71 |
|
|
72 |
protected String getSchema() { |
|
73 |
return this.schema; |
|
74 |
} |
|
75 |
|
|
76 |
protected String getTablename() { |
|
77 |
return this.table; |
|
78 |
} |
|
79 |
|
|
68 | 80 |
public void fetch( |
69 | 81 |
EditableFeatureType featureType, |
70 | 82 |
Connection conn, |
... | ... | |
106 | 118 |
boolean firstGeometryAttrFound = false; |
107 | 119 |
for (i = 1; i <= rsMetadata.getColumnCount(); i++) { |
108 | 120 |
attr = getAttributeFromMetadata(featureType, conn, rsMetadata, i); |
109 |
if (pks != null && pks.contains(attr.getName())) {
|
|
121 |
if ( isInPrimaryKeys(pks,attr) ) {
|
|
110 | 122 |
attr.setIsPrimaryKey(true); |
111 | 123 |
} |
112 | 124 |
if (attr.getType() == DataTypes.GEOMETRY) { |
... | ... | |
122 | 134 |
|
123 | 135 |
} |
124 | 136 |
|
125 |
if (geometriesColumns > 0) { |
|
126 |
fetch_CRS_and_shapeType(conn, rsMetadata, featureType, schema, table); |
|
127 |
} |
|
128 |
|
|
129 | 137 |
if (defaultGeometryColumn == null && geometriesColumns == 1) { |
130 | 138 |
featureType.setDefaultGeometryAttributeName(lastGeometry); |
131 | 139 |
} |
... | ... | |
142 | 150 |
} |
143 | 151 |
} |
144 | 152 |
|
153 |
protected boolean isInPrimaryKeys(List<String> pks, EditableFeatureAttributeDescriptor attr) { |
|
154 |
return pks != null && pks.contains(attr.getName()); |
|
155 |
} |
|
156 |
|
|
145 | 157 |
protected List<String> getPrimaryKeysFromMetadata( |
146 | 158 |
Connection conn, |
147 | 159 |
String catalog, |
... | ... | |
286 | 298 |
); |
287 | 299 |
break; |
288 | 300 |
case DataTypes.GEOMETRY: |
289 |
this.fetchGeometryType(attr, rsMetadata, colIndex); |
|
301 |
this.fetchGeometryTypeAndSRS(attr, rsMetadata, colIndex);
|
|
290 | 302 |
break; |
291 | 303 |
} |
292 | 304 |
return attr; |
293 | 305 |
} |
294 | 306 |
|
295 |
protected void fetchGeometryType( |
|
296 |
EditableFeatureAttributeDescriptor attr, |
|
297 |
ResultSetMetaData rsMetadata, |
|
298 |
int colIndex |
|
299 |
) { |
|
300 |
try { |
|
301 |
GeometryType geomType = GeometryLocator.getGeometryManager().getGeometryType( |
|
302 |
Geometry.TYPES.GEOMETRY, |
|
303 |
Geometry.SUBTYPES.GEOM2D |
|
304 |
); |
|
305 |
attr.setGeometryType(geomType); |
|
306 |
} catch (Exception ex) { |
|
307 |
logger.warn("Can't get default geometry type.",ex); |
|
308 |
} |
|
309 |
} |
|
310 |
|
|
311 | 307 |
protected int getDataTypeFromMetadata( |
312 | 308 |
ResultSetMetaData rsMetadata, |
313 | 309 |
int colIndex |
... | ... | |
369 | 365 |
} |
370 | 366 |
} |
371 | 367 |
|
372 |
protected void fetch_CRS_and_shapeType( |
|
373 |
Connection conn, |
|
368 |
/** |
|
369 |
* Inicializa el tipo, subtipo y SRS del attributo de tipo geometria. |
|
370 |
* |
|
371 |
* @param attr |
|
372 |
* @param rsMetadata |
|
373 |
* @param colIndex |
|
374 |
*/ |
|
375 |
protected void fetchGeometryTypeAndSRS( |
|
376 |
EditableFeatureAttributeDescriptor attr, |
|
374 | 377 |
ResultSetMetaData rsMetadata, |
375 |
EditableFeatureType featureType, |
|
376 |
String schema, |
|
377 |
String table |
|
378 |
) throws SQLException { |
|
379 |
|
|
380 |
// Nothing to do |
|
378 |
int colIndex |
|
379 |
) { |
|
380 |
if( attr.getType()!=DataTypes.GEOMETRY ) { |
|
381 |
return; |
|
382 |
} |
|
383 |
try { |
|
384 |
GeometryType geomType = GeometryLocator.getGeometryManager().getGeometryType( |
|
385 |
Geometry.TYPES.GEOMETRY, |
|
386 |
Geometry.SUBTYPES.GEOM2D |
|
387 |
); |
|
388 |
attr.setGeometryType(geomType); |
|
389 |
attr.setSRS(null); |
|
390 |
} catch (Exception ex) { |
|
391 |
logger.warn("Can't get default geometry type.",ex); |
|
392 |
} |
|
381 | 393 |
} |
382 |
|
|
394 |
|
|
383 | 395 |
} |
Also available in: Unified diff