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

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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 0618ca82a0 refactor(Storage): rework SQL metadata analysis to improve 
byte/tinyint signing determination
0618ca82a0 is described below

commit 0618ca82a03356177d4d48e93bec65f4fd3eb045
Author: Alexis Manin <[email protected]>
AuthorDate: Mon Jul 31 12:22:43 2023 +0200

    refactor(Storage): rework SQL metadata analysis to improve byte/tinyint 
signing determination
    
    Provides user with a warning if required metadata is not found.
    Change scan logic to stop at soon as the information is found.
    Previously, the scan continued until 'true' was found.
---
 .../org/apache/sis/internal/sql/feature/Database.java  | 18 ++++++++++++++++--
 .../org/apache/sis/internal/sql/feature/Resources.java |  5 +++++
 .../sis/internal/sql/feature/Resources.properties      |  1 +
 .../sis/internal/sql/feature/Resources_fr.properties   |  1 +
 4 files changed, 23 insertions(+), 2 deletions(-)

diff --git 
a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Database.java
 
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Database.java
index 4bff8152db..36c378273e 100644
--- 
a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Database.java
+++ 
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Database.java
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.internal.sql.feature;
 
+import java.sql.SQLFeatureNotSupportedException;
 import java.util.Set;
 import java.util.Map;
 import java.util.List;
@@ -236,16 +237,29 @@ public class Database<G> extends Syntax  {
          * Get information about whether byte are unsigned.
          * According JDBC specification, the rows shall be ordered by 
DATA_TYPE.
          * But the PostgreSQL driver 42.2.2 still provides rows in random 
order.
+         * Also, if we find information about tiny int, but it does not 
specify signing information,
+         * we continue looping in case the type information is duplicated with 
more information later.
          */
-        boolean unsigned = true;
+        Boolean unsigned = null;
         try (ResultSet reflect = metadata.getTypeInfo()) {
             while (reflect.next()) {
                 if (reflect.getInt(Reflection.DATA_TYPE) == Types.TINYINT) {
                     unsigned = 
reflect.getBoolean(Reflection.UNSIGNED_ATTRIBUTE);
-                    if (unsigned) break;        // Give precedence to "true" 
value.
+                    if (reflect.wasNull()) unsigned = null;
+                    else break;
                 }
             }
+        } catch (SQLFeatureNotSupportedException e) {
+            // If metadata cannot be fetched, consider it equivalent to an 
empty metadata: assume default interpretation
+            unsigned = null;
         }
+
+        if (unsigned == null) {
+            unsigned = true;
+            listeners.warning(Resources.forLocale(listeners.getLocale())
+                                       
.getString(Resources.Keys.AssumeUnsigned));
+        }
+
         this.source        = source;
         this.isByteSigned  = !unsigned;
         this.geomLibrary   = geomLibrary;
diff --git 
a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Resources.java
 
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Resources.java
index 5a5a23d2a3..3c4fa47446 100644
--- 
a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Resources.java
+++ 
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Resources.java
@@ -56,6 +56,11 @@ public class Resources extends IndexedResourceBundle {
         private Keys() {
         }
 
+        /**
+         * Assume database byte/tinyint unsigned, due to a lack of metadata.
+         */
+        public static final short AssumeUnsigned = 16;
+
         /**
          * Cannot fetch a Coordinate Reference System (CRS) for SRID code {0}.
          */
diff --git 
a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Resources.properties
 
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Resources.properties
index b052d22dce..dd6bc75655 100644
--- 
a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Resources.properties
+++ 
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Resources.properties
@@ -19,6 +19,7 @@
 # Resources in this file are for "sis-sqlstore" usage only and should not be 
used by any other module.
 # For resources shared by all modules in the Apache SIS project, see 
"org.apache.sis.util.resources" package.
 #
+AssumeUnsigned                    = Assume database byte/tinyint unsigned, due 
to a lack of metadata.
 CanNotFetchCRS_1                  = Cannot fetch a Coordinate Reference System 
(CRS) for SRID code {0}.
 CanNotFindSRID_1                  = Cannot find an identifier in the database 
for the reference system \u201c{0}\u201d.
 DataSource                        = Provider of connections to the database.
diff --git 
a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Resources_fr.properties
 
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Resources_fr.properties
index c46969e66a..27403a8bce 100644
--- 
a/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Resources_fr.properties
+++ 
b/storage/sis-sqlstore/src/main/java/org/apache/sis/internal/sql/feature/Resources_fr.properties
@@ -24,6 +24,7 @@
 #   U+202F NARROW NO-BREAK SPACE  before  ; ! and ?
 #   U+00A0 NO-BREAK SPACE         before  :
 #
+AssumeUnsigned                    = Les valeurs de type 'tinyint'/'byte' 
seront consid�r�es comme non sign�es, car la base de donn�es ne fournit pas 
d'information � ce sujet.
 CanNotFetchCRS_1                  = Ne peut pas obtenir un syst\u00e8me de 
r\u00e9f\u00e9rence des coordonn\u00e9es pour le code SRID {0}.
 CanNotFindSRID_1                  = Ne peut pas trouver un identifiant dans la 
base de donn\u00e9es pour le syst\u00e8me de r\u00e9f\u00e9rence 
\u00ab\u202f{0}\u202f\u00bb.
 DataSource                        = Fournisseur de connexions \u00e0 la base 
de donn\u00e9es.

Reply via email to