/** * Return the first geometry field of tableName or null if it contains none. * * @param connection Connection * @param tableName TableLocation * @return The first geometry field of tableName or null if it contains none * @throws SQLException */ protected static String getFirstGeometryField(Connection connection, TableLocation tableName) throws SQLException { final List<String> geometryFields = SFSUtilities.getGeometryFields(connection, tableName); if (geometryFields.isEmpty()) { return null; } return geometryFields.get(0); }
/** * Return the first geometry field of tableName or null if it contains none. * * @param connection Connection * @param tableName TableLocation * @return The first geometry field of tableName or null if it contains none * @throws SQLException */ protected static String getFirstGeometryField(Connection connection, TableLocation tableName) throws SQLException { final List<String> geometryFields = SFSUtilities.getGeometryFields(connection, tableName); if (geometryFields.isEmpty()) { return null; } return geometryFields.get(0); }
/** * Return the first geometry field of tableName or null if it contains none. * * @param connection Connection * @param tableName TableLocation * @return The first geometry field of tableName or null if it contains none * @throws SQLException */ protected static String getFirstGeometryField(Connection connection, TableLocation tableName) throws SQLException { final List<String> geometryFields = SFSUtilities.getGeometryFields(connection, tableName); if (geometryFields.isEmpty()) { return null; } return geometryFields.get(0); }
@Override public boolean printRow(ResultSet rs) throws SQLException { if(geomFieldName.isEmpty()) { List<String> geomFields = SFSUtilities.getGeometryFields(rs); if(!geomFields.isEmpty()) { geomFieldName = geomFields.get(0); } } Object geomObj = rs.getObject(geomFieldName); return geomObj instanceof Geometry && ((Geometry) geomObj).intersects(envelope); } }
/** * Compute the full extend of a resultset using the first geometry field. If * the resulset does not contain any geometry field throw an exception * * @param resultSet * @return the full envelope of the resulSet * @throws SQLException */ public static Envelope getResultSetEnvelope(ResultSet resultSet) throws SQLException { List<String> geometryFields = getGeometryFields(resultSet); if (geometryFields.isEmpty()) { throw new SQLException("This resultset doesn't contain any geometry field."); } else { return getResultSetEnvelope(resultSet, geometryFields.get(0)); } }
/** * Compute the full extend of a resultset using the first geometry field. If * the resulset does not contain any geometry field throw an exception * * @param resultSet * @return the full envelope of the resulSet * @throws SQLException */ public static Envelope getResultSetEnvelope(ResultSet resultSet) throws SQLException { List<String> geometryFields = getGeometryFields(resultSet); if (geometryFields.isEmpty()) { throw new SQLException("This resultset doesn't contain any geometry field."); } else { return getResultSetEnvelope(resultSet, geometryFields.get(0)); } }
/** * Compute the full extend of a ResultSet using the first geometry field. If * the ResultSet does not contain any geometry field throw an exception * * @param resultSet ResultSet to analyse * * @return The full envelope of the ResultSet * * @throws SQLException */ public static Envelope getResultSetEnvelope(ResultSet resultSet) throws SQLException { List<String> geometryFields = getGeometryFields(resultSet); if (geometryFields.isEmpty()) { throw new SQLException("This ResultSet doesn't contain any geometry field."); } else { return getResultSetEnvelope(resultSet, geometryFields.get(0)); } }
/** * Return the first spatial geometry field name * * @param tableName * @param connection * @return the name of the first geometry column * @throws SQLException */ private static String getFirstGeometryField(String tableName, Connection connection) throws SQLException { // Find first geometry column List<String> geomFields = SFSUtilities.getGeometryFields(connection, TableLocation.parse(tableName, JDBCUtilities.isH2DataBase(connection.getMetaData()))); if (!geomFields.isEmpty()) { return geomFields.get(0); } else { throw new SQLException("The table " + tableName + " does not contain a geometry field"); } }
/** * Return the first spatial geometry field name * * @param tableName * @param connection * @return the name of the first geometry column * @throws SQLException */ private static String getFirstGeometryField(String tableName, Connection connection) throws SQLException { // Find first geometry column List<String> geomFields = SFSUtilities.getGeometryFields(connection, TableLocation.parse(tableName, JDBCUtilities.isH2DataBase(connection.getMetaData()))); if (!geomFields.isEmpty()) { return geomFields.get(0); } else { throw new SQLException("The table " + tableName + " does not contain a geometry field"); } }
/** * Return the first spatial geometry field name * * @param tableName * @param connection * @return the name of the first geometry column * @throws SQLException */ private static String getFirstGeometryField(String tableName, Connection connection) throws SQLException { // Find first geometry column List<String> geomFields = SFSUtilities.getGeometryFields(connection, TableLocation.parse(tableName, JDBCUtilities.isH2DataBase(connection.getMetaData()))); if (!geomFields.isEmpty()) { return geomFields.get(0); } else { throw new SQLException("The table " + tableName + " does not contain a geometry field"); } }
@Override public Geometry getGeometry() throws SQLException { if(firstGeometryIndex == -1) { try(Connection connection = dataSource.getConnection()) { List<String> geoFields = SFSUtilities.getGeometryFields(connection, location); if(!geoFields.isEmpty()) { firstGeometryIndex = JDBCUtilities.getFieldIndex(getMetaData(), geoFields.get(0)); } else { throw new SQLException("No geometry column found"); } } } return getGeometry(firstGeometryIndex); }
@Override public Geometry getGeometry() throws SQLException { if(firstGeometryIndex == -1) { try(Connection connection = dataSource.getConnection()) { List<String> geoFields = SFSUtilities.getGeometryFields(connection, location); if(!geoFields.isEmpty()) { firstGeometryIndex = JDBCUtilities.getFieldIndex(getMetaData(), geoFields.get(0)); } else { throw new SQLException("No geometry column found"); } } } return getGeometry(firstGeometryIndex); }
@Override public boolean isVectorial() throws LayerException { if(getTableReference().isEmpty()) { return false; } try(Connection connection = dataManager.getDataSource().getConnection()) { try { return !SFSUtilities.getGeometryFields(connection,TableLocation.parse(getTableReference())).isEmpty(); } finally { connection.close(); } } catch (SQLException ex) { throw new LayerException(I18N.tr("Error while fetching source MetaData")); } }
/** * Find geometry fields name of a table. * @param connection Active connection * @param location Table location * @return A list of Geometry fields name * @throws SQLException */ public static List<String> getGeometryFields(Connection connection,TableLocation location) throws SQLException { return getGeometryFields(connection, location.getCatalog(), location.getSchema(), location.getTable()); }
/** * Find geometry fields name of a table. * @param connection Active connection * @param location Table location * @return A list of Geometry fields name * @throws SQLException */ public static List<String> getGeometryFields(Connection connection,TableLocation location) throws SQLException { return getGeometryFields(connection, location.getCatalog(), location.getSchema(), location.getTable()); }
/** * Find geometry fields name of a table. * * @param connection Active connection * @param location Table location * * @return A list of Geometry fields name * * @throws SQLException */ public static List<String> getGeometryFields(Connection connection,TableLocation location) throws SQLException { return getGeometryFields(connection, location.getCatalog(), location.getSchema(), location.getTable()); }
/** * Builds the WizardPanel. The objects it will create will be linked to {@code l}. * @param l The parent layer. * @param m Needed for LegendContext implementation. */ public ThematicMapWizard(ILayer l, MapTransform m){ layer = l; try(Connection connection = l.getDataManager().getDataSource().getConnection()) { TableLocation tableLocation = TableLocation.parse(l.getTableReference()); int type = SFSUtilities.getGeometryType(connection, tableLocation, SFSUtilities.getGeometryFields(connection, tableLocation).get(0)); this.geometryType = SimpleGeometryType.getSimpleType(type); mt = m; } catch (SQLException e) { LOGGER.error("Error while reading the data source"); } }
@Override public ILayer createLayer(String layerName, String tableRef) throws LayerException { try { try (Connection connection = dataManager.getDataSource().getConnection()) { List<String> geoFields = SFSUtilities.getGeometryFields(connection, TableLocation.parse(tableRef)); if (!geoFields.isEmpty()) { return new Layer(layerName, tableRef, dataManager); } else { throw new LayerException(I18N.tr("The source contains no spatial info")); } } } catch (SQLException ex) { throw new LayerException("Cannot retrieve spatial metadata",ex); } }
protected void cacheColumnNames() throws SQLException { cachedColumnNames = new DualHashBidiMap<>(); cachedGeomColumnNames = new DualHashBidiMap<>(); try(Resource res = resultSetHolder.getResource()) { ResultSetMetaData meta = res.getResultSet().getMetaData(); for (int idColumn = 1; idColumn <= meta.getColumnCount(); idColumn++) { cachedColumnNames.put(meta.getColumnName(idColumn), idColumn); } if(excludeGeomFields) { List<String> geomFields = SFSUtilities.getGeometryFields(getConnection(), location); for (String geomField : geomFields) { cachedGeomColumnNames.put(geomField, cachedColumnNames.get(geomField)); } } } }
@Override protected Set<Long> doInBackground() throws Exception { Set<Long> newSelection; // Get all primary value where default geometry intersects a bounding box try (Connection connection = SFSUtilities.wrapConnection(activeLayer.getDataManager().getDataSource().getConnection())) { String geomFieldName = SFSUtilities.getGeometryFields(connection, TableLocation.parse(activeLayer.getTableReference())).get(0); newSelection = ReadTable.getTablePkByEnvelope(mc.getDataManager(), activeLayer.getTableReference(), geomFieldName, selectionRect, !intersects); } catch (SQLException e) { automaton.transition(Code.NO_SELECTION); throw new TransitionException(e); } return newSelection; }