This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit da3c8abd29d1bc84fd1b4aa780904e9ca815885f
Author: jsorel <johann.so...@geomatys.com>
AuthorDate: Fri Aug 9 11:28:03 2024 +0200

    Associate the geometry type encoding to the spatial schema.
    It reduces the need to create `Database` subclasses.
    This commit is derived from Johann Sorel's work.
---
 .../storage/sql/feature/GeometryTypeEncoding.java  | 56 ++++++++++++++++++++++
 .../sis/storage/sql/feature/InfoStatements.java    | 38 +--------------
 .../sis/storage/sql/feature/SpatialSchema.java     | 19 +++++---
 .../sis/storage/sql/postgis/ExtendedInfo.java      |  1 +
 4 files changed, 72 insertions(+), 42 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/GeometryTypeEncoding.java
 
b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/GeometryTypeEncoding.java
new file mode 100644
index 0000000000..6b8c7859f2
--- /dev/null
+++ 
b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/GeometryTypeEncoding.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.storage.sql.feature;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import org.apache.sis.geometry.wrapper.GeometryType;
+
+
+/**
+ * Specifies how the geometry type is encoded in the {@code "GEOMETRY_TYPE"} 
column.
+ * The OGC standard defines numeric values, but PostGIS uses textual values.
+ *
+ * @see #configureSpatialColumns(PreparedStatement, TableReference, Map, 
GeometryTypeEncoding)
+ */
+public enum GeometryTypeEncoding {
+    /**
+     * {@code "GEOMETRY_TYPE"} column is expected to contain an integer value.
+     * This is the encoding used in OGC standard.
+     */
+    NUMERIC,
+
+    /**
+     * {@code "GEOMETRY_TYPE"} column is expected to contain a textual value.
+     * This is the encoding used by PostGIS, but using a different column name
+     * ({@code "TYPE"} instead of {@code "GEOMETRY_TYPE"}) for avoiding 
confusion.
+     */
+    TEXTUAL() {
+        @Override GeometryType parse(final ResultSet result, final int 
columnIndex) throws SQLException {
+            return GeometryType.forName(result.getString(columnIndex));
+        }
+    };
+
+    /**
+     * Decodes the geometry type encoded in the specified column of the given 
result set.
+     * If there is no type information, then this method returns {@code null}.
+     */
+    GeometryType parse(final ResultSet result, final int columnIndex) throws 
SQLException {
+        final int code = result.getInt(columnIndex);
+        return result.wasNull() ? null : GeometryType.forBinaryType(code);
+    }
+}
diff --git 
a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/InfoStatements.java
 
b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/InfoStatements.java
index 45b087f698..26b61023db 100644
--- 
a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/InfoStatements.java
+++ 
b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/InfoStatements.java
@@ -74,40 +74,6 @@ import org.opengis.metadata.Identifier;
  * @see <a href="https://www.ogc.org/standards/sfs";>OGC Simple feature access 
