static DBFeatureType getFeatureType(Connection connection, PostgresqlStoreParameters params) throws ReadException { DBFeatureType featureType = new DBFeatureType(); String[] ids = params.getFieldsId(); int i; DBAttributeDescriptor attr; loadFieldsToFeatureType(connection, params, featureType); try { featureType.setFieldsId(ids); } catch (DataException e) { throw new ReadException(PostgresqlStore.DATASTORE_NAME, e); } // Inicializamos los 'serial' ya que en postgres el // 'isAutonumeric' devuelve false // try{ // initializeSerialFields(connection,featureType); // } catch (java.sql.SQLException e) { // throw new InitializeException(PostgresqlStore.DATASTORE_NAME,e); // // } // // Inicializar campos geometricos si los hubiese // TODO Datos geometricos // featureType.setDefaultGeometry(params.getGeometryField()); getTableEPSG_and_shapeType(connection, params, featureType); // Inicializar la geometria por defecto if (params.getDefaultGeometryField() != null && params.getDefaultGeometryField() != "") { if (featureType.getIndex(params.getDefaultGeometryField()) < 0) { throw new InitializeException( PostgresqlStore.DATASTORE_NAME, new Exception("Geometry Field '" + params.getDefaultGeometryField() + "' not Found")); } attr = (DBAttributeDescriptor) featureType.get(params.getDefaultGeometryField()); if (attr.getDataType() != FeatureAttributeDescriptor.GEOMETRY) { throw new InitializeException( PostgresqlStore.DATASTORE_NAME, new Exception("Field '" + params.getDefaultGeometryField() + "' isn't a geometry")); } } featureType.setDefaultGeometry(params.getDefaultGeometryField()); // featureType.setGeometryTypes(new int[]{Geometry.TYPES.GEOMETRY}); return featureType; }
private static void loadFieldsToFeatureType( Connection conn, PostgresqlStoreParameters params, DBFeatureType featureType) throws ReadException { String sql = ""; String columns = params.getFieldsString(); boolean fillTableData; if (params.getSqlSoure() != null) { sql = params.getSqlSoure(); fillTableData = false; } else { sql = "Select " + columns + " from " + params.tableID(); fillTableData = true; } try { Statement stAux = conn.createStatement(); stAux.setFetchSize(1); ResultSet rs = stAux.executeQuery(sql); ResultSetMetaData rsMetadata = rs.getMetaData(); int i; featureType.setTableID(params.tableID()); DBAttributeDescriptor attr; for (i = 1; i <= rsMetadata.getColumnCount(); i++) { attr = getAttributeFromJDBC(featureType, conn, rsMetadata, i); featureType.add(attr); // attr.setOrdinal(i-1); attr.loading(); attr.setCatalogName(params.getDb()); if (fillTableData) { attr.setSchemaName(params.getSchema()); attr.setTableName(params.getTableName()); } attr.stopLoading(); } rs.close(); stAux.close(); } catch (java.sql.SQLException e) { throw new SQLException(sql, "getFeatureType", e); } catch (IsNotAttributeSettingException e) { e.printStackTrace(); } }