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

asf-gitbox-commits 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 1bf2017453 More flexible workaround for HSQLDB not supporting fully 
collations in LIKE clauses: There is actually a partial support, if the 
wildcard is only at the end.
1bf2017453 is described below

commit 1bf20174537ed4c682397647e0c39504d6298be1
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Sat Oct 17 18:42:01 2026 +0200

    More flexible workaround for HSQLDB not supporting fully collations in LIKE 
clauses:
    There is actually a partial support, if the wildcard is only at the end.
---
 .../sis/metadata/sql/internal/shared/Dialect.java  | 11 +++++++
 .../referencing/factory/sql/EPSGCodeFinder.java    | 20 ++++++++++---
 .../referencing/factory/sql/EPSGFactoryTest.java   | 35 ++++++++++++++++++++++
 3 files changed, 62 insertions(+), 4 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/sql/internal/shared/Dialect.java
 
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/sql/internal/shared/Dialect.java
index ff2a4ee83e..17152a9523 100644
--- 
a/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/sql/internal/shared/Dialect.java
+++ 
b/endorsed/src/org.apache.sis.metadata/main/org/apache/sis/metadata/sql/internal/shared/Dialect.java
@@ -56,6 +56,17 @@ public enum Dialect {
     /**
      * The database uses HSQL syntax. This is ANSI, but does not allow {@code 
INSERT} statements inserting many lines.
      * It also have a {@code SHUTDOWN} command which is specific to HSQLDB.
+     *
+     * Note: the following HSQLDB 2.7.4 issues require workaround by Apache 
SIS:
+     *
+     * <ul>
+     *   <li><a href="https://sourceforge.net/p/hsqldb/bugs/1752/";>HSQLDB 
should not depend on the jdk.unsupporte module</a></li>
+     *   <li><a href="https://sourceforge.net/p/hsqldb/bugs/1753/";>Deadlock 
between SchemaManager and SessionManager</a></li>
+     *   <li><a 
href="https://sourceforge.net/p/hsqldb/bugs/1754/";>Connection.rollback() does 
not remove schemas</a></li>
+     *   <li><a href="https://sourceforge.net/p/hsqldb/bugs/1758/";>Embedded 
database extremely slow because of inefficient length measurement</a></li>
+     *   <li><a href="https://sourceforge.net/p/hsqldb/bugs/1761/";>Embedded 
database does not work when HSQL is on the module-path</a></li>
+     *   <li><a href="https://sourceforge.net/p/hsqldb/bugs/1762/";>Collation 
does not work with LIKE clause having wildcard in the middle</a></li>
+     * </ul>
      */
     HSQL("hsqldb", Supports.ALTER_TABLE_WITH_ADD_CONSTRAINT
                  | Supports.READ_ONLY_UPDATE
diff --git 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGCodeFinder.java
 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGCodeFinder.java
index 3f8040eb23..4bdd45d083 100644
--- 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGCodeFinder.java
+++ 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/factory/sql/EPSGCodeFinder.java
@@ -553,6 +553,15 @@ crs:    if (isInstance(CoordinateReferenceSystem.class, 
object)) {
      * Note that this rule replaces also the {@code %}, {@code _} and {@code 
'} characters,
      * thus avoiding the need to escape them.
      *
+     * <p>A trailing {@code '%'} character is added for including datum 
variants.
+     * For example if the name is <q>Nouvelle Triangulation Française</q>,
+     * we want to find the following:</p>
+     *
+     * <ul>
+     *   <li>EPSG:6275 — Nouvelle Triangulation Française</li>
+     *   <li>EPSG:6807 — Nouvelle Triangulation Française (Paris)</li>
+     * </ul>
+     *
      * <p>This method does not try to address case-insensitive and 
accent-insensitive searches.
      * This method assumes that the column uses a database collation ignoring 
cases and accents.
      * This method is used in complement to collation, for adding more 
flexibility in the punctuations.
@@ -624,14 +633,17 @@ crs:    if (isInstance(CoordinateReferenceSystem.class, 
object)) {
                 if (isNext) {
                     buffer.append(" OR ");
                 }
-                final String name;
-                final String operator;
+                String name;
+                String operator = " LIKE ";
                 if (supportsCollationInLike) {
                     name = entry.getValue();    // LIKE pattern.
-                    operator = " LIKE ";
                 } else {
                     name = entry.getKey();      // Original name.
-                    operator = " = ";
+                    if (name.indexOf('%') < 0 && name.indexOf('_') < 0) {
+                        name += '%';            // On HSQLDB, LIKE works if 
the wildcard is only at the end.
+                    } else {
+                        operator = " = ";       // Collation does not fully 
work with LIKE clause on HSQLDB.
+                    }
                 }
                 
buffer.append(column).append(operator).append(JDK26.enquoteLiteral(name));
                 isNext = true;
diff --git 
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java
 
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java
index d610ce1334..bc9f776f42 100644
--- 
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java
+++ 
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java
@@ -1022,4 +1022,39 @@ public final class EPSGFactoryTest extends 
TestCaseWithLogs {
         assertFalse(it.hasNext());
         loggings.assertNoUnexpectedLog();
     }
+
+    /**
+     * Tests {@link EPSGFactory#newIdentifiedObjectFinder()} method in a way 
that requires collation support.
+     * This test reproduces the * <a 
href="https://sis.apache.org/command-line.html#identifier";>Getting a verified
+     * EPSG identifier from a Coordinate Reference System</a> example with 
{@code MissingIdentifier.wkt} sample file.
+     *
+     * @throws FactoryException if an error occurred while querying the 
factory.
+     */
+    @Test
+    public void testFindNeedsCollation() throws FactoryException {
+        final CoordinateReferenceSystem crs = CRS.fromWKT(
+                "PROJCRS[“NTF (Paris) / zone to be discovered by the demo”,\n"
+                + "  BASEGEODCRS[“Bla (Paris)”,\n"
+                + "    DATUM[“Nouvelle Triangulation Francaise”,\n"     // 
Intentionally omitting the "(Paris") suffix.
+                + "      ELLIPSOID[“Clarke 1880 (IGN)”, 6378249.2, 
293.4660212936269]],\n"
+                + "      PRIMEM[“Paris”, 2.5969213],\n"
+                + "    UNIT[“grade”, 0.015707963267948967]],\n"
+                + "  CONVERSION[“Lambert zone II”,\n"
+                + "    METHOD[“Lambert Conic Conformal (1SP)”],\n"
+                + "    PARAMETER[“Latitude of natural origin”, 52.0, 
UNIT[“grade”, 0.015707963267948967]],\n"
+                + "    PARAMETER[“Scale factor at natural origin”, 
0.99987742],\n"
+                + "    PARAMETER[“False easting”, 600000.0],\n"
+                + "    PARAMETER[“False northing”, 2200000.0]],\n"
+                + "  CS[Cartesian, 2],\n"
+                + "    AXIS[“Easting (E)”, east],\n"
+                + "    AXIS[“Northing (N)”, north],\n"
+                + "    LENGTHUNIT[“metre”, 1],\n"
+                + "  REMARK[“In this example, the EPSG:27572 identifier has 
been intentionally omitted.”]]");
+
+        assertNotNull(dataEPSG.factory());    // Skip the test if no EPSG 
database.
+        final String identifier = IdentifiedObjects.lookupURN(crs, 
Citations.EPSG);
+        assertNotNull(identifier);
+        assertTrue(identifier.endsWith(":27572"), identifier);
+        loggings.assertNoUnexpectedLog();
+    }
 }

Reply via email to