sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/02: Rename older Dialect fields for consistency. Refine regular expression.
Date Tue, 02 Jun 2020 11:03:20 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 5599c0e14f81174ec2fa927f5ab35625cb70e509
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue Jun 2 12:59:47 2020 +0200

    Rename older Dialect fields for consistency. Refine regular expression.
---
 .../org/apache/sis/internal/metadata/sql/Dialect.java | 19 ++++++++++++-------
 .../sis/internal/metadata/sql/ScriptRunner.java       |  7 ++++---
 .../sis/internal/metadata/sql/package-info.java       |  1 +
 .../org/apache/sis/metadata/sql/MetadataWriter.java   | 10 +++++-----
 4 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Dialect.java
b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Dialect.java
index 1865d76..4c22a22 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Dialect.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Dialect.java
@@ -26,13 +26,16 @@ import org.apache.sis.util.CharSequences;
  * that can not (to our knowledge) be inferred from the {@link DatabaseMetaData}.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 0.8
+ * @author  Johann Sorel (Geomatys)
+ * @version 1.1
  * @since   0.7
  * @module
  */
 public enum Dialect {
     /**
      * The database is presumed to use ANSI SQL syntax.
+     *
+     * @see DatabaseMetaData#supportsANSI92EntryLevelSQL()
      */
     ANSI(null, false, true),
 
@@ -75,7 +78,7 @@ public enum Dialect {
     /**
      * Whether this dialect support table inheritance.
      */
-    public final boolean isTableInheritanceSupported;
+    public final boolean supportsTableInheritance;
 
     /**
      * {@code true} if child tables inherit the index of their parent tables.
@@ -83,23 +86,25 @@ public enum Dialect {
      *
      * @see <a href="https://issues.apache.org/jira/browse/SIS-358">SIS-358</a>
      */
-    public final boolean isIndexInheritanceSupported = false;
+    public final boolean supportsIndexInheritance = false;
 
     /**
      * Whether this dialect support adding table constraints after creation.
      * This feature is not yet supported in SQLite.
      *
-     * @see <a href="https://www.sqlite.org/omitted.html">SQL Features That SQLite
Does Not Implement</a>
+     * @see DatabaseMetaData#supportsAlterTableWithAddColumn()
      */
     public final boolean supportsAlterTableWithAddConstraint;
 
     /**
      * Creates a new enumeration value for a SQL dialect for the given protocol.
      */
-    private Dialect(final String protocol, final boolean isTableInheritanceSupported,
-            final boolean supportsAlterTableWithAddConstraint) {
+    private Dialect(final String  protocol,
+                    final boolean supportsTableInheritance,
+                    final boolean supportsAlterTableWithAddConstraint)
+    {
         this.protocol = protocol;
-        this.isTableInheritanceSupported = isTableInheritanceSupported;
+        this.supportsTableInheritance = supportsTableInheritance;
         this.supportsAlterTableWithAddConstraint = supportsAlterTableWithAddConstraint;
     }
 
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 c6af122..3e6b8b7 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
@@ -50,7 +50,8 @@ import org.apache.sis.util.resources.Errors;
  * functionalities other than what we need for those scripts.</p>
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @author  Johann Sorel (Geomatys)
+ * @version 1.1
  * @since   0.7
  * @module
  */
@@ -343,7 +344,7 @@ public class ScriptRunner implements AutoCloseable {
             addStatementToSkip("COMMENT\\s+ON\\s+.*");
         }
         if (!dialect.supportsAlterTableWithAddConstraint) {
-            addStatementToSkip("ALTER TABLE.+ADD CONSTRAINT.*");
+            addStatementToSkip("ALTER\\s+TABLE\\s+\\w+\\s+ADD\\s+CONSTRAINT\\s+.*");
         }
     }
 
@@ -714,7 +715,7 @@ parseLine:  while (pos < length) {
             return 0;
         }
         String subSQL = currentSQL = CharSequences.trimWhitespaces(sql).toString();
-        if (!dialect.isTableInheritanceSupported && subSQL.startsWith("CREATE TABLE"))
{
+        if (!dialect.supportsTableInheritance && subSQL.startsWith("CREATE TABLE"))
{
             final int s = sql.lastIndexOf("INHERITS");
             if (s >= 0 && isOutsideQuotes(sql, s+8, sql.length())) {         
   // 8 is the length of "INHERITS".
                 sql.setLength(CharSequences.skipTrailingWhitespaces(sql, 0, s));
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/package-info.java
b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/package-info.java
index f2470d8..4ef929e 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/package-info.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/package-info.java
@@ -72,6 +72,7 @@
  * </ol>
  *
  * @author  Martin Desruisseaux (Geomatys)
+ * @author  Johann Sorel (Geomatys)
  * @version 1.1
  * @since   0.7
  * @module
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataWriter.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataWriter.java
index 1c28195..e2cd11f 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataWriter.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataWriter.java
@@ -306,7 +306,7 @@ public class MetadataWriter extends MetadataSource {
                  * (if such parent exists). In most case, the answer is "no" and 'addTo'
is equals to 'table'.
                  */
                 String addTo = table;
-                if (helper.dialect.isTableInheritanceSupported) {
+                if (helper.dialect.supportsTableInheritance) {
                     @SuppressWarnings("null")
                     final Class<?> declaring = colTables.get(column);
                     if (!interfaceType.isAssignableFrom(declaring)) {
@@ -421,7 +421,7 @@ public class MetadataWriter extends MetadataSource {
                     if (dependency == null) {
                         dependency = add(stmt, value, done, identifier);
                         assert done.get(value) == dependency;                       // Really
identity comparison.
-                        if (!helper.dialect.isIndexInheritanceSupported) {
+                        if (!helper.dialect.supportsIndexInheritance) {
                             /*
                              * In a classical object-oriented model, the foreigner key constraints
declared in the
                              * parent table would take in account the records in the child
table and we would have
@@ -507,7 +507,7 @@ public class MetadataWriter extends MetadataSource {
                  * However this is not yet supported as of PostgreSQL 9.6. If inheritance
is not supported,
                  * then we have to repeat the constraint creation in child tables.
                  */
-                if (!helper.dialect.isIndexInheritanceSupported && !table.equals(fkey.tableName))
{
+                if (!helper.dialect.supportsIndexInheritance && !table.equals(fkey.tableName))
{
                     stmt.executeUpdate(helper.createForeignKey(schema(), table, column, target,
primaryKey, !isCodeList));
                 }
             }
@@ -597,12 +597,12 @@ public class MetadataWriter extends MetadataSource {
                 if (standard.isMetadata(candidate)) {
                     isChildTable = Boolean.TRUE;
                     final SQLBuilder helper = helper();
-                    if (helper.dialect.isTableInheritanceSupported) {
+                    if (helper.dialect.supportsTableInheritance) {
                         final String parent = getTableName(candidate);
                         createTable(stmt, candidate, parent, getExistingColumns(parent));
                         if (inherits == null) {
                             helper.clear().append("CREATE TABLE ").appendIdentifier(schema(),
table);
-                            if (!helper.dialect.isIndexInheritanceSupported) {
+                            if (!helper.dialect.supportsIndexInheritance) {
                                 /*
                                  * In a classical object-oriented model, the new child table
would inherit the index from
                                  * its parent table. However this is not yet the case as
of PostgreSQL 9.6. If the index is


Mime
View raw message