diff --git a/src/services/ogc-features/src/main/java/com/camptocamp/opendata/ogc/features/autoconfigure/geotools/PostgisBackendAutoConfiguration.java b/src/services/ogc-features/src/main/java/com/camptocamp/opendata/ogc/features/autoconfigure/geotools/PostgisBackendAutoConfiguration.java index 850b4b6..7259d18 100644 --- a/src/services/ogc-features/src/main/java/com/camptocamp/opendata/ogc/features/autoconfigure/geotools/PostgisBackendAutoConfiguration.java +++ b/src/services/ogc-features/src/main/java/com/camptocamp/opendata/ogc/features/autoconfigure/geotools/PostgisBackendAutoConfiguration.java @@ -113,9 +113,9 @@ protected SQLDialect createSQLDialect(JDBCDataStore dataStore, Map 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) { @@ -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 null. + * @param tableName The table, never null. + * @param columnName The column name, never null + * @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; + } } } diff --git a/src/services/ogc-features/src/main/resources/application.yml b/src/services/ogc-features/src/main/resources/application.yml index 147c8e9..19c5574 100644 --- a/src/services/ogc-features/src/main/resources/application.yml +++ b/src/services/ogc-features/src/main/resources/application.yml @@ -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: @@ -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