Skip to content

Commit

Permalink
feat: override default implementation of getGeometryDimension
Browse files Browse the repository at this point in the history
  • Loading branch information
f-necas committed May 28, 2024
1 parent fabbcfb commit 5b897e6
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ protected SQLDialect createSQLDialect(JDBCDataStore dataStore, Map<String, ?> pa
}

/**
* A PostGIS dialect that does not rely on the public geometry_columns table to get the
* SRID of a geometry column.
* Get the SRID from the geometry in the table instead.
* A PostGIS dialect that does not rely on the public geometry_columns table to
* get the SRID of a geometry column. Get the SRID from the geometry in the
* table instead.
*/
private static class SchemaUnawarePostGISDialect extends PostGISDialect {
public SchemaUnawarePostGISDialect(JDBCDataStore dataStore) {
Expand All @@ -140,5 +140,70 @@ public Integer getGeometrySRID(String schemaName, String tableName, String colum
}
return srid;
}

/**
* Override default implementation to get the geometry from the expected schema.table
* Suppose that Postgis version > 1.5
* Suppose there's only one table with the given name in all schemas
*
* @param schemaName The database schema, could be <code>null</code>.
* @param tableName The table, never <code>null</code>.
* @param columnName The column name, never <code>null</code>
* @param cx The database connection.
* @return The dimension of the geometry column, or 2 if not found.
* @throws SQLException
*/
@Override
public int getGeometryDimension(String schemaName, String tableName, String columnName, Connection cx)
throws SQLException {
// first attempt, try with the geometry metadata
Integer dimension = null;
try (Statement statement = cx.createStatement()) {
if (schemaName == null) {
String sqlStatement = "select table_schema from information_schema.tables WHERE table_name LIKE '"
+ tableName + "' LIMIT 1;";
LOGGER.log(Level.FINE, "Check table in information schema; {0} ", sqlStatement);
try (ResultSet result = statement.executeQuery(sqlStatement)) {

if (result.next()) {
schemaName = result.getString(1);
}
} catch (SQLException e) {
schemaName = "public";
}
}

// try geography_columns
// first look for an entry in geography_columns
String sqlStatement = "SELECT COORD_DIMENSION FROM GEOGRAPHY_COLUMNS WHERE " //
+ "F_TABLE_SCHEMA = '" + schemaName + "' " //
+ "AND F_TABLE_NAME = '" + tableName + "' " //
+ "AND F_GEOGRAPHY_COLUMN = '" + columnName + "'";
LOGGER.log(Level.FINE, "Geography srid check; {0} ", sqlStatement);
try (ResultSet result = statement.executeQuery(sqlStatement)) {

if (result.next()) {
return result.getInt(1);
}
} catch (SQLException e) {
LOGGER.log(Level.WARNING, "Failed to retrieve information about " + schemaName + "." + tableName
+ "." + columnName + " from the geography_columns table, checking geometry_columns instead",
e);
}
}

// fall back on inspection of the first geometry, assuming uniform srid (fair
// assumption
// an unpredictable srid makes the table un-queriable)
if (dimension == null) {
dimension = getDimensionFromFirstGeo(schemaName, tableName, columnName, cx);
}

if (dimension == null) {
dimension = 2;
}

return dimension;
}
}
}
14 changes: 8 additions & 6 deletions src/services/ogc-features/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ springdoc:
swagger-ui:
enabled: true
#path: ${openapi.geoServerACL.base-path}/swagger-ui.html
try-it-out-enabled: true
try-it-out-enabled: true

logging:
level:
Expand All @@ -32,12 +32,14 @@ spring:
config.activate.on-profile: postgis
datasource:
url: jdbc:postgresql://${postgres.host:localhost}:${postgres.port:5432}/${postgres.db:postgis}
username: ${postgres.user:postgis}
username: ${postgres.user:postgis}
password: ${postgres.password:postgis}
driver-class-name: org.postgresql.Driver
hikari:
maximum-pool-size: ${postgres.pool.maxsize:20}
minimum-idle: ${postgres.pool.minsize:0}
max-lifetime: 30000 # 30000ms is the minimum allowed

maximum-pool-size: ${postgres.pool.maxsize:40}
minimum-idle: ${postgres.pool.minsize:2}
max-lifetime: ${postgres.pool.maxlifetime:120000} # 30000ms is the minimum allowed
idle-timeout: ${postgres.pool.idletimeout:300000} # 600000ms is the minimum allowed
connection-timeout: ${postgres.pool.connectiontimeout:60000} # 30000ms is the minimum allowed
leak-detection-threshold: ${postgres.pool.leakdetectionthreshold:0} # 0ms is the minimum allowed

0 comments on commit 5b897e6

Please sign in to comment.