sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1729284 - in /sis/branches/JDK7: ./ core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ core/sis-metadata/src/main/java/org/apache/sis/io/wkt/ core/sis-ref...
Date Mon, 08 Feb 2016 22:37:32 GMT
Author: desruisseaux
Date: Mon Feb  8 22:37:31 2016
New Revision: 1729284

URL: http://svn.apache.org/viewvc?rev=1729284&view=rev
Log:
Merge from the JDK8 branch.

Added:
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGDataFormatter.java
      - copied unchanged from r1729283, sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGDataFormatter.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGDataFormatterTest.java
      - copied unchanged from r1729283, sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGDataFormatterTest.java
Modified:
    sis/branches/JDK7/   (props changed)
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Transliterator.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/AuthorityCodes.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/SQLTranslator.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateOperationMethods.java
    sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java

Propchange: sis/branches/JDK7/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Feb  8 22:37:31 2016
@@ -1,4 +1,4 @@
 /sis/branches/Android:1430670-1480699
 /sis/branches/JDK6:1394913-1508480
-/sis/branches/JDK8:1584960-1728765
+/sis/branches/JDK8:1584960-1729283
 /sis/trunk:1394364-1508466,1519089-1519674

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java?rev=1729284&r1=1729283&r2=1729284&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/ReferencingServices.java
[UTF-8] Mon Feb  8 22:37:31 2016
@@ -64,7 +64,7 @@ import org.apache.sis.util.Deprecable;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
- * @version 0.6
+ * @version 0.7
  * @module
  */
 public class ReferencingServices extends OptionalDependency {
@@ -586,6 +586,8 @@ public class ReferencingServices extends
      * @return The information, or {@code null} if none.
      *
      * @see org.apache.sis.internal.util.MetadataServices#getInformation(String)
+     *
+     * @since 0.7
      */
     public String getInformation(String key, Locale locale) {
         return null;

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java?rev=1729284&r1=1729283&r2=1729284&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java
[UTF-8] Mon Feb  8 22:37:31 2016
@@ -276,10 +276,10 @@ public class ScriptRunner implements Aut
                  * In addition, we must declare explicitly that we want the tables to be
cached on disk. Finally,
                  * HSQL expects "CHR" to be spelled "CHAR".
                  */
-                replace("UNIQUE", "");
-                replace("CHR", "CHAR");
-                replace("CREATE", MORE_WORDS);
-                replace("CREATE TABLE", "CREATE CACHED TABLE");
+                addReplacement("UNIQUE", "");
+                addReplacement("CHR", "CHAR");
+                addReplacement("CREATE", MORE_WORDS);
+                addReplacement("CREATE TABLE", "CREATE CACHED TABLE");
                 break;
             }
         }
@@ -315,13 +315,24 @@ public class ScriptRunner implements Aut
      * @param inScript The word in the script which need to be replaced.
      * @param replacement The word to use instead.
      */
