sis-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=1731642&view=rev
Log:
Allow use of enumerated values instead of VARCHAR for columns that are used in Java switch
statements.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.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/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=1731642&r1=1731641&r2=1731642&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 13:41:23 2016
@@ -43,6 +43,8 @@ import org.apache.sis.util.logging.Perfo
 /**
  * Runs the SQL scripts for creating an EPSG database.
  *
+ * See {@code EPSGDataFormatter} in the test directory for more information about how the
scripts are formatted.
+ *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.7
  * @version 0.7
@@ -146,8 +148,20 @@ final class EPSGInstaller extends Script
             addReplacement(SQLTranslator.TABLE_PREFIX + "supersession",               "Supersession");
             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");
+            }
             prependNamespace(schema);
         }
+        if (!isEnumTypeSupported) {
+            addReplacement(SQLTranslator.TABLE_PREFIX + "datum_kind", "VARCHAR(24)");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "crs_kind",   "VARCHAR(24)");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "cs_kind",    "VARCHAR(24)");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "table_name", "VARCHAR(80)");
+        }
     }
 
     /**
@@ -205,6 +219,12 @@ final class EPSGInstaller extends Script
         if (!isGrantOnTableSupported && CharSequences.regionMatches(sql, 0, "GRANT"))
{
             return 0;
         }
+        if (!isEnumTypeSupported && CharSequences.regionMatches(sql, 0, "CREATE"))
{
+            final String t = CharSequences.trimWhitespaces(sql, 6, 12).toString();
+            if (t.equals("TYPE") || t.equals("CAST")) {
+                return 0;
+            }
+        }
         if (statementToSkip != null && statementToSkip.reset(sql).matches()) {
             return 0;
         }

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=1731642&r1=1731641&r2=1731642&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 13:41:23 2016
@@ -32,6 +32,7 @@ import java.sql.SQLException;
 import javax.sql.DataSource;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import org.apache.sis.util.Workaround;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.internal.metadata.sql.ScriptRunner;
 import org.apache.sis.internal.metadata.sql.TestDatabase;
@@ -76,6 +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>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,
@@ -85,6 +87,10 @@ import java.nio.charset.StandardCharsets
  *           change the type of the {@code realization_epoch} column to {@code SMALLINT}.</li>
  *       <li>Change the type of {@code show_crs}, {@code show_operation} and all {@code
deprecated} fields
  *           from {@code SMALLINT} to {@code BOOLEAN}.</li>
+ *       <li>Change the type of every {@code table_name} columns from {@code VARCHAR(80)}
to {@code epsg_table_name}.</li>
+ *       <li>Change the type of {@code coord_ref_sys_kind} column from {@code VARCHAR(24)}
to {@code epsg_crs_kind}.</li>
+ *       <li>Change the type of {@code coord_sys_type} column from {@code VARCHAR(24)}
to {@code epsg_cs_kind}.</li>
+ *       <li>Change the type of {@code datum_type} column from {@code VARCHAR(24)}
to {@code epsg_datum_kind}.</li>
  *       <li>Suppress trailing spaces and save.</li>
  *     </ul>
  *     <p>Usually this results in no change at all compared to the previous script
(ignoring white spaces),
@@ -239,6 +245,14 @@ public final class EPSGDataFormatter ext
         try (final LineNumberReader in = new LineNumberReader(
                 new InputStreamReader(new FileInputStream(inputFile), StandardCharsets.ISO_8859_1)))
         {
+            out.write("---\n" +
+                      "---    Copyright International Association of Oil and Gas Producers
(IOGP)\n" +
+                      "---    See  http://www.epsg.org/TermsOfUse  (a copy is in ./LICENSE.txt).\n"
+
+                      "---\n" +
+                      "---    This file has been reformatted (without any change in the data)
for the needs of Apache SIS project.\n" +
+                      "---    See org.apache.sis.referencing.factory.sql.EPSGDataFormatter.\n"
+
+                      "---\n" +
+                      "\n");
             run(inputFile.getName(), in);
         } finally {
             out.close();
@@ -247,6 +261,18 @@ public final class EPSGDataFormatter ext
     }
 
     /**
+     * EPSG scripts version 8.9 seems to have 2 errors where the {@code OBJECT_TABLE_NAME}
column contains
+     * {@code "AxisName"} instead of {@code "Coordinate Axis Name"}.
+     */
+    @Override
+    @Workaround(library="EPSG", version="8.9")
+    protected void editText(final StringBuilder sql, int lower, final int upper) {
+        if (upper - lower == 10 && CharSequences.regionMatches(sql, ++lower, "AxisName"))
{
+            sql.replace(lower, upper-1, "Coordinate Axis Name");
+        }
+    }
+
+    /**
      * "Executes" the given SQL statement. In the context of this {@code EPSGDataWriter}
class,
      * executing a SQL statement means compacting it and writing it to the output file.
      *
@@ -259,6 +285,35 @@ public final class EPSGDataFormatter ext
     protected int execute(final StringBuilder sql) throws IOException, SQLException {
         removeLF(sql);
         String line = CharSequences.trimWhitespaces(sql).toString();
+        if (line.startsWith("UPDATE ")) {
+            /*
+             * Some EPSG tables have a "table_name" field which will contain the names of
other EPSG tables.
+             * In the EPSG scripts, the values are initially the table names used in the
MS-Access database.
+             * Then the MS-Access table names are replaced by statements like below:
+             *
+             *    UPDATE epsg_alias SET object_table_name = 'epsg_coordinateaxis' WHERE object_table_name
= 'Coordinate Axis';
+             *    UPDATE epsg_deprecation SET object_table_name = 'epsg_alias' WHERE object_table_name
= 'Alias';
+             *    etc.
+             *
+             * For Apache SIS, we keep the original table names as defined in MS-Access database,
+             * for consistency with the table names that we actually use in our EPSG schema.
+             */
+            if (line.contains("object_table_name")) {
+                return 0;
+            }
+            /*
+             * Following statements do not make sense anymore on enumerated values:
+             *
+             *    UPDATE epsg_coordinatereferencesystem SET coord_ref_sys_kind = replace(coord_ref_sys_kind,
CHR(182), CHR(10));
+             *    UPDATE epsg_coordinatesystem SET coord_sys_type = replace(coord_sys_type,
CHR(182), CHR(10));
+             *    UPDATE epsg_datum SET datum_type = replace(datum_type, CHR(182), CHR(10));
+             */
+            if (line.contains("replace")) {
+                if (line.contains("coord_ref_sys_kind") || line.contains("coord_sys_type")
|| line.contains("datum_type")) {
+                    return 0;
+                }
+            }
+        }
         if (insertStatement != null) {
             if (line.startsWith(insertStatement)) {
                 // The previous instruction was already an INSERT INTO the same table.



Mime
View raw message