sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 02/02: Reduce the amount of HSQL-specific changes to SQL statements. We do not need anymore to omit "UNIQUE" keywords or to rename "CHR" as "CHAR". Avoid the "CREATE CACHED TABLE" statement by setting a default value instead.
Date Tue, 27 Aug 2019 15:12:21 GMT
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 90949f7b5d9e58af90c517cadebc845faf734167
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue Aug 27 17:10:17 2019 +0200

    Reduce the amount of HSQL-specific changes to SQL statements.
    We do not need anymore to omit "UNIQUE" keywords or to rename "CHR" as "CHAR".
    Avoid the "CREATE CACHED TABLE" statement by setting a default value instead.
---
 .../sis/internal/metadata/sql/ScriptRunner.java    | 28 +++++++++-------------
 .../java/org/apache/sis/test/sql/TestDatabase.java |  4 ++--
 2 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java
b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java
index 2125ac3..0f5662f 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java
@@ -281,16 +281,18 @@ public class ScriptRunner implements AutoCloseable {
      * @param  maxRowsPerInsert  maximum number of rows per {@code "INSERT INTO"} statement.
      * @throws SQLException if an error occurred while creating a SQL statement.
      */
-    public ScriptRunner(final Connection connection, int maxRowsPerInsert) throws SQLException
{
+    public ScriptRunner(final Connection connection, final int maxRowsPerInsert) throws SQLException
{
         ArgumentChecks.ensureNonNull("connection", connection);
         ArgumentChecks.ensurePositive("maxRowsPerInsert", maxRowsPerInsert);
         final DatabaseMetaData metadata = connection.getMetaData();
+        this.maxRowsPerInsert   = maxRowsPerInsert;
         this.dialect            = Dialect.guess(metadata);
         this.identifierQuote    = metadata.getIdentifierQuoteString();
         this.isSchemaSupported  = metadata.supportsSchemasInTableDefinitions() &&
                                   metadata.supportsSchemasInDataManipulation();
         this.isCatalogSupported = metadata.supportsCatalogsInTableDefinitions() &&
                                   metadata.supportsCatalogsInDataManipulation();
+        this.statement          = connection.createStatement();
         switch (dialect) {
             default: {
                 isEnumTypeSupported      = false;
@@ -315,23 +317,15 @@ public class ScriptRunner implements AutoCloseable {
                 isGrantOnTableSupported  = false;
                 isCreateLanguageRequired = false;
                 isCommentSupported       = false;
-                if (maxRowsPerInsert != 0) {
-                    maxRowsPerInsert = 1;
-                }
                 /*
-                 * HSQLDB does not seem to support the {@code UNIQUE} keyword in {@code CREATE
TABLE} statements.
-                 * In addition, we must declare explicitly that we want the tables to be
cached on disk. Finally,
-                 * HSQL expects "CHR" to be spelled "CHAR".
+                 * HSQLDB stores tables in memory by default. For storing the tables on files,
we have to
+                 * use "CREATE CACHED TABLE" statement, which is HSQL-specific. For avoiding
SQL dialect,
+                 * the following statement change the default setting on current connection.
                  */
-                addReplacement("UNIQUE", "");
-                addReplacement("CHR", "CHAR");
-                addReplacement("CREATE", MORE_WORDS);
-                addReplacement("CREATE TABLE", "CREATE CACHED TABLE");
+                statement.execute("SET DATABASE DEFAULT TABLE TYPE CACHED");
                 break;
             }
         }
-        this.maxRowsPerInsert = maxRowsPerInsert;
-        statement = connection.createStatement();
         /*
          * Now build the list of statements to skip, depending of which features are supported
by the database.
          * WARNING: do not use capturing group here, because some subclasses (e.g. EPSGInstaller)
will use their
@@ -403,7 +397,7 @@ public class ScriptRunner implements AutoCloseable {
      *
      * If a text to replace contains two or more words, then this map needs to contain an
entry for the first word
      * associated to the {@link #MORE_WORDS} value. For example if one needs to replace the
{@code "CREATE TABLE"}
-     * words, then in addition to the {@code "CREATE TABLE"} entry this {@code replacements}
map shall also contain
+     * words, then in addition to the {@code "CREATE TABLE"} entry the {@code replacements}
map shall also contain
      * a {@code "CREATE"} entry associated with the {@link #MORE_WORDS} value.
      *
      * @param  inScript     the word in the script which need to be replaced.
@@ -544,9 +538,9 @@ parseLine:  while (pos < length) {
                             if (!Character.isUnicodeIdentifierPart(c)) break;
                         }
                         /*
-                         * Perform in-place replacement if the Unicode identifier is one
of the keys in the listed
-                         * in the 'replacements' map. This operation may change the buffer
length.  The 'pos' must
-                         * be updated if needed for staying the position after the Unicode
identifier.
+                         * Perform in-place replacement if the Unicode identifier is one
of the keys listed
+                         * in the 'replacements' map. This operation may change the buffer
length. The 'pos'
+                         * must be updated if needed for staying at position after the Unicode
identifier.
                          */
                         final String word = buffer.substring(start, pos);
                         final String replace = replacements.get(word);
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/test/sql/TestDatabase.java b/core/sis-metadata/src/test/java/org/apache/sis/test/sql/TestDatabase.java
index a3d0255..d610bf4 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/test/sql/TestDatabase.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/test/sql/TestDatabase.java
@@ -140,6 +140,8 @@ public strictfp class TestDatabase implements AutoCloseable {
      * @return connection to the test database.
      * @throws SQLException if an error occurred while creating the database.
      *
+     * @see <a href="http://hsqldb.org/doc/apidocs/org/hsqldb/jdbc/JDBCDataSource.html">JDBC
data source for HSQL</a>
+     *
      * @since 1.0
      */
     public static TestDatabase createOnHSQLDB(final String name, final boolean pooled) throws
SQLException {
@@ -148,12 +150,10 @@ public strictfp class TestDatabase implements AutoCloseable {
         final String url = "jdbc:hsqldb:mem:".concat(name);
         if (pooled) {
             pool = new JDBCPool();
-            pool.setDatabaseName("Apache SIS test database");
             pool.setURL(url);
             ds = pool;
         } else {
             final JDBCDataSource simple = new JDBCDataSource();
-            simple.setDatabaseName("Apache SIS test database");
             simple.setURL(url);
             ds = simple;
             pool = null;


Mime
View raw message