— Part 2: SQL option</a>
  */
 public class InfoStatements implements Localized, AutoCloseable {
-    /**
-     * Specifies how the geometry type is encoded in the {@code 
"GEOMETRY_TYPE"} column.
-     * The OGC standard defines numeric values, but PostGIS uses textual 
values.
-     *
-     * @see #configureSpatialColumns(PreparedStatement, TableReference, Map, 
GeometryTypeEncoding)
-     */
-    protected enum GeometryTypeEncoding {
-        /**
-         * {@code "GEOMETRY_TYPE"} column is expected to contain an integer 
value.
-         * This is the encoding used in OGC standard.
-         */
-        NUMERIC,
-
-        /**
-         * {@code "GEOMETRY_TYPE"} column is expected to contain a textual 
value.
-         * This is the encoding used by PostGIS, but using a different column 
name
-         * ({@code "TYPE"} instead of {@code "GEOMETRY_TYPE"}) for avoiding 
confusion.
-         */
-        TEXTUAL() {
-            @Override GeometryType parse(final ResultSet result, final int 
columnIndex) throws SQLException {
-                return GeometryType.forName(result.getString(columnIndex));
-            }
-        };
-
-        /**
-         * Decodes the geometry type encoded in the specified column of the 
given result set.
-         * If there is no type information, then this method returns {@code 
null}.
-         */
-        GeometryType parse(final ResultSet result, final int columnIndex) 
throws SQLException {
-            final int code = result.getInt(columnIndex);
-            return result.wasNull() ? null : GeometryType.forBinaryType(code);
-        }
-    }
-
     /**
      * The database that created this set of cached statements. This object 
includes the
      * cache of CRS created from SRID codes and the listeners where to send 
warnings.
@@ -249,11 +215,11 @@ public class InfoStatements implements Localized, 
AutoCloseable {
      * @throws SQLException if a SQL error occurred.
      */
     public void completeIntrospection(final TableReference source, final 
Map<String,Column> columns) throws Exception {
+        final SpatialSchema schema = database.getSpatialSchema().orElseThrow();
         if (geometryColumns == null) {
-            final SpatialSchema schema = 
database.getSpatialSchema().orElseThrow();
             geometryColumns = 
prepareIntrospectionStatement(schema.geometryColumns, false, null, null);
         }
-        configureSpatialColumns(geometryColumns, source, columns, 
GeometryTypeEncoding.NUMERIC);
+        configureSpatialColumns(geometryColumns, source, columns, 
schema.typeEncoding);
     }
 
     /**
diff --git 
a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/SpatialSchema.java
 
b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/SpatialSchema.java
index a20176fc5b..e171d80793 100644
--- 
a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/SpatialSchema.java
+++ 
b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/feature/SpatialSchema.java
@@ -39,7 +39,8 @@ public enum SpatialSchema {
      * {@code geometry_type_name} column.
      */
     GEOPACKAGE("gpkg_spatial_ref_sys", "srs_id", "organization", 
"organization_coordsys_id", "definition",
-               "gpkg_geometry_columns", "table_catalog", "table_schema", 
"table_name", "column_name", "geometry_type_name"),
+               "gpkg_geometry_columns", "table_catalog", "table_schema", 
"table_name", "column_name",
+               "geometry_type_name", GeometryTypeEncoding.TEXTUAL),
 
     /**
      * Table and column names as specified by ISO-13249 SQL/MM. This is the 
same thing as {@link #SIMPLE_FEATURE}
@@ -59,7 +60,7 @@ public enum SpatialSchema {
      * except for the case (Geopackage uses lower case).
      */
     SQL_MM("ST_SPATIAL_REFERENCE_SYSTEMS", "SRS_ID", "ORGANIZATION", 
"ORGANIZATION_COORDSYS_ID", "DEFINITION",
-           "ST_GEOMETRY_COLUMNS", "TABLE_CATALOG", "TABLE_SCHEMA", 
"TABLE_NAME", "COLUMN_NAME", null),
+           "ST_GEOMETRY_COLUMNS", "TABLE_CATALOG", "TABLE_SCHEMA", 
"TABLE_NAME", "COLUMN_NAME", null, null),
 
     /**
      * Table and column names as specified by ISO 19125 / OGC Simple feature 
access part 2.
@@ -76,7 +77,8 @@ public enum SpatialSchema {
      * }
      */
     SIMPLE_FEATURE("SPATIAL_REF_SYS", "SRID", "AUTH_NAME", "AUTH_SRID", 
"SRTEXT",
-                   "GEOMETRY_COLUMNS", "F_TABLE_CATALOG", "F_TABLE_SCHEMA", 
"F_TABLE_NAME", "F_GEOMETRY_COLUMN", "GEOMETRY_TYPE");
+                   "GEOMETRY_COLUMNS", "F_TABLE_CATALOG", "F_TABLE_SCHEMA", 
"F_TABLE_NAME", "F_GEOMETRY_COLUMN",
+                   "GEOMETRY_TYPE", GeometryTypeEncoding.NUMERIC);
 
     /**
      * Name of the table for Spatial Reference System definitions.
@@ -141,11 +143,14 @@ public enum SpatialSchema {
     /**
      * Name of the column where the type of each geometry column is stored, or 
{@code null} if none.
      * Example: {@code "GEOMETRY_TYPE"}.
-     *
-     * @see InfoStatements.GeometryTypeEncoding
      */
     final String geomTypeColumn;
 
+    /**
+     * Specifies how geometry types are encoded in the {@link #geomTypeColumn}.
+     */
+    final GeometryTypeEncoding typeEncoding;
+
     /**
      * Creates a new enumeration value.
      *
@@ -160,11 +165,12 @@ public enum SpatialSchema {
      * @param geomTableColumn         name of the column where the table of 
each geometry column is stored.
      * @param geomColNameColumn       name of the column where the column of 
each geometry column is stored.
      * @param geomTypeColumn          name of the column where the type of 
each geometry column is stored, or null if none.
+     * @param typeEncoding            how geometry types are encoded in the 
{@link #geomTypeColumn}.
      */
     private SpatialSchema(String crsTable, String crsIdentifierColumn, String 
crsAuthorityNameColumn,
                           String crsAuthorityCodeColumn, String 
crsDefinitionColumn, String geometryColumns,
                           String geomCatalogColumn, String geomSchemaColumn, 
String geomTableColumn,
-                          String geomColNameColumn, String geomTypeColumn)
+                          String geomColNameColumn, String geomTypeColumn, 
GeometryTypeEncoding typeEncoding)
     {
         this.crsTable               = crsTable;
         this.crsIdentifierColumn    = crsIdentifierColumn;
@@ -177,5 +183,6 @@ public enum SpatialSchema {
         this.geomTableColumn        = geomTableColumn;
         this.geomColNameColumn      = geomColNameColumn;
         this.geomTypeColumn         = geomTypeColumn;
+        this.typeEncoding           = typeEncoding;
     }
 }
diff --git 
a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/postgis/ExtendedInfo.java
 
b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/postgis/ExtendedInfo.java
index 843804a7ed..e43555c88e 100644
--- 
a/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/postgis/ExtendedInfo.java
+++ 
b/endorsed/src/org.apache.sis.storage.sql/main/org/apache/sis/storage/sql/postgis/ExtendedInfo.java
@@ -24,6 +24,7 @@ import org.apache.sis.storage.sql.feature.Column;
 import org.apache.sis.storage.sql.feature.Database;
 import org.apache.sis.storage.sql.feature.TableReference;
 import org.apache.sis.storage.sql.feature.InfoStatements;
+import org.apache.sis.storage.sql.feature.GeometryTypeEncoding;
 
 
 /**

Reply via email to