-    protected final void replace(final String inScript, final String replacement) {
+    protected final void addReplacement(final String inScript, final String replacement)
{
         if (replacements.put(inScript, replacement) != null) {
             throw new IllegalArgumentException(inScript);
         }
     }
 
     /**
+     * Returns the word to use instead than the given one.
+     * If there is no replacement, then {@code inScript} is returned.
+     *
+     * @param inScript The word in the script which need to be replaced.
+     * @return The word to use instead.
+     */
+    protected final String getReplacement(final String inScript) {
+        return JDK8.getOrDefault(replacements, inScript, inScript);
+    }
+
+    /**
      * For every entries in the replacements map, replace the entry value by the value returned
by
      * {@code function(key, value)}.
      *
@@ -374,8 +385,8 @@ public class ScriptRunner implements Aut
      * @throws SQLException if an error occurred while executing a SQL statement.
      */
     private int run(final LineNumberReader in) throws IOException, SQLException {
-        int     statementCount     = 0;
-        boolean isInsideText       = false;
+        int     statementCount     = 0;         // For informative purpose only.
+        int     posOpeningQuote    = -1;        // -1 if we are not inside a text.
         boolean isInsideIdentifier = false;
         final StringBuilder buffer = new StringBuilder();
         String line;
@@ -424,7 +435,7 @@ public class ScriptRunner implements Aut
 parseLine:  while (pos < length) {
                 int c = buffer.codePointAt(pos);
                 int n = Character.charCount(c);
-                if (!isInsideText && !isInsideIdentifier) {
+                if (posOpeningQuote < 0 && !isInsideIdentifier) {
                     int start = pos;
                     while (Character.isUnicodeIdentifierStart(c)) {
                         /*
@@ -475,7 +486,7 @@ parseLine:  while (pos < length) {
                      * replace the standard quote character by the database-specific one.
                      */
                     case IDENTIFIER_QUOTE: {
-                        if (!isInsideText) {
+                        if (posOpeningQuote < 0) {
                             isInsideIdentifier = !isInsideIdentifier;
                             length = buffer.replace(pos, pos + n, identifierQuote).length();
                             n = identifierQuote.length();
@@ -488,10 +499,12 @@ parseLine:  while (pos < length) {
                      */
                     case QUOTE: {
                         if (!isInsideIdentifier) {
-                            if (!isInsideText) {
-                                isInsideText = true;
+                            if (posOpeningQuote < 0) {
+                                posOpeningQuote = pos;
                             } else if ((pos += n) >= length || buffer.codePointAt(pos)
!= QUOTE) {
-                                isInsideText = false;
+                                editText(buffer, posOpeningQuote, pos);
+                                pos -= length - (length = buffer.length());
+                                posOpeningQuote = -1;
                                 continue;   // Because we already skipped the ' character.
                             } // else found a double ' character, which means to escape it.
                         }
@@ -502,7 +515,7 @@ parseLine:  while (pos < length) {
                      * since SQL statement in JDBC are not expected to contain it.
                      */
                     case END_OF_STATEMENT: {
-                        if (!isInsideText && !isInsideIdentifier) {
+                        if (posOpeningQuote < 0 && !isInsideIdentifier) {
                             if (CharSequences.skipLeadingWhitespaces(buffer, pos + n, length)
>= length) {
                                 buffer.setLength(pos);
                             }
@@ -524,6 +537,19 @@ parseLine:  while (pos < length) {
     }
 
     /**
+     * Invoked for each text found in a SQL statement. The text, <em>including its
quote characters</em>,
+     * is the {@code sql} substring from index {@code lower} inclusive to {@code upper} exclusive.
+     * Subclasses can override this method if they wish to modify the text content.
+     * Modifications are applied directly in the given {@code sql} buffer.
+     *
+     * @param sql   The whole SQL statement.
+     * @param lower Index of the opening quote character ({@code '}) of the text in {@code
sql}.
+     * @param upper Index after the closing quote character ({@code '}) of the text in {@code
sql}.
+     */
+    protected void editText(final StringBuilder sql, final int lower, final int upper) {
+    }
+
+    /**
      * Executes the given SQL statement.
      * This method performs the following choices:
      *
@@ -575,7 +601,7 @@ parseLine:  while (pos < length) {
                                 if (subSQL.charAt(end - 1) == ',') {
                                     end--;
                                 }
-                                count += statement.executeUpdate(sql.append(subSQL, begin,
end).toString());
+                                count += statement.executeUpdate(currentSQL = sql.append(subSQL,
begin, end).toString());
                                 sql.setLength(startOfValues);       // Prepare for next INSERT
INTO statement.
                                 nrows = maxRowsPerInsert;
                                 begin = endOfLine + 1;
@@ -583,7 +609,7 @@ parseLine:  while (pos < length) {
                         }
                         // The remaining of the statement to be executed.
                         int end = CharSequences.skipTrailingWhitespaces(subSQL, begin, subSQL.length());
-                        subSQL = (end > begin) ? sql.append(subSQL, begin, end).toString()
: null;
+                        currentSQL = subSQL = (end > begin) ? sql.append(subSQL, begin,
end).toString() : null;
                     }
                 }
             }

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Transliterator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Transliterator.java?rev=1729284&r1=1729283&r2=1729284&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Transliterator.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/io/wkt/Transliterator.java
[UTF-8] Mon Feb  8 22:37:31 2016
@@ -366,8 +366,13 @@ public abstract class Transliterator imp
                     }
                 }
             } else {
-                if      (abbreviation.equalsIgnoreCase("Lat" )) abbreviation = "B";
-                else if (abbreviation.equalsIgnoreCase("Long")) abbreviation = "L";
+                if (abbreviation.equalsIgnoreCase("Lat")) {
+                    abbreviation = "B";
+                } else if (abbreviation.regionMatches(true, 0, "Long", 0,
+                        Math.min(3, Math.max(4, abbreviation.length()))))   // Accept "Lon"
or "Long".
+                {
+                    abbreviation = "L";
+                }
             }
         }
         return abbreviation;

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/AuthorityCodes.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/AuthorityCodes.java?rev=1729284&r1=1729283&r2=1729284&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/AuthorityCodes.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/AuthorityCodes.java
[UTF-8] Mon Feb  8 22:37:31 2016
@@ -160,7 +160,9 @@ final class AuthorityCodes extends Abstr
         final int conditionStart = buffer.length();
         if (table.showColumn != null) {
             buffer.append(table.showColumn).append("<>0 AND ");
+            // Do not put spaces around "<>" - SQLTranslator searches for this exact
match.
         }
+        // Do not put spaces around "=" - SQLTranslator searches for this exact match.
         buffer.append("DEPRECATED=0 ORDER BY ").append(table.codeColumn);
         sql[ALL] = factory.translator.apply(buffer.toString());
         /*

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java?rev=1729284&r1=1729283&r2=1729284&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGDataAccess.java
[UTF-8] Mon Feb  8 22:37:31 2016
@@ -1569,7 +1569,7 @@ addURIs:    for (int i=0; ; i++) {
                       " COORD_OP_METHOD_CODE," +
                       " TARGET_CRS_CODE" +
                 " FROM [Coordinate_Operation]" +
-               " WHERE DEPRECATED=0" +
+               " WHERE DEPRECATED=0" +           // Do not put spaces around "=" - SQLTranslator
searches for this exact match.
                  " AND TARGET_CRS_CODE = "       + BursaWolfInfo.TARGET_CRS +
                  " AND COORD_OP_METHOD_CODE >= " + BursaWolfInfo.MIN_METHOD_CODE +
                  " AND COORD_OP_METHOD_CODE <= " + BursaWolfInfo.MAX_METHOD_CODE +
@@ -2916,7 +2916,7 @@ addURIs:    for (int i=0; ; i++) {
             }
             buffer.append(getSearchDomain() == Domain.ALL_DATASET
                           ? " ORDER BY ABS(DEPRECATED), "
-                          : " AND DEPRECATED=0 ORDER BY ");
+                          : " AND DEPRECATED=0 ORDER BY ");     // Do not put spaces around
"=" - SQLTranslator searches for this exact match.
             if (isFloat) {
                 buffer.append("ABS(").append(select).append("-?), ");
             }
@@ -3026,7 +3026,8 @@ addURIs:    for (int i=0; ; i++) {
                       " FROM [Coordinate_Operation] AS CO" +
                 " INNER JOIN [Coordinate Reference System] AS SRC ON SRC.COORD_REF_SYS_CODE
= CO.SOURCE_CRS_CODE" +
                 " INNER JOIN [Coordinate Reference System] AS TGT ON TGT.COORD_REF_SYS_CODE
= CO.TARGET_CRS_CODE" +
-                      " WHERE CO.DEPRECATED = 0 AND COORD_OP_METHOD_CODE = ?";
+                      " WHERE CO.DEPRECATED=0 AND COORD_OP_METHOD_CODE = ?";
+                // Do not put spaces in "DEPRECATED=0" - SQLTranslator searches for this
exact match.
             } else {
                 key = "DerivedDimensions";
                 sql = "SELECT DISTINCT SRC.COORD_SYS_CODE," +
@@ -3034,7 +3035,7 @@ addURIs:    for (int i=0; ; i++) {
                       " FROM [Coordinate Reference System] AS TGT" +
                 " INNER JOIN [Coordinate Reference System] AS SRC ON TGT.SOURCE_GEOGCRS_CODE
= SRC.COORD_REF_SYS_CODE" +
                 " INNER JOIN [Coordinate_Operation] AS CO ON TGT.PROJECTION_CONV_CODE = CO.COORD_OP_CODE"
+
-                      " WHERE CO.DEPRECATED = 0 AND COORD_OP_METHOD_CODE = ?";
+                      " WHERE CO.DEPRECATED=0 AND COORD_OP_METHOD_CODE = ?";
             }
             try (ResultSet result = executeQuery(key, sql, method)) {
                 while (result.next()) {

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java?rev=1729284&r1=1729283&r2=1729284&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
[UTF-8] Mon Feb  8 22:37:31 2016
@@ -63,6 +63,11 @@ final class EPSGInstaller extends Script
     };
 
     /**
+     * The encoding used in the SQL scripts.
+     */
+    static final String ENCODING = "ISO-8859-1";
+
+    /**
      * The pattern for an {@code "UPDATE … SET … REPLACE"} instruction.
      * Example:
      *
@@ -71,7 +76,7 @@ final class EPSGInstaller extends Script
      *     SET datum_name = replace(datum_name, CHAR(182), CHAR(10));
      * }
      */
-    private static final String REPLACE_STATEMENT =
+    static final String REPLACE_STATEMENT =
             "\\s*UPDATE\\s+[\\w\\.\" ]+\\s+SET\\s+(\\w+)\\s*=\\s*replace\\s*\\(\\s*\\1\\W+.*";
 
     /**
@@ -95,7 +100,7 @@ final class EPSGInstaller extends Script
      * @throws SQLException if an error occurred while executing a SQL statement.
      */
     public EPSGInstaller(final Connection connection) throws SQLException {
-        super(connection, "ISO-8859-1", 100);
+        super(connection, ENCODING, 100);
         boolean isReplaceSupported = false;
         final DatabaseMetaData metadata = connection.getMetaData();
         final String functions = metadata.getStringFunctions();
@@ -138,27 +143,27 @@ final class EPSGInstaller extends Script
              * Mapping from the table names used in the SQL scripts to the original names
used in the MS-Access database.
              * We use those original names because they are easier to read than the names
in SQL scripts.
              */
-            replace(SQLTranslator.TABLE_PREFIX + "alias",                      "Alias");
-            replace(SQLTranslator.TABLE_PREFIX + "area",                       "Area");
-            replace(SQLTranslator.TABLE_PREFIX + "change",                     "Change");
-            replace(SQLTranslator.TABLE_PREFIX + "coordinateaxis",             "Coordinate
Axis");
-            replace(SQLTranslator.TABLE_PREFIX + "coordinateaxisname",         "Coordinate
Axis Name");
-            replace(SQLTranslator.TABLE_PREFIX + "coordoperation",             "Coordinate_Operation");
-            replace(SQLTranslator.TABLE_PREFIX + "coordoperationmethod",       "Coordinate_Operation
Method");
-            replace(SQLTranslator.TABLE_PREFIX + "coordoperationparam",        "Coordinate_Operation
Parameter");
-            replace(SQLTranslator.TABLE_PREFIX + "coordoperationparamusage",   "Coordinate_Operation
Parameter Usage");
-            replace(SQLTranslator.TABLE_PREFIX + "coordoperationparamvalue",   "Coordinate_Operation
Parameter Value");
-            replace(SQLTranslator.TABLE_PREFIX + "coordoperationpath",         "Coordinate_Operation
Path");
-            replace(SQLTranslator.TABLE_PREFIX + "coordinatereferencesystem",  "Coordinate
Reference System");
-            replace(SQLTranslator.TABLE_PREFIX + "coordinatesystem",           "Coordinate
System");
-            replace(SQLTranslator.TABLE_PREFIX + "datum",                      "Datum");
-            replace(SQLTranslator.TABLE_PREFIX + "deprecation",                "Deprecation");
-            replace(SQLTranslator.TABLE_PREFIX + "ellipsoid",                  "Ellipsoid");
-            replace(SQLTranslator.TABLE_PREFIX + "namingsystem",               "Naming System");
-            replace(SQLTranslator.TABLE_PREFIX + "primemeridian",              "Prime Meridian");
-            replace(SQLTranslator.TABLE_PREFIX + "supersession",               "Supersession");
-            replace(SQLTranslator.TABLE_PREFIX + "unitofmeasure",              "Unit of Measure");
-            replace(SQLTranslator.TABLE_PREFIX + "versionhistory",             "Version History");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "alias",                      "Alias");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "area",                       "Area");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "change",                     "Change");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "coordinateaxis",             "Coordinate
Axis");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "coordinateaxisname",         "Coordinate
Axis Name");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "coordoperation",             "Coordinate_Operation");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "coordoperationmethod",       "Coordinate_Operation
Method");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "coordoperationparam",        "Coordinate_Operation
Parameter");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "coordoperationparamusage",   "Coordinate_Operation
Parameter Usage");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "coordoperationparamvalue",   "Coordinate_Operation
Parameter Value");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "coordoperationpath",         "Coordinate_Operation
Path");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "coordinatereferencesystem",  "Coordinate
Reference System");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "coordinatesystem",           "Coordinate
System");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "datum",                      "Datum");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "deprecation",                "Deprecation");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "ellipsoid",                  "Ellipsoid");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "namingsystem",               "Naming
System");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "primemeridian",              "Prime
Meridian");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "supersession",               "Supersession");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "unitofmeasure",              "Unit
of Measure");
+            addReplacement(SQLTranslator.TABLE_PREFIX + "versionhistory",             "Version
History");
             prependNamespace(schema);
         }
     }
@@ -169,12 +174,41 @@ final class EPSGInstaller extends Script
     final void prependNamespace(final String schema) {
         modifyReplacements(new BiFunction<String,String,String>() {
             @Override public String apply(String key, String value) {
-                return schema + '.' + identifierQuote + value + identifierQuote;
+                return key.startsWith(SQLTranslator.TABLE_PREFIX) ?
+                        schema + '.' + identifierQuote + value + identifierQuote : value;
             }
         });
     }
 
     /**
+     * Invoked for each text found in a SQL statement. This method replaces {@code ''} by
{@code Null}.
+     * The intend is to consistently use the null value for meaning "no information", which
is not the
+     * same than "information is an empty string". This replacement is okay in this particular
case
+     * since there is no field in the EPSG database for which we really want an empty string.
+     *
+     * @param sql   The whole SQL statement.
+     * @param lower Index of the first character of the text in {@code sql}.
+     * @param upper Index after the last character of the text in {@code sql}.
+     */
+    @Override
+    protected void editText(final StringBuilder sql, final int lower, final int upper) {
+        final String replacement;
+        switch (upper - lower) {
+            default: {
+                return;
+            }
+            /*
+             * Replace '' by Null for every table.
+             */
+            case 2: {
+                replacement = "Null";
+                break;
+            }
+        }
+        sql.replace(lower, upper, replacement);
+    }
+
+    /**
      * Modifies the SQL statement before to execute it, or omit unsupported statements.
      *
      * @throws SQLException if an error occurred while executing the SQL statement.
@@ -222,10 +256,7 @@ final class EPSGInstaller extends Script
      */
     public void run(final Path scriptDirectory) throws SQLException, IOException {
         long time = System.nanoTime();
-        if (scriptDirectory == null) {
-            log(Messages.getResources(null).getLogRecord(Level.INFO, Messages.Keys.CreatingSchema_2,
-                    Constants.EPSG, getConnection().getMetaData().getURL()));
-        }
+        log(Messages.getResources(null).getLogRecord(Level.INFO, Messages.Keys.CreatingSchema_2,
Constants.EPSG, getURL()));
         int numScripts = SCRIPTS.length;
         if (!isGrantOnTableSupported) {
             numScripts--;
@@ -252,6 +283,17 @@ final class EPSGInstaller extends Script
     }
 
     /**
+     * Returns a simplified form of the URL (truncated before the first ? or ; character),
+     * for logging purpose only.
+     */
+    private String getURL() throws SQLException {
+        String url = getConnection().getMetaData().getURL();
+        int s1 = url.indexOf('?'); if (s1 < 0) s1 = url.length();
+        int s2 = url.indexOf(';'); if (s2 < 0) s2 = url.length();
+        return url.substring(0, Math.min(s1, s2));
+    }
+
+    /**
      * Logs a message reporting the failure to create EPSG database.
      */
     final void logFailure(final Locale locale) {

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/SQLTranslator.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/SQLTranslator.java?rev=1729284&r1=1729283&r2=1729284&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/SQLTranslator.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/SQLTranslator.java
[UTF-8] Mon Feb  8 22:37:31 2016
@@ -22,6 +22,7 @@ import java.util.Locale;
 import java.sql.DatabaseMetaData;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Types;
 import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.resources.Errors;
@@ -129,6 +130,15 @@ public class SQLTranslator {
     static final String TABLE_PREFIX = "epsg_";
 
     /**
+     * The columns that may be of {@code BOOLEAN} type instead of {@code SMALLINT}.
+     */
+    private static final String[] BOOLEAN_FIELDS = {
+        "SHOW_CRS",
+        "SHOW_OPERATION",
+        "DEPRECATED"
+    };
+
+    /**
      * The name of the catalog that contains the EPSG tables, or {@code null} or an empty
string.
      * <ul>
      *   <li>The {@code ""} value retrieves the EPSG schema without a catalog.</li>
@@ -184,6 +194,12 @@ public class SQLTranslator {
     private final String quote;
 
     /**
+     * {@code true} if the database uses the {@code BOOLEAN} type instead than {@code SMALLINT}
+     * for the {@code show_crs}, {@code show_operation} and all {@code deprecated} fields.
+     */
+    private boolean useBoolean;
+
+    /**
      * {@code true} if one of the {@link #SENTINEL} tables exist.
      * If {@code false}, then {@link EPSGInstaller} needs to be run.
      *
@@ -270,6 +286,22 @@ public class SQLTranslator {
         if (translateColumns) {
             accessToAnsi.put("ORDER", "coord_axis_order");
         }
+        /*
+         * Detect if the database uses boolean types where applicable.
+         * We arbitrarily use the Datum table as a representative value.
+         */
+        String deprecated = "DEPRECATED";
+        if (md.storesLowerCaseIdentifiers()) {
+            deprecated = deprecated.toLowerCase(Locale.US);
+        }
+        try (ResultSet result = md.getColumns(catalog, schema, null, deprecated)) {
+            while (result.next()) {
+                if (CharSequences.endsWith(result.getString("TABLE_NAME"), "Datum", true))
{
+                    useBoolean = result.getInt("DATA_TYPE") == Types.BOOLEAN;
+                    break;
+                }
+            }
+        }
     };
 
     /**
@@ -374,6 +406,43 @@ public class SQLTranslator {
                 }
             }
         }
-        return ansi.append(sql, end, sql.length()).toString();
+        ansi.append(sql, end, sql.length());
+        /*
+         * If the database use the BOOLEAN type instead of SMALLINT, replaces "deprecated=0'
by "deprecated=false".
+         */
+        if (useBoolean) {
+            int w = ansi.indexOf("WHERE");
+            if (w >= 0) {
+                w += 5;
+                for (final String field : BOOLEAN_FIELDS) {
+                    int p = ansi.indexOf(field, w);
+                    if (p >= 0) {
+                        p += field.length();
+                        if (!replaceIfEquals(ansi, p, "=0", "=FALSE") &&
+                            !replaceIfEquals(ansi, p, "<>0", "=TRUE"))
+                        {
+                            // Remove "ABS" in "ABS(DEPRECATED)" or "ABS(CO.DEPRECATED)".
+                            if ((p = ansi.lastIndexOf("(", p)) > w) {
+                                replaceIfEquals(ansi, p-3, "ABS", "");
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        return ansi.toString();
+    }
+
+    /**
+     * Replaces the text at the given position in the buffer if it is equals to the {@code
expected} text.
+     */
+    private static boolean replaceIfEquals(final StringBuilder ansi, final int pos,
+            final String expected, final String replacement)
+    {
+        if (CharSequences.regionMatches(ansi, pos, expected)) {
+            ansi.replace(pos, pos + expected.length(), replacement);
+            return true;
+        }
+        return false;
     }
 }

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java?rev=1729284&r1=1729283&r2=1729284&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java
[UTF-8] Mon Feb  8 22:37:31 2016
@@ -455,16 +455,16 @@ public final strictfp class EPSGFactoryT
         final List<CoordinateReferenceSystem> components = crs.getComponents();
         assertEquals("components.size()", 2, components.size());
         assertEpsgNameAndIdentifierEqual("NTF (Paris)",      4807, components.get(0));
-        assertEpsgNameAndIdentifierEqual("NGF IGN69 height", 5720, components.get(1));
+        assertEpsgNameAndIdentifierEqual("NGF-IGN69 height", 5720, components.get(1));
 
         assertAxisDirectionsEqual("(no EPSG code)", crs.getCoordinateSystem(),
                 AxisDirection.NORTH, AxisDirection.EAST, AxisDirection.UP);
 
         final GeographicBoundingBox bbox = CRS.getGeographicBoundingBox(crs);
         assertNotNull("No bounding box. Maybe an older EPSG database is used?", bbox);
-        assertEquals("southBoundLatitude", 42.25, bbox.getSouthBoundLatitude(), STRICT);
-        assertEquals("northBoundLatitude", 51.10, bbox.getNorthBoundLatitude(), STRICT);
-        assertEquals("westBoundLongitude", -5.20, bbox.getWestBoundLongitude(), STRICT);
+        assertEquals("southBoundLatitude", 42.33, bbox.getSouthBoundLatitude(), STRICT);
+        assertEquals("northBoundLatitude", 51.14, bbox.getNorthBoundLatitude(), STRICT);
+        assertEquals("westBoundLongitude", -4.87, bbox.getWestBoundLongitude(), STRICT);
         assertEquals("eastBoundLongitude",  8.23, bbox.getEastBoundLongitude(), STRICT);
 
         assertSame("CRS shall be cached", crs, factory.createCoordinateReferenceSystem("7400"));
@@ -590,7 +590,7 @@ public final strictfp class EPSGFactoryT
 
         final Set<String> ellipsoids = factory.getAuthorityCodes(Ellipsoid.class);
         assertFalse("Ellipsoid not found.",       ellipsoids.isEmpty());
-        assertTrue ("Check size() consistency.",  ellipsoids.size() >= 49);
+        assertTrue ("Check size() consistency.",  ellipsoids.size() >= 48);
         assertTrue ("Shall contain WGS84.",       ellipsoids.contains("7030"));
         assertTrue ("Shall contain GRS 1980.",    ellipsoids.contains("7019"));
 

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java?rev=1729284&r1=1729283&r2=1729284&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGInstallerTest.java
[UTF-8] Mon Feb  8 22:37:31 2016
@@ -17,22 +17,35 @@
 package org.apache.sis.referencing.factory.sql;
 
 import java.util.Map;
+import java.util.Set;
 import java.util.HashMap;
+import java.util.HashSet;
+import java.util.regex.Pattern;
+import javax.sql.DataSource;
 import java.sql.Connection;
+import java.sql.Statement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
-import javax.sql.DataSource;
 import org.opengis.util.FactoryException;
 import org.opengis.referencing.crs.GeographicCRS;
+import org.opengis.referencing.crs.ProjectedCRS;
 import org.apache.sis.referencing.CommonCRS;
-import org.apache.sis.internal.metadata.sql.TestDatabase;
+import org.apache.sis.internal.system.Loggers;
+import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.ComparisonMode;
 import org.apache.sis.util.Utilities;
+
+// Test dependencies
+import org.apache.sis.internal.metadata.sql.TestDatabase;
+import org.apache.sis.test.LoggingWatcher;
 import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
+import org.junit.Ignore;
+import org.junit.Rule;
 import org.junit.Test;
 
 import static org.junit.Assert.*;
+import static org.junit.Assume.*;
 
 // Branch-dependent imports
 import java.nio.file.Path;
@@ -54,13 +67,59 @@ import java.nio.file.Path;
 @DependsOn(EPSGFactoryTest.class)
 public final strictfp class EPSGInstallerTest extends TestCase {
     /**
+     * A JUnit rule for listening to log events emitted during execution of tests.
+     * This rule verifies that the log message contains the expected information.
+     *
+     * <p>This field is public because JUnit requires us to do so, but should be considered
+     * as an implementation details (it should have been a private field).</p>
+     */
+    @Rule
+    public final LoggingWatcher listener = new LoggingWatcher(Logging.getLogger(Loggers.CRS_FACTORY))
{
+        @Override protected void verifyMessage(final String message) {
+            log = message;      // Verified later by the tests in the enclosing class.
+        }
+    };
+
+    /**
+     * The logging message caught by the {@link #listener}.
+     */
+    private String log;
+
+    /**
+     * Tests the {@link EPSGInstaller#REPLACE_STATEMENT} pattern.
+     */
+    @Test
+    public void testReplacePattern() {
+        // Statement as in the EPSG scripts since EPSG version 7.06.
+        assertTrue(Pattern.matches(EPSGInstaller.REPLACE_STATEMENT,
+                "UPDATE epsg_datum\n" +
+                "SET datum_name = replace(datum_name, CHR(182), CHR(10))"));
+
+        // Statement as in the EPSG scripts prior to EPSG version 7.06.
+        assertTrue(Pattern.matches(EPSGInstaller.REPLACE_STATEMENT,
+                "UPDATE epsg_datum\n" +
+                "SET datum_name = replace(datum_name, CHAR(182), CHAR(10))"));
+
+        // Modified statement with MS-Access table name in a schema.
+        assertTrue(Pattern.matches(EPSGInstaller.REPLACE_STATEMENT,
+                "UPDATE epsg.\"Alias\"\n" +
+                "SET object_table_name = replace(object_table_name, CHR(182), CHR(10))"));
+
+        // Like above, but the table name contains a space.
+        assertTrue(Pattern.matches(EPSGInstaller.REPLACE_STATEMENT,
+                "UPDATE epsg.\"Coordinate Axis\"\n" +
+                "SET coord_axis_orientation = replace(coord_axis_orientation, CHR(182), CHR(10))"));
+    }
+
+    /**
      * Tests the creation of an EPSG database on Derby.
-     * This test is skipped if no Derby or JavaDB driver has been found.
+     * This test is skipped if Derby/JavaDB is not found, or if the SQL scripts are not found.
      *
      * @throws Exception if an error occurred while creating the database.
      */
     @Test
     public void testCreationOnDerby() throws Exception {
+        assumeTrue("Slow test skipped in non-extensive test mode.", RUN_EXTENSIVE_TESTS);
         final Path scripts = TestDatabase.directory("ExternalSources");
         final DataSource ds = TestDatabase.create("test");
         try {
@@ -68,22 +127,79 @@ public final strictfp class EPSGInstalle
         } finally {
             TestDatabase.drop(ds);
         }
+        assertTrue(log, log.contains("EPSG"));
+        assertTrue(log, log.contains("jdbc:derby:memory:test"));
+    }
+
+    /**
+     * Tests the creation of an EPSG database on HSQLDB.
+     * This test is skipped if the SQL scripts are not found.
+     *
+     * <p>This test is skipped by default because HSQLDB changes the {@code java.util.logging}
configuration,
+     * which causes failures in all Apache SIS tests that verify the logging messages after
execution of this
+     * test. This impact this {@code EPSGInstallerTest} class, but also other test classes.</p>
+     *
+     * @throws Exception if an error occurred while creating the database.
+     */
+    @Test
+    @Ignore("Skipped for protecting java.util.logging configuration against changes.")
+    public void testCreationOnHSQLDB() throws Exception {
+        final Path scripts = TestDatabase.directory("ExternalSources");
+        final DataSource ds = (DataSource) Class.forName("org.hsqldb.jdbc.JDBCDataSource").newInstance();
+        ds.getClass().getMethod("setURL", String.class).invoke(ds, "jdbc:hsqldb:mem:test");
+        try {
+            createAndTest(ds, scripts);
+        } finally {
+            try (Connection c = ds.getConnection(); Statement s = c.createStatement()) {
+                s.execute("SHUTDOWN");
+            }
+        }
+        assertTrue(log, log.contains("EPSG"));
+        assertTrue(log, log.contains("jdbc:hsqldb:mem:test"));
     }
 
     /**
-     * Requests the WGS84 coordinate reference system from the EPSG database at the given
source.
-     * It should trig the creation of the EPSG database.
+     * Requests the "WGS84" and the "WGS72 / UTM zone 15N" coordinate reference systems from
the EPSG database
+     * at the given {@code DataSource}. Those requests should trig the creation of the EPSG
database.
      */
-    private static void createAndTest(final DataSource ds, final Path scripts) throws SQLException,
FactoryException {
+    private void createAndTest(final DataSource ds, final Path scripts) throws SQLException,
FactoryException {
+        listener.maximumLogCount = 100;
         final Map<String,Object> properties = new HashMap<>();
         assertNull(properties.put("dataSource", ds));
         assertNull(properties.put("scriptDirectory", scripts));
         assertEquals("Should not contain EPSG tables before we created them.", 0, countCRSTables(ds));
+        assertEquals("Should not yet have logged anything at this point.", 100, listener.maximumLogCount);
         try (EPSGFactory factory = new EPSGFactory(properties)) {
+            /*
+             * Fetch the "WGS 84" coordinate reference system.
+             */
             final GeographicCRS crs = factory.createGeographicCRS("4326");
             assertTrue(Utilities.deepEquals(CommonCRS.WGS84.geographic(), crs, ComparisonMode.DEBUG));
+            /*
+             * Fetch the "WGS 72 / UTM zone 15" coordinate system.
+             * This implies the creation of a coordinate operation.
+             */
+            final ProjectedCRS p = factory.createProjectedCRS("EPSG:32215");
+            assertTrue(Utilities.deepEquals(CommonCRS.WGS72.UTM(1, -93), p, ComparisonMode.DEBUG));
+            /*
+             * Get the authority codes. We choose a type that implies an SQL statement
+             * with both "DEPRECATED" and "SHOW_CRS" conditions in their "WHERE" clause.
+             */
+            Set<String> codes = factory.getAuthorityCodes(GeographicCRS.class);
+            assertTrue("4979", codes.contains("4979"));     // A non-deprecated code.
+            assertTrue("4329", codes.contains("4329"));     // A deprecated code.
+            /*
+             * Following forces the authority factory to iterate over all codes.
+             * Since the iterator returns only non-deprecated codes, EPSG:4329
+             * should not be included. The intend is to verify that the fields
+             * of type BOOLEAN have been properly handled.
+             */
+            codes = new HashSet<>(codes);
+            assertTrue ("4979", codes.contains("4979"));
+            assertFalse("4329", codes.contains("4329"));
         }
         assertEquals("Should contain EPSG tables after we created them.", 1, countCRSTables(ds));
+        assertEquals("Should have logged a message about the database creation.", 99, listener.maximumLogCount);
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateOperationMethods.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateOperationMethods.java?rev=1729284&r1=1729283&r2=1729284&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateOperationMethods.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/report/CoordinateOperationMethods.java
[UTF-8] Mon Feb  8 22:37:31 2016
@@ -25,7 +25,6 @@ import java.util.Collections;
 import java.io.IOException;
 import org.opengis.util.FactoryException;
 import org.opengis.util.GenericName;
-import org.opengis.metadata.Identifier;
 import org.opengis.metadata.extent.GeographicBoundingBox;
 import org.opengis.parameter.*;
 import org.opengis.referencing.operation.*;
@@ -51,6 +50,7 @@ import org.apache.sis.util.Numbers;
 
 // Branch-dependent imports
 import org.apache.sis.internal.jdk8.JDK8;
+import org.opengis.metadata.Identifier;
 
 
 /**

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1729284&r1=1729283&r2=1729284&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] Mon Feb  8 22:37:31 2016
@@ -202,6 +202,7 @@ import org.junit.BeforeClass;
     org.apache.sis.referencing.factory.MultiAuthoritiesFactoryTest.class,
     org.apache.sis.referencing.factory.sql.EPSGFactoryTest.class,
     org.apache.sis.referencing.factory.sql.EPSGInstallerTest.class,
+    org.apache.sis.referencing.factory.sql.EPSGDataFormatterTest.class,
     org.apache.sis.referencing.EPSGFactoryFallbackTest.class,
     org.apache.sis.referencing.AuthorityFactoriesTest.class,
     org.apache.sis.referencing.CRSTest.class,




Mime
View raw message