sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 03/03: Leverage Reflection constants in other modules.
Date Wed, 04 Jul 2018 16:08:16 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 8b9558f54bf55dced1819f5d93093855686b212d
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Jul 4 17:51:18 2018 +0200

    Leverage Reflection constants in other modules.
---
 .../sis/internal/metadata/sql/Reflection.java       | 21 +++++++++++++--------
 .../org/apache/sis/metadata/sql/MetadataSource.java |  3 ++-
 .../org/apache/sis/metadata/sql/MetadataWriter.java | 11 ++++++-----
 .../sis/referencing/factory/sql/SQLTranslator.java  |  9 +++++----
 .../referencing/factory/sql/EPSGInstallerTest.java  |  3 ++-
 5 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Reflection.java
b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Reflection.java
index 45f21b2..71ea48a 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Reflection.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Reflection.java
@@ -41,6 +41,13 @@ import java.sql.DatabaseMetaData;
  */
 public final class Reflection {
     /**
+     * The {@value} key for getting a catalog name. This column appears in all reflection
+     * operations (listing schemas, tables, columns, constraints, <i>etc.</i>)
used by SIS.
+     * The value in that column may be null.
+     */
+    public static final String TABLE_CAT = "TABLE_CAT";
+
+    /**
      * The {@value} key for getting a schema name. This column appears in all reflection
      * operations (listing schemas, tables, columns, constraints, <i>etc.</i>)
used by SIS.
      * The value in that column may be null.
@@ -86,14 +93,6 @@ public final class Reflection {
     public static final String COLUMN_SIZE = "COLUMN_SIZE";
 
     /**
-     * The {@value} key for the number of fractional digits.
-     * Null is returned for data types where {@code DECIMAL_DIGITS} is not applicable.
-     *
-     * <p>Values in this column are integers ({@code int}) rather than {@code String}.</p>
-     */
-    public static final String DECIMAL_DIGITS = "DECIMAL_DIGITS";
-
-    /**
      * The {@value} key for the nullability of a column. Possible values are {@code "YES"}
if
      * the parameter can include NULLs, {@code "NO"} if the parameter cannot include NULLs,
      * and empty string if the nullability for the parameter is unknown.
@@ -120,6 +119,12 @@ public final class Reflection {
     public static final String PK_NAME = "PK_NAME";
 
     /**
+     * The {@value} key for the primary key table catalog being imported.
+     * Values in this column may be null.
+     */
+    public static final String PKTABLE_CAT = "PKTABLE_CAT";
+
+    /**
      * The {@value} key for the primary key table schema being imported.
      * Values in this column may be null.
      */
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
index e268e80..4501b17 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
@@ -56,6 +56,7 @@ import org.apache.sis.internal.system.SystemListener;
 import org.apache.sis.internal.system.DelayedExecutor;
 import org.apache.sis.internal.system.DelayedRunnable;
 import org.apache.sis.internal.metadata.sql.Initializer;
+import org.apache.sis.internal.metadata.sql.Reflection;
 import org.apache.sis.internal.metadata.sql.SQLBuilder;
 import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.internal.util.CollectionsExt;
@@ -792,7 +793,7 @@ public class MetadataSource implements AutoCloseable {
             final DatabaseMetaData md = connection().getMetaData();
             try (ResultSet rs = md.getColumns(catalog, schema, table, null)) {
                 while (rs.next()) {
-                    if (!columns.add(rs.getString("COLUMN_NAME"))) {
+                    if (!columns.add(rs.getString(Reflection.COLUMN_NAME))) {
                         // Paranoiac check, but should never happen.
                         throw new SQLNonTransientException(table);
                     }
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 f205d0f..4b96b98 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
@@ -51,6 +51,7 @@ import org.apache.sis.metadata.ValueExistencePolicy;
 import org.apache.sis.metadata.TitleProperty;
 import org.apache.sis.metadata.iso.citation.Citations;
 import org.apache.sis.internal.metadata.sql.SQLBuilder;
+import org.apache.sis.internal.metadata.sql.Reflection;
 import org.apache.sis.xml.IdentifiedObject;
 
 // Branch-dependent imports
@@ -446,12 +447,12 @@ public class MetadataWriter extends MetadataSource {
                                     referencedTables = new HashMap<>();
                                     try (ResultSet rs = stmt.getConnection().getMetaData().getImportedKeys(catalog,
schema(), table)) {
                                         while (rs.next()) {
-                                            if ((schema() == null || schema().equals(rs.getString("PKTABLE_SCHEM")))
&&
-                                                (catalog  == null || catalog.equals(rs.getString("PKTABLE_CAT"))))
+                                            if ((schema() == null || schema().equals(rs.getString(Reflection.PKTABLE_SCHEM)))
&&
+                                                (catalog  == null || catalog.equals(rs.getString(Reflection.PKTABLE_CAT))))
                                             {
-                                                referencedTables.put(rs.getString("FKCOLUMN_NAME"),
-                                                            new FKey(rs.getString("PKTABLE_NAME"),
null,
-                                                                     rs.getString("FK_NAME")));
+                                                referencedTables.put(rs.getString(Reflection.FKCOLUMN_NAME),
+                                                            new FKey(rs.getString(Reflection.PKTABLE_NAME),
null,
+                                                                     rs.getString(Reflection.FK_NAME)));
                                             }
                                         }
                                     }
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/SQLTranslator.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/SQLTranslator.java
index 43c8641..dcf96ee 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/SQLTranslator.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/SQLTranslator.java
@@ -28,6 +28,7 @@ import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.internal.util.Constants;
+import org.apache.sis.internal.metadata.sql.Reflection;
 
 
 /**
@@ -264,8 +265,8 @@ public class SQLTranslator implements Function<String,String> {
                     isPrefixed      = table.startsWith(TABLE_PREFIX);
                     quoteTableNames = (i == MIXED_CASE);
                     do {
-                        catalog = result.getString("TABLE_CAT");
-                        schema  = result.getString("TABLE_SCHEM");
+                        catalog = result.getString(Reflection.TABLE_CAT);
+                        schema  = result.getString(Reflection.TABLE_SCHEM);
                     } while (!Constants.EPSG.equalsIgnoreCase(schema) && result.next());
                     if (schema == null) schema = "";
                     break;
@@ -304,8 +305,8 @@ public class SQLTranslator implements Function<String,String> {
         }
         try (ResultSet result = md.getColumns(catalog, schema, null, deprecated)) {
             while (result.next()) {
-                if (CharSequences.endsWith(result.getString("TABLE_NAME"), "Datum", true))
{
-                    final int type = result.getInt("DATA_TYPE");
+                if (CharSequences.endsWith(result.getString(Reflection.TABLE_NAME), "Datum",
true)) {
+                    final int type = result.getInt(Reflection.DATA_TYPE);
                     useBoolean = (type == Types.BOOLEAN) || (type == Types.BIT);
                     break;
                 }
diff --git a/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java
b/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java
index b247659..2fcdfb3 100644
--- a/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java
+++ b/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java
@@ -35,6 +35,7 @@ import org.opengis.referencing.crs.ProjectedCRS;
 import org.apache.sis.referencing.CommonCRS;
 import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.internal.util.Constants;
+import org.apache.sis.internal.metadata.sql.Reflection;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.Utilities;
 
@@ -240,7 +241,7 @@ public final strictfp class EPSGInstallerTest extends TestCase {
         try (Connection c = ds.getConnection()) {
             try (ResultSet r = c.getMetaData().getTables(null, null, "Coordinate Reference
System", null)) {
                 while (r.next()) {
-                    final String schema = r.getString("TABLE_SCHEM");
+                    final String schema = r.getString(Reflection.TABLE_SCHEM);
                     assertTrue(schema, "EPSG".equalsIgnoreCase(schema));
                     count++;
                 }


Mime
View raw message