sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1731652 - in /sis/branches/JDK8/core/sis-referencing/src: main/java/org/apache/sis/referencing/factory/sql/ main/resources/org/apache/sis/referencing/factory/sql/ test/java/org/apache/sis/referencing/factory/sql/
Date Mon, 22 Feb 2016 14:43:13 GMT
Author: desruisseaux
Date: Mon Feb 22 14:43:13 2016
New Revision: 1731652

URL: http://svn.apache.org/viewvc?rev=1731652&view=rev
Log:
Keep the definition of enumerated values in SIS instead than with the EPSG scripts because
those enumerated values are closely related to hard-coded values in EPSGDataAccess Java code.

Added:
    sis/branches/JDK8/core/sis-referencing/src/main/resources/org/apache/sis/referencing/factory/sql/EPSG_Finish.sql
      - copied unchanged from r1731651, sis/branches/JDK8/core/sis-referencing/src/main/resources/org/apache/sis/referencing/factory/sql/EPSG.sql
    sis/branches/JDK8/core/sis-referencing/src/main/resources/org/apache/sis/referencing/factory/sql/EPSG_Prepare.sql
  (with props)
Removed:
    sis/branches/JDK8/core/sis-referencing/src/main/resources/org/apache/sis/referencing/factory/sql/EPSG.sql
Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/InstallationScriptProvider.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGDataFormatter.java

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java?rev=1731652&r1=1731651&r2=1731652&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
[UTF-8] Mon Feb 22 14:43:13 2016
@@ -974,6 +974,9 @@ addURIs:    for (int i=0; ; i++) {
      * The given {@code name} may be prefixed by {@code "epsg_"} and may contain abbreviations
of the full name.
      * For example {@code "epsg_coordoperation"} is considered as a match for {@code "Coordinate_Operation"}.
      *
+     * <p>The table name should be one of the values enumerated in the {@code epsg_table_name}
type of the
+     * {@code EPSG_Prepare.sql} file.</p>
+     *
      * @param  expected  The expected table name (e.g. {@code "Coordinate_Operation"}).
      * @param  name      The actual table name.
      * @return Whether the given {@code name} is considered to match the expected name.
@@ -1320,6 +1323,9 @@ addURIs:    for (int i=0; ; i++) {
                 /*
                  * Note: Do not invoke 'createProperties' now, even if we have all required
informations,
                  *       because the 'properties' map is going to overwritten by calls to
'createDatum', etc.
+                 *
+                 * The following switch statement should have a case for all "epsg_crs_kind"
values enumerated
+                 * in the "EPSG_Prepare.sql" file, except that the values in this Java code
are in lower cases.
                  */
                 final CRSFactory crsFactory = owner.crsFactory;
                 final CoordinateReferenceSystem crs;
@@ -1596,6 +1602,10 @@ addURIs:    for (int i=0; ; i++) {
                 } catch (NumberFormatException exception) {
                     unexpectedException("createDatum", exception);          // Not a fatal
error.
                 }
+                /*
+                 * The following switch statement should have a case for all "epsg_datum_kind"
values enumerated
+                 * in the "EPSG_Prepare.sql" file, except that the values in this Java code
are in lower cases.
+                 */
                 final DatumFactory datumFactory = owner.datumFactory;
                 final Datum datum;
                 switch (type.toLowerCase(Locale.US)) {
@@ -2047,6 +2057,10 @@ addURIs:    for (int i=0; ; i++) {
                 final boolean deprecated = getOptionalBoolean(result, 6);
                 final CoordinateSystemAxis[] axes = createCoordinateSystemAxes(epsg, dimension);
                 final Map<String,Object> properties = createProperties("Coordinate
System", name, epsg, remarks, deprecated);   // Must be after axes.
+                /*
+                 * The following switch statement should have a case for all "epsg_cs_kind"
values enumerated
+                 * in the "EPSG_Prepare.sql" file, except that the values in this Java code
are in lower cases.
+                 */
                 final CSFactory csFactory = owner.csFactory;
                 CoordinateSystem cs = null;
                 switch (type.toLowerCase(Locale.US)) {

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java?rev=1731652&r1=1731651&r2=1731652&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
[UTF-8] Mon Feb 22 14:43:13 2016
@@ -149,10 +149,10 @@ final class EPSGInstaller extends Script
             addReplacement(SQLTranslator.TABLE_PREFIX + "unitofmeasure",              "Unit
of Measure");
             addReplacement(SQLTranslator.TABLE_PREFIX + "versionhistory",             "Version
History");
             if (isEnumTypeSupported) {
-                addReplacement(SQLTranslator.TABLE_PREFIX + "datum_kind",             "Datum
kind");
-                addReplacement(SQLTranslator.TABLE_PREFIX + "crs_kind",               "CRS
kind");
-                addReplacement(SQLTranslator.TABLE_PREFIX + "cs_kind",                "CS
kind");
-                addReplacement(SQLTranslator.TABLE_PREFIX + "table_name",             "Table
name");
+                addReplacement(SQLTranslator.TABLE_PREFIX + "datum_kind",             "Datum
Kind");
+                addReplacement(SQLTranslator.TABLE_PREFIX + "crs_kind",               "CRS
Kind");
+                addReplacement(SQLTranslator.TABLE_PREFIX + "cs_kind",                "CS
Kind");
+                addReplacement(SQLTranslator.TABLE_PREFIX + "table_name",             "Table
Name");
             }
             prependNamespace(schema);
         }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/InstallationScriptProvider.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/InstallationScriptProvider.java?rev=1731652&r1=1731651&r2=1731652&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/InstallationScriptProvider.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/InstallationScriptProvider.java
[UTF-8] Mon Feb 22 14:43:13 2016
@@ -69,12 +69,20 @@ import java.nio.file.Path;
  */
 public abstract class InstallationScriptProvider {
     /**
+     * A sentinel value for the content of the script to execute before the official EPSG
scripts.
+     * This is an Apache SIS build-in script for constraining the values of some {@code VARCHAR}
columns
+     * to enumerations of values recognized by {@link EPSGDataAccess}. Those enumerations
are not required
+     * for proper working of {@link EPSGFactory}, but can improve data integrity.
+     */
+    protected static final String PREPARE = "Prepare";
+
+    /**
      * A sentinel value for the content of the script to execute after the official EPSG
scripts.
      * This is an Apache SIS build-in script for creating indexes or performing any other
manipulation
      * that help SIS to use the EPSG dataset. Those indexes are not required for proper working
of
      * {@link EPSGFactory}, but can significantly improve performances.
      */
-    protected static final String POST_CREATE = "(post create)";
+    protected static final String FINISH = "Finish";
 
     /**
      * The names of the SQL scripts to read.
@@ -90,7 +98,7 @@ public abstract class InstallationScript
      * (potentially completed with EPSG dataset version and database software name):</p>
      *
      * <blockquote><code>
-     *   "EPSG_Tables.sql", "EPSG_Data.sql", "EPSG_FKeys.sql", {@linkplain #POST_CREATE}
+     *   {@linkplain #PREPARE}, "EPSG_Tables.sql", "EPSG_Data.sql", "EPSG_FKeys.sql", {@linkplain
#FINISH}
      * </code></blockquote>
      *
      * @param names Names of the SQL scripts to read.
@@ -176,8 +184,8 @@ public abstract class InstallationScript
         String name = names[index];
         final Charset charset;
         final InputStream in;
-        if (POST_CREATE.equals(name)) {
-            name = authority.concat(".sql");
+        if (PREPARE.equals(name) || FINISH.equals(name)) {
+            name = authority + '_' + name + ".sql";
             in = InstallationScriptProvider.class.getResourceAsStream(name);
             charset = StandardCharsets.UTF_8;
         } else {
@@ -193,7 +201,7 @@ public abstract class InstallationScript
     /**
      * Opens the input stream for the SQL script of the given name.
      * This method is invoked by the default implementation of {@link #getScriptContent(int)}
-     * for all scripts except {@link #POST_CREATE}.
+     * for all scripts except {@link #PREPARE} and {@link #FINISH}.
      *
      * <div class="note"><b>Examples:</b>
      * If this {@code InstallationScriptProvider} instance gets the SQL scripts from files
in a well-known directory
@@ -250,10 +258,11 @@ public abstract class InstallationScript
          * Creates a default provider.
          */
         public Default() {
-            super("EPSG_Tables.sql",
+            super(PREPARE,
+                  "EPSG_Tables.sql",
                   "EPSG_Data.sql",
                   "EPSG_FKeys.sql",
-                  POST_CREATE);
+                  FINISH);
 
             Path dir = DataDirectory.DATABASES.getDirectory();
             if (dir != null) {

Added: sis/branches/JDK8/core/sis-referencing/src/main/resources/org/apache/sis/referencing/factory/sql/EPSG_Prepare.sql
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/resources/org/apache/sis/referencing/factory/sql/EPSG_Prepare.sql?rev=1731652&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/resources/org/apache/sis/referencing/factory/sql/EPSG_Prepare.sql
(added)
+++ sis/branches/JDK8/core/sis-referencing/src/main/resources/org/apache/sis/referencing/factory/sql/EPSG_Prepare.sql
[UTF-8] Mon Feb 22 14:43:13 2016
@@ -0,0 +1,45 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license
agreements.
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+
+
+--
+-- Enumerated values to be used instead of VARCHAR. Those values match switch cases in the
Apache SIS code.
+-- If those values change, then the Apache SIS code would likely needs to be updated (see
EPSGDataAccess).
+-- If enumerated values are not supported by the database, Apache SIS will automatically
replace their usage
+-- by the VARCHAR type.
+--
+CREATE TYPE epsg_datum_kind AS ENUM ('geodetic', 'vertical', 'temporal', 'engineering');
+CREATE TYPE epsg_crs_kind   AS ENUM ('geocentric', 'geographic 2D', 'geographic 3D', 'projected',
'vertical', 'temporal', 'compound', 'engineering');
+CREATE TYPE epsg_cs_kind    AS ENUM ('ellipsoidal', 'spherical', 'Cartesian', 'vertical',
'gravity-related', 'time', 'linear', 'polar', 'cylindrical', 'affine');
+CREATE TYPE epsg_table_name AS ENUM
+   ('Alias',
+    'Area',
+    'Change',
+    'Coordinate Axis',
+    'Coordinate Axis Name',
+    'Coordinate_Operation',
+    'Coordinate_Operation Method',
+    'Coordinate_Operation Parameter',
+    'Coordinate_Operation Parameter Usage',
+    'Coordinate_Operation Parameter Value',
+    'Coordinate_Operation Path',
+    'Coordinate Reference System',
+    'Coordinate System',
+    'Datum',
+    'Deprecation',
+    'Ellipsoid',
+    'Naming System',
+    'Prime Meridian',
+    'Supersession',
+    'Unit of Measure',
+    'Version History');
+
+--
+-- Those casts allow to use enumerated values as if they were VARCHAR elements.
+--
+CREATE CAST (VARCHAR AS epsg_datum_kind) WITH INOUT AS ASSIGNMENT;
+CREATE CAST (VARCHAR AS epsg_crs_kind)   WITH INOUT AS ASSIGNMENT;
+CREATE CAST (VARCHAR AS epsg_cs_kind)    WITH INOUT AS ASSIGNMENT;
+CREATE CAST (VARCHAR AS epsg_table_name) WITH INOUT AS ASSIGNMENT;

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/resources/org/apache/sis/referencing/factory/sql/EPSG_Prepare.sql
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-referencing/src/main/resources/org/apache/sis/referencing/factory/sql/EPSG_Prepare.sql
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGDataFormatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGDataFormatter.java?rev=1731652&r1=1731651&r2=1731652&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGDataFormatter.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGDataFormatter.java
[UTF-8] Mon Feb 22 14:43:13 2016
@@ -77,7 +77,7 @@ import java.nio.charset.StandardCharsets
  *
  *   <li><p>Open the {@code Tables.sql} file for edition:</p>
  *     <ul>
- *       <li>Keep the comments and enumerated values that existed in the overwritten
file.</li>
+ *       <li>Keep the header comments that existed in the overwritten file.</li>
  *       <li>In the statement creating the {@code coordinateaxis} table,
  *           add the {@code NOT NULL} constraint to the {@code coord_axis_code} column.</li>
  *       <li>In the statement creating the {@code change} table,



Mime
View raw message