sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1770881 - in /sis/branches/JDK8: core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/ core/sis-metadata/src/main/resources/org/ core/sis-metadata/src/main/resour...
Date Tue, 22 Nov 2016 20:08:04 GMT
Author: desruisseaux
Date: Tue Nov 22 20:08:04 2016
New Revision: 1770881

URL: http://svn.apache.org/viewvc?rev=1770881&view=rev
Log:
First draft of a SQL installation script for metadata about file formats.
This draft required changes in ScriptRunner and all classes that used it in order to avoid duplicating code.
More metadata will be added later.

Added:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/Installer.java   (with props)
    sis/branches/JDK8/core/sis-metadata/src/main/resources/org/
    sis/branches/JDK8/core/sis-metadata/src/main/resources/org/apache/
    sis/branches/JDK8/core/sis-metadata/src/main/resources/org/apache/sis/
    sis/branches/JDK8/core/sis-metadata/src/main/resources/org/apache/sis/metadata/
    sis/branches/JDK8/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/
    sis/branches/JDK8/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Create.sql   (with props)
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/ScriptRunnerTest.java   (with props)
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataSourceTest.java   (with props)
Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/ResultPool.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/TestDatabase.java
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.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/test/java/org/apache/sis/referencing/factory/sql/EPSGDataFormatter.java
    sis/branches/JDK8/ide-project/NetBeans/build.xml

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java?rev=1770881&r1=1770880&r2=1770881&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java [UTF-8] Tue Nov 22 20:08:04 2016
@@ -19,10 +19,13 @@ package org.apache.sis.internal.metadata
 import java.util.Map;
 import java.util.HashMap;
 import java.util.Locale;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
 import java.io.EOFException;
 import java.io.IOException;
 import java.io.BufferedReader;
 import java.io.LineNumberReader;
+import java.io.InputStreamReader;
 import java.io.StringReader;
 import java.sql.Statement;
 import java.sql.Connection;
@@ -50,7 +53,7 @@ import java.util.function.BiFunction;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.7
- * @version 0.7
+ * @version 0.8
  * @module
  */
 public class ScriptRunner implements AutoCloseable {
@@ -102,9 +105,9 @@ public class ScriptRunner implements Aut
 
     /**
      * A mapping of words to replace. The replacements are performed only for occurrences outside identifiers or texts.
-     * See {@link #replace(String, String)} for more explanation.
+     * See {@link #addReplacement(String, String)} for more explanation.
      *
-     * @see #replace(String, String)
+     * @see #addReplacement(String, String)
      */
     private final Map<String,String> replacements = new HashMap<>();
 
@@ -124,6 +127,12 @@ public class ScriptRunner implements Aut
 
     /**
      * {@code true} if the database supports enums.
+     * Example:
+     *
+     * {@preformat sql
+     *     CREATE TYPE metadata."CI_DateTypeCode" AS ENUM ('creation', 'publication');
+     *     CREATE CAST (VARCHAR AS metadata."CI_DateTypeCode") WITH INOUT AS ASSIGNMENT;
+     * }
      *
      * <p>Notes per database product:</p>
      * <ul>
@@ -131,6 +140,8 @@ public class ScriptRunner implements Aut
      *       we require PostgreSQL 8.4 because we need the {@code CAST … WITH INOUT} feature.</li>
      *   <li><b>Other databases:</b> assumed not supported.</li>
      * </ul>
+     *
+     * @see #statementsToSkip
      */
     protected final boolean isEnumTypeSupported;
 
@@ -147,16 +158,42 @@ public class ScriptRunner implements Aut
     /**
      * {@code true} if the database supports {@code "GRANT USAGE ON SCHEMA"} statements.
      * Read-only permissions are typically granted to {@link #PUBLIC}.
+     * Example:
+     *
+     * {@preformat sql
+     *     GRANT USAGE ON SCHEMA metadata TO PUBLIC;
+     * }
+     *
+     * @see #statementsToSkip
      */
     protected final boolean isGrantOnSchemaSupported;
 
     /**
      * {@code true} if the database supports {@code "GRANT SELECT ON TABLE"} statements.
      * Read-only permissions are typically granted to {@link #PUBLIC}.
+     * Example:
+     *
+     * {@preformat sql
+     *     GRANT SELECT ON TABLE epsg_coordinatereferencesystem TO PUBLIC;
+     * }
+     *
+     * @see #statementsToSkip
      */
     protected final boolean isGrantOnTableSupported;
 
     /**
+     * {@code true} if the database supports the {@code COMMENT} statement.
+     * Example:
+     *
+     * {@preformat sql
+     *     COMMENT ON SCHEMA metadata IS 'ISO 19115 metadata';
+     * }
+     *
+     * @see #statementsToSkip
+     */
+    protected final boolean isCommentSupported;
+
+    /**
      * {@code true} if the following instruction shall be executed
      * (assuming that the PostgreSQL {@code "plpgsql"} language is desired):
      *
@@ -189,6 +226,26 @@ public class ScriptRunner implements Aut
     private final Statement statement;
 
     /**
+     * If non-null, the SQL statements to skip (typically because not supported by the database).
+     * The matcher is built as an alternation of many regular expressions separated by the pipe symbol.
+     * The list of statements to skip depends on which {@code is*Supported} fields are set to {@code true}:
+     *
+     * <ul>
+     *   <li>{@link #isEnumTypeSupported} for {@code "CREATE TYPE …"} or {@code "CREATE CAST …"} statements.</li>
+     *   <li>{@link #isGrantOnSchemaSupported} for {@code "GRANT USAGE ON SCHEMA …"} statements.</li>
+     *   <li>{@link #isGrantOnTableSupported} for {@code "GRANT SELECT ON TABLE …"} statements.</li>
+     *   <li>{@link #isCommentSupported} for {@code "COMMENT ON …"} statements.</li>
+     * </ul>
+     */
+    private Matcher statementsToSkip;
+
+    /**
+     * The regular expression to use for building {@link #statementsToSkip}.
+     * At most one of {@code regexOfStmtToSkip} and {@code statementsToSkip} shall be non-null.
+     */
+    private StringBuilder regexOfStmtToSkip;
+
+    /**
      * Name of the SQL script under execution, or {@code null} if unknown.
      * This is used only for error reporting.
      */
@@ -221,8 +278,8 @@ public class ScriptRunner implements Aut
      *       {@code INSERT INTO} statement. Note that this causes {@link StackOverflowError} in some JDBC driver.</li>
      * </ul>
      *
-     * @param connection        The connection to the database.
-     * @param maxRowsPerInsert  Maximum number of rows per {@code "INSERT INTO"} statement.
+     * @param  connection        the connection to the database.
+     * @param  maxRowsPerInsert  maximum number of rows per {@code "INSERT INTO"} statement.
      * @throws SQLException if an error occurred while creating a SQL statement.
      */
     protected ScriptRunner(final Connection connection, int maxRowsPerInsert) throws SQLException {
@@ -241,6 +298,7 @@ public class ScriptRunner implements Aut
                 isGrantOnSchemaSupported = false;
                 isGrantOnTableSupported  = false;
                 isCreateLanguageRequired = false;
+                isCommentSupported       = false;
                 break;
             }
             case POSTGRESQL: {
@@ -249,6 +307,7 @@ public class ScriptRunner implements Aut
                 isGrantOnSchemaSupported = true;
                 isGrantOnTableSupported  = true;
                 isCreateLanguageRequired = (version < 9);
+                isCommentSupported       = true;
                 break;
             }
             case HSQL: {
@@ -256,6 +315,7 @@ public class ScriptRunner implements Aut
                 isGrantOnSchemaSupported = false;
                 isGrantOnTableSupported  = false;
                 isCreateLanguageRequired = false;
+                isCommentSupported       = false;
                 if (maxRowsPerInsert != 0) {
                     maxRowsPerInsert = 1;
                 }
@@ -273,12 +333,34 @@ public class ScriptRunner implements Aut
         }
         this.maxRowsPerInsert = maxRowsPerInsert;
         statement = connection.createStatement();
+        /*
+         * Now build the list of statements to skip, depending of which features are supported by the database.
+         * WARNING: do not use capturing group here, because some subclasses (e.g. EPSGInstaller) will use their
+         * own capturing groups. A non-capturing group is declared by "(?:A|B)" instead than a plain "(A|B)".
+         */
+        if (!isEnumTypeSupported) {
+            addStatementToSkip("CREATE\\s+(?:TYPE|CAST)\\s+.*");
+        }
+        if (!isGrantOnSchemaSupported || !isGrantOnTableSupported) {
+            addStatementToSkip("GRANT\\s+\\w+\\s+ON\\s+");
+            if (isGrantOnSchemaSupported) {
+                regexOfStmtToSkip.append("TABLE");
+            } else if (isGrantOnTableSupported) {
+                regexOfStmtToSkip.append("SCHEMA");
+            } else {
+                regexOfStmtToSkip.append("(?:TABLE|SCHEMA)");
+            }
+            regexOfStmtToSkip.append("\\s+.*");
+        }
+        if (!isCommentSupported) {
+            addStatementToSkip("COMMENT\\s+ON\\s+.*");
+        }
     }
 
     /**
      * Returns the connection to the database.
      *
-     * @return The connection.
+     * @return the connection.
      * @throws SQLException if the connection can not be obtained.
      */
     protected final Connection getConnection() throws SQLException {
@@ -286,6 +368,31 @@ public class ScriptRunner implements Aut
     }
 
     /**
+     * Adds a statement to skip. By default {@code ScriptRunner} ignores the following statements:
+     *
+     * <ul>
+     *   <li>{@code "CREATE TYPE …"} or {@code "CREATE CAST …"} if {@link #isEnumTypeSupported} is {@code false}.</li>
+     *   <li>{@code "GRANT USAGE ON SCHEMA …"} if {@link #isGrantOnSchemaSupported} is {@code false}.</li>
+     *   <li>{@code "GRANT SELECT ON TABLE …"} if {@link #isGrantOnTableSupported} is {@code false}.</li>
+     *   <li>{@code "COMMENT ON …"} if {@link #isCommentSupported} is {@code false}.</li>
+     * </ul>
+     *
+     * This method can be invoked for ignoring some additional statements.
+     *
+     * @param  regex  regular expression of the statement to ignore.
+     */
+    protected final void addStatementToSkip(final String regex) {
+        if (statementsToSkip != null) {
+            throw new IllegalStateException();
+        }
+        if (regexOfStmtToSkip == null) {
+            regexOfStmtToSkip = new StringBuilder(regex);
+        } else {
+            regexOfStmtToSkip.append('|').append(regex);
+        }
+    }
+
+    /**
      * Declares that a word in the SQL script needs to be replaced by the given word.
      * The replacement is performed only for occurrences outside identifiers or texts.
      *
@@ -300,8 +407,8 @@ public class ScriptRunner implements Aut
      * words, then in addition to the {@code "CREATE TABLE"} entry this {@code replacements} map shall also contain
      * a {@code "CREATE"} entry associated with the {@link #MORE_WORDS} value.
      *
-     * @param inScript The word in the script which need to be replaced.
-     * @param replacement The word to use instead.
+     * @param  inScript     the word in the script which need to be replaced.
+     * @param  replacement  the word to use instead.
      */
     protected final void addReplacement(final String inScript, final String replacement) {
         if (replacements.put(inScript, replacement) != null) {
@@ -313,18 +420,18 @@ public class ScriptRunner implements Aut
      * 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.
+     * @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 replacements.getOrDefault(inScript, inScript);
     }
 
     /**
-     * For every entries in the replacements map, replace the entry value by the value returned by
+     * For every entries in the replacements map, replaces the entry value by the value returned by
      * {@code function(key, value)}.
      *
-     * @param function The function that modify the replacement mapping.
+     * @param function  the function that modify the replacement mapping.
      */
     protected final void modifyReplacements(final BiFunction<String,String,String> function) {
         replacements.replaceAll(function);
@@ -334,8 +441,8 @@ public class ScriptRunner implements Aut
      * Runs the given SQL script.
      * Lines are read and grouped up to the terminal {@value #END_OF_STATEMENT} character, then sent to the database.
      *
-     * @param  statement The SQL statements to execute.
-     * @return The number of rows added or modified as a result of the statement execution.
+     * @param  statement  the SQL statements to execute.
+     * @return the number of rows added or modified as a result of the statement execution.
      * @throws IOException if an error occurred while reading the input (should never happen).
      * @throws SQLException if an error occurred while executing a SQL statement.
      */
@@ -344,12 +451,28 @@ public class ScriptRunner implements Aut
     }
 
     /**
+     * Runs the SQL script of the given name in the same package than the given class.
+     * The script is presumed encoded in UTF-8.
+     *
+     * @param  loader    the class to use for loading the SQL script.
+     * @param  filename  the SQL script filename, relative to the {@code loader} package.
+     * @return the number of rows added or modified as a result of the statement execution.
+     * @throws IOException if an error occurred while reading the input (should never happen).
+     * @throws SQLException if an error occurred while executing a SQL statement.
+     */
+    public final int run(final Class<?> loader, final String filename) throws IOException, SQLException {
+        try (final BufferedReader in = new LineNumberReader(new InputStreamReader(loader.getResourceAsStream(filename), "UTF-8"))) {
+            return run(filename, in);
+        }
+    }
+
+    /**
      * Runs the script from the given reader. Lines are read and grouped up to the
      * terminal {@value #END_OF_STATEMENT} character, then sent to the database.
      *
-     * @param  filename Name of the SQL script being executed. This is used only for error reporting.
-     * @param  in The stream to read. It is caller's responsibility to close this reader.
-     * @return The number of rows added or modified as a result of the script execution.
+     * @param  filename  name of the SQL script being executed. This is used only for error reporting.
+     * @param  in        the stream to read. It is caller's responsibility to close this reader.
+     * @return the number of rows added or modified as a result of the script execution.
      * @throws IOException if an error occurred while reading the input.
      * @throws SQLException if an error occurred while executing a SQL statement.
      */
@@ -516,18 +639,41 @@ parseLine:  while (pos < length) {
      * 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}.
+     * @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) {
     }
 
     /**
+     * Returns {@code true} if the given SQL statements is supported by the database engine,
+     * or {@code false} if this statement should be ignored. The default implementation checks
+     * if the given query matches the regular expressions given to {@link #addStatementToSkip(String)}.
+     *
+     * <p>This method is only a hint; a value of {@code true} is not a guaranteed that the given
+     * SQL statement is valid.</p>
+     *
+     * @param  sql  the SQL statement to verify.
+     * @return whether the given SQL statement is supported by the database engine.
+     */
+    protected boolean isSupported(final CharSequence sql) {
+        if (regexOfStmtToSkip == null) {
+            return !statementsToSkip.reset(sql).matches();
+        } else {
+            // We do not use Pattern.CASE_INSENTITIVE for performance reasons.
+            statementsToSkip = Pattern.compile(regexOfStmtToSkip.toString(), Pattern.DOTALL).matcher(sql);
+            regexOfStmtToSkip = null;
+            return !statementsToSkip.matches();
+        }
+    }
+
+    /**
      * Executes the given SQL statement.
      * This method performs the following choices:
      *
      * <ul>
+     *   <li>If {@link #isSupported(StringBuilder)} returns {@code false}, then this method does nothing.</li>
      *   <li>If the {@code maxRowsPerInsert} argument given at construction time was zero,
      *       then this method skips {@code "INSERT INTO"} statements but executes all other.</li>
      *   <li>Otherwise this method executes the given statement with the following modification:
@@ -539,12 +685,15 @@ parseLine:  while (pos < length) {
      * Subclasses that override this method can freely edit the {@link StringBuilder} content before
      * to invoke this method.
      *
-     * @param  sql The SQL statement to execute.
-     * @return The number of rows added or modified as a result of the statement execution.
+     * @param  sql  the SQL statement to execute.
+     * @return the number of rows added or modified as a result of the statement execution.
      * @throws SQLException if an error occurred while executing the SQL statement.
      * @throws IOException if an I/O operation was required and failed.
      */
     protected int execute(final StringBuilder sql) throws SQLException, IOException {
+        if (!isSupported(sql)) {
+            return 0;
+        }
         String subSQL = currentSQL = CharSequences.trimWhitespaces(sql).toString();
         int count = 0;
         /*
@@ -599,7 +748,7 @@ parseLine:  while (pos < length) {
      * Closes the statement used by this runner. Note that this method does not close the connection
      * given to the constructor; this connection still needs to be closed explicitly by the caller.
      *
-     * @throws SQLException If an error occurred while closing the statement.
+     * @throws SQLException if an error occurred while closing the statement.
      */
     @Override
     public void close() throws SQLException {
@@ -635,7 +784,7 @@ parseLine:  while (pos < length) {
      * current position in the script being executed, and the SQL statement. This method may be invoked after a
      * {@link SQLException} occurred in order to determine the line in the SQL script that caused the error.
      *
-     * @return The current position in the script being executed.
+     * @return the current position in the script being executed.
      */
     @Debug
     @Override

Added: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/Installer.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/Installer.java?rev=1770881&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/Installer.java (added)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/Installer.java [UTF-8] Tue Nov 22 20:08:04 2016
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.metadata.sql;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+import org.apache.sis.internal.metadata.sql.ScriptRunner;
+import org.apache.sis.util.CharSequences;
+import org.apache.sis.util.StringBuilders;
+
+
+/**
+ * Execute the installation scripts for the "metadata" schema in the "SpatialMetadata" database.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.8
+ * @version 0.8
+ * @module
+ */
+final class Installer extends ScriptRunner {
+    /**
+     * Creates a new installer for the metadata database.
+     *
+     * @param  connection  connection to the metadata database.
+     * @throws SQLException if an error occurred while executing a SQL statement.
+     */
+    Installer(final Connection connection) throws SQLException {
+        super(connection, 100);
+    }
+
+    /**
+     * Runs the installation script.
+     */
+    public void run() throws IOException, SQLException {
+        run(Installer.class, "Create.sql");
+    }
+
+    /**
+     * Invoked for each line of the SQL installation script to execute.
+     * If the database does not support enumerations, replace enumeration columns by {@code VARCHAR}.
+     *
+     * @todo The hard-coded checks performed in this method should disappear after we replaced the
+     *       "CREATE TABLE" statement by usage of {@code MetadataWriter}.
+     */
+    @Override
+    protected int execute(final StringBuilder sql) throws SQLException, IOException {
+        if (!isEnumTypeSupported && CharSequences.startsWith(sql, "CREATE TABLE", true)) {
+            StringBuilders.replace(sql, "metadata.\"CI_RoleCode\"", "VARCHAR(20)");
+            StringBuilders.replace(sql, "metadata.\"CI_DateTypeCode\"", "VARCHAR(20)");
+            StringBuilders.replace(sql, "metadata.\"CI_PresentationFormCode\"", "VARCHAR(20)");
+        }
+        return super.execute(sql);
+    }
+}

Propchange: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/Installer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/Installer.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/ResultPool.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/ResultPool.java?rev=1770881&r1=1770880&r2=1770881&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/ResultPool.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/ResultPool.java [UTF-8] Tue Nov 22 20:08:04 2016
@@ -153,6 +153,9 @@ final class ResultPool {
      * to ensure that the connection is used by only one thread at time. This is also necessary
      * for preventing the background thread to close the connection too early.
      *
+     * <p>Callers shall not close the connection returned by this method.
+     * The connection will be closed by {@link #closeExpired()} after an arbitrary timeout.</p>
+     *
      * @return the connection to the database.
      * @throws SQLException if an error occurred while fetching the connection.
      */
@@ -161,7 +164,8 @@ final class ResultPool {
         Connection c = connection;
         if (c == null) {
             connection = c = dataSource.getConnection();
-            Logging.log(MetadataSource.class, "lookup", Initializer.connected(connection.getMetaData()));
+            Logging.log(MetadataSource.class, "lookup", Initializer.connected(c.getMetaData()));
+            scheduleCloseTask();
         }
         return c;
     }
@@ -222,11 +226,18 @@ final class ResultPool {
         }
         cache[preferredIndex] = statement;
         statement.expireTime = System.nanoTime() + TIMEOUT;
+        scheduleCloseTask();
+        return preferredIndex;
+    }
+
+    /**
+     * Schedules a task for closing the statements and the connection, if no such task is scheduled.
+     */
+    private void scheduleCloseTask() {
         if (!isCloseScheduled) {
             DelayedExecutor.schedule(new CloseTask(System.nanoTime() + (TIMEOUT + EXTRA_DELAY)));
             isCloseScheduled = true;
         }
-        return preferredIndex;
     }
 
     /**

Added: sis/branches/JDK8/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Create.sql
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Create.sql?rev=1770881&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Create.sql (added)
+++ sis/branches/JDK8/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Create.sql Tue Nov 22 20:08:04 2016
@@ -0,0 +1,105 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+
+CREATE SCHEMA metadata;
+GRANT USAGE ON SCHEMA metadata TO PUBLIC;
+COMMENT ON SCHEMA metadata IS 'ISO 19115 metadata';
+
+
+--
+-- CodeLists are represented as enumeration on PostgreSQL.
+-- Those declarations will be omitted on databases that do
+-- no support enumerations; VARCHAR is used instead.
+--
+CREATE TYPE metadata."CI_PresentationFormCode" AS ENUM (
+  'documentDigital', 'documentHardcopy',
+  'imageDigital',    'imageHardcopy',
+  'mapDigital',      'mapHardcopy',
+  'modelDigital',    'modelHardcopy',
+  'profileDigital',  'profileHardcopy',
+  'tableDigital',    'tableHardcopy',
+  'videoDigital',    'videoHardcopy');
+
+CREATE TYPE metadata."CI_RoleCode" AS ENUM (
+  'resourceProvider', 'custodian', 'owner', 'user', 'distributor', 'originator', 'pointOfContact',
+  'principalInvestigator', 'processor', 'publisher', 'author', 'sponsor', 'coAuthor', 'collaborator',
+  'editor', 'mediator', 'rightsHolder', 'contributor', 'funder', 'stakeholder');
+
+CREATE TYPE metadata."CI_DateTypeCode" AS ENUM (
+  'creation', 'publication', 'revision', 'expiry', 'lastUpdate', 'lastRevision', 'nextUpdate',
+  'unavailable', 'inForce', 'adopted', 'deprecated', 'superseded', 'validityBegins', 'validityExpires',
+  'released', 'distribution');
+
+CREATE CAST (VARCHAR AS metadata."CI_PresentationFormCode") WITH INOUT AS ASSIGNMENT;
+CREATE CAST (VARCHAR AS metadata."CI_RoleCode")             WITH INOUT AS ASSIGNMENT;
+CREATE CAST (VARCHAR AS metadata."CI_DateTypeCode")         WITH INOUT AS ASSIGNMENT;
+
+
+--
+-- This script creates some tables needed for SIS pre-defined metadata.
+-- We do not need to create all tables or all columns in tables here.
+-- Missing tables and columns will be added on-the-fly by SIS as needed.
+--
+-- VARCHAR(10) are for primary keys or foreigner keys.
+-- VARCHAR(80) are for character sequences.
+--
+CREATE TABLE metadata."MD_Identifier" (
+  ID                            VARCHAR(10) NOT NULL PRIMARY KEY,
+  "authority"                   VARCHAR(10),
+  "code"                        VARCHAR(80),
+  "codeSpace"                   VARCHAR(80),
+  "version"                     VARCHAR(80));
+
+CREATE TABLE metadata."CI_Party" (
+  ID                            VARCHAR(10) NOT NULL PRIMARY KEY,
+  "name"                        VARCHAR(80));
+
+CREATE TABLE metadata."CI_Responsibility" (
+  ID                            VARCHAR(10) NOT NULL PRIMARY KEY,
+  "role"                        metadata."CI_RoleCode",
+  "party"                       VARCHAR(10) REFERENCES metadata."CI_Party" (ID) ON UPDATE RESTRICT ON DELETE RESTRICT);
+
+CREATE TABLE metadata."CI_Date" (
+  ID                            VARCHAR(10) NOT NULL PRIMARY KEY,
+  "date"                        TIMESTAMP,
+  "dateType"                    metadata."CI_DateTypeCode");
+
+CREATE TABLE metadata."CI_Citation" (
+  ID                            VARCHAR(10) NOT NULL PRIMARY KEY,
+  "title"                       VARCHAR(80),
+  "alternateTitle"              VARCHAR(80),
+  "date"                        VARCHAR(10) REFERENCES metadata."CI_Date" (ID) ON UPDATE RESTRICT ON DELETE RESTRICT,
+  "edition"                     VARCHAR(80),
+  "editionDate"                 TIMESTAMP,
+  "identifier"                  VARCHAR(10) REFERENCES metadata."MD_Identifier"     (ID) ON UPDATE RESTRICT ON DELETE RESTRICT,
+  "citedResponsibleParty"       VARCHAR(10) REFERENCES metadata."CI_Responsibility" (ID) ON UPDATE RESTRICT ON DELETE RESTRICT,
+  "presentationForm"            metadata."CI_PresentationFormCode");
+
+ALTER TABLE metadata."MD_Identifier" ADD CONSTRAINT fk_identifier_citation
+FOREIGN KEY ("authority") REFERENCES metadata."CI_Citation" (ID) ON UPDATE RESTRICT ON DELETE RESTRICT;
+
+CREATE TABLE metadata."MD_Format" (
+  ID                            VARCHAR(10) NOT NULL PRIMARY KEY,
+  "formatSpecificationCitation" VARCHAR(10) REFERENCES metadata."CI_Citation" (ID) ON UPDATE RESTRICT ON DELETE RESTRICT,
+  "amendmentNumber"             VARCHAR(80),
+  "fileDecompressionTechnique"  VARCHAR(80));
+
+
+--
+-- Metadata about file formats.
+--
+INSERT INTO metadata."CI_Citation" (ID, "alternateTitle", "title") VALUES
+  ('GeoTIFF', 'GeoTIFF', 'GeoTIFF Coverage Encoding Profile'),
+  ('NetCDF',  'NetCDF',  'NetCDF Classic and 64-bit Offset Format'),
+  ('PNG',     'PNG',     'PNG (Portable Network Graphics) Specification'),
+  ('CSV',     'CSV',     'Common Format and MIME Type for Comma-Separated Values (CSV) Files'),
+  ('CSV-MF',  'CSV',     'OGC Moving Features Encoding Extension: Simple Comma-Separated Values (CSV)');
+
+INSERT INTO metadata."MD_Format" (ID, "formatSpecificationCitation") VALUES
+  ('GeoTIFF', 'GeoTIFF'),
+  ('NetCDF',  'NetCDF'),
+  ('PNG',     'PNG'),
+  ('CSV',     'CSV'),
+  ('CSV-MF',  'CSV-MF');

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

Propchange: sis/branches/JDK8/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Create.sql
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/ScriptRunnerTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/ScriptRunnerTest.java?rev=1770881&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/ScriptRunnerTest.java (added)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/ScriptRunnerTest.java [UTF-8] Tue Nov 22 20:08:04 2016
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.metadata.sql;
+
+import java.sql.Connection;
+import javax.sql.DataSource;
+import org.apache.sis.test.TestCase;
+import org.apache.sis.test.TestStep;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Tests {@link ScriptRunner}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.8
+ * @version 0.8
+ * @module
+ */
+public final strictfp class ScriptRunnerTest extends TestCase {
+    /**
+     * Tests {@link ScriptRunner} on an in-memory Derby database.
+     * This method delegates its work to all other methods in this class that expect a {@link ScriptRunner} argument.
+     *
+     * @throws Exception if an error occurred while executing the script runner.
+     */
+    @Test
+    public void testOnDerby() throws Exception {
+        final DataSource ds = TestDatabase.create("temporary");
+        try (final Connection c = ds.getConnection()) {
+            final ScriptRunner sr = new ScriptRunner(c, 3);
+            testSupportedFlags(sr);
+            testRegularExpressions(sr);
+        } finally {
+            TestDatabase.drop(ds);
+        }
+    }
+
+    /**
+     * Verifies the values of {@code is*Supported} flags in the given script runner.
+     *
+     * @param  sr  the script runner for which to verify flag values.
+     */
+    @TestStep
+    public static void testSupportedFlags(final ScriptRunner sr) {
+        assertFalse("isCatalogSupported",       sr.isCatalogSupported);
+        assertTrue ("isSchemaSupported",        sr.isSchemaSupported);
+        assertFalse("isGrantOnSchemaSupported", sr.isGrantOnSchemaSupported);
+        assertFalse("isGrantOnTableSupported",  sr.isGrantOnTableSupported);
+        assertFalse("isEnumTypeSupported",      sr.isEnumTypeSupported);
+        assertFalse("isCommentSupported",       sr.isCommentSupported);
+    }
+
+    /**
+     * Verifies the regular expressions used by the script runner.
+     * This method tests the values returned by {@link ScriptRunner#isSupported(StringBuilder)}
+     *
+     * @param  sr  the script runner to use for testing regular expressions.
+     */
+    @TestStep
+    public static void testRegularExpressions(final ScriptRunner sr) {
+        assertFalse(sr.isSupported("CREATE TYPE CI_DateTypeCode AS ENUM ('creation', 'publication')"));
+        assertFalse(sr.isSupported("CREATE CAST (VARCHAR AS CI_DateTypeCode) WITH INOUT AS ASSIGNMENT"));
+        assertTrue (sr.isSupported("CREATE TABLE CI_Citation (…)"));
+        assertFalse(sr.isSupported("GRANT USAGE ON SCHEMA metadata TO PUBLIC"));
+        assertFalse(sr.isSupported("GRANT SELECT ON TABLE epsg_coordinatereferencesystem TO PUBLIC"));
+        assertFalse(sr.isSupported("COMMENT ON SCHEMA metadata IS 'ISO 19115 metadata'"));
+    }
+}

Propchange: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/ScriptRunnerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/ScriptRunnerTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/TestDatabase.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/TestDatabase.java?rev=1770881&r1=1770880&r2=1770881&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/TestDatabase.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/TestDatabase.java [UTF-8] Tue Nov 22 20:08:04 2016
@@ -59,8 +59,8 @@ public final strictfp class TestDatabase
      * Returns the path to the directory of the given name in {@code $SIS_DATA/Databases}.
      * If the directory is not found, then the test will be interrupted by an {@code org.junit.Assume} statement.
      *
-     * @param name The name of the sub-directory.
-     * @return The path to the given sub-directory.
+     * @param  name  the name of the sub-directory.
+     * @return the path to the given sub-directory.
      */
     public static Path directory(final String name) {
         Path dir = DataDirectory.DATABASES.getDirectory();
@@ -74,8 +74,8 @@ public final strictfp class TestDatabase
      * Creates a Derby database in memory. If no Derby or JavaDB driver is not found,
      * then the test will be interrupted by an {@code org.junit.Assume} statement.
      *
-     * @param  name The database name (without {@code "memory:"} prefix).
-     * @return The data source.
+     * @param  name  the database name (without {@code "memory:"} prefix).
+     * @return the data source.
      * @throws Exception if an error occurred while creating the database.
      */
     public static DataSource create(final String name) throws Exception {
@@ -96,7 +96,7 @@ public final strictfp class TestDatabase
     /**
      * Drops an in-memory Derby database after usage.
      *
-     * @param  ds The data source created by {@link #create(String)}.
+     * @param  ds  the data source created by {@link #create(String)}.
      * @throws Exception if an error occurred while dropping the database.
      */
     public static void drop(final DataSource ds) throws Exception {

Added: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataSourceTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataSourceTest.java?rev=1770881&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataSourceTest.java (added)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataSourceTest.java [UTF-8] Tue Nov 22 20:08:04 2016
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.metadata.sql;
+
+import java.sql.Connection;
+import javax.sql.DataSource;
+import org.apache.sis.internal.metadata.sql.TestDatabase;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+
+/**
+ * Tests {@link MetadataSource}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.8
+ * @version 0.8
+ * @module
+ */
+@DependsOn(org.apache.sis.internal.metadata.sql.ScriptRunnerTest.class)
+public final strictfp class MetadataSourceTest extends TestCase {
+    /**
+     * Tests installation.
+     *
+     * @throws Exception if an error occurred while executing the installation script.
+     */
+    @Test
+    public void testInstall() throws Exception {
+        final DataSource ds = TestDatabase.create("metadata");
+        try (final Connection c = ds.getConnection()) {
+            final Installer install = new Installer(c);
+            install.run();
+        } finally {
+            TestDatabase.drop(ds);
+        }
+    }
+}

Propchange: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataSourceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataSourceTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java?rev=1770881&r1=1770880&r2=1770881&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java [UTF-8] Tue Nov 22 20:08:04 2016
@@ -102,7 +102,9 @@ import org.junit.BeforeClass;
     org.apache.sis.io.wkt.ElementTest.class,
 
     org.apache.sis.internal.metadata.sql.SQLUtilitiesTest.class,
-    org.apache.sis.internal.metadata.sql.TypeMapperTest.class
+    org.apache.sis.internal.metadata.sql.TypeMapperTest.class,
+    org.apache.sis.internal.metadata.sql.ScriptRunnerTest.class,
+    org.apache.sis.metadata.sql.MetadataSourceTest.class
 })
 public final strictfp class MetadataTestSuite extends TestSuite {
     /**

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=1770881&r1=1770880&r2=1770881&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] Tue Nov 22 20:08:04 2016
@@ -25,15 +25,12 @@ import java.util.StringTokenizer;
 import java.util.concurrent.TimeUnit;
 import java.util.logging.Level;
 import java.util.logging.LogRecord;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 import java.io.BufferedReader;
 import org.apache.sis.util.StringBuilders;
 import org.apache.sis.internal.metadata.sql.ScriptRunner;
 import org.apache.sis.internal.metadata.sql.SQLUtilities;
 import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.internal.util.Fallback;
-import org.apache.sis.util.CharSequences;
 import org.apache.sis.util.Exceptions;
 import org.apache.sis.util.resources.Messages;
 import org.apache.sis.util.logging.PerformanceLevel;
@@ -61,9 +58,11 @@ final class EPSGInstaller extends Script
      *     UPDATE epsg_datum
      *     SET datum_name = replace(datum_name, CHAR(182), CHAR(10));
      * }
+     *
+     * Note: this regular expression use a capturing group.
      */
     static final String REPLACE_STATEMENT =
-            "\\s*UPDATE\\s+[\\w\\.\" ]+\\s+SET\\s+(\\w+)\\s*=\\s*replace\\s*\\(\\s*\\1\\W+.*";
+            "UPDATE\\s+[\\w\\.\" ]+\\s+SET\\s+(\\w+)\\s*=\\s*replace\\s*\\(\\s*\\1\\W+.*";
 
     /**
      * {@code true} if the Pilcrow character (¶ - decimal code 182) should be replaced by Line Feed
@@ -73,12 +72,6 @@ final class EPSGInstaller extends Script
     private final boolean replacePilcrow;
 
     /**
-     * Non-null if there is SQL statements to skip. This is the case of {@code UPDATE … SET x = REPLACE(x, …)}
-     * functions, since Derby does not supports the {@code REPLACE} function.
-     */
-    private final Matcher statementToSkip;
-
-    /**
      * Creates a new runner which will execute the statements using the given connection.
      * The encoding is {@code "ISO-8859-1"}, which is the encoding used for the files provided by EPSG.
      *
@@ -97,11 +90,15 @@ final class EPSGInstaller extends Script
                 break;
             }
         }
-        if (isReplaceSupported) {
-            statementToSkip = null;
-        } else {
-            statementToSkip = Pattern.compile(REPLACE_STATEMENT, Pattern.CASE_INSENSITIVE).matcher("");
+        if (!isReplaceSupported) {
+            addStatementToSkip(REPLACE_STATEMENT);
         }
+        /*
+         * The SQL scripts provided by EPSG contains some lines with only a "COMMIT" statement.
+         * This statement is not understood by all databases, and interferes with our calls to
+         * setAutoCommit(false) ... commit() / rollback().
+         */
+        addStatementToSkip("COMMIT");
         replacePilcrow = false;         // Never supported for now.
     }
 
@@ -210,26 +207,6 @@ final class EPSGInstaller extends Script
      */
     @Override
     protected int execute(final StringBuilder sql) throws SQLException, IOException {
-        /*
-         * The SQL scripts provided by EPSG contains some lines with only a "COMMIT" statement.
-         * This statement is not understood by all databases, and interferes with our calls to
-         * setAutoCommit(false) ... commit() / rollback().
-         */
-        if (CharSequences.equalsIgnoreCase(sql, "COMMIT")) {
-            return 0;
-        }
-        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;
-        }
         if (replacePilcrow) {
             StringBuilders.replace(sql, "¶", "\n");
         }

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=1770881&r1=1770880&r2=1770881&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] Tue Nov 22 20:08:04 2016
@@ -115,7 +115,7 @@ import java.nio.charset.StandardCharsets
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @since   0.7
- * @version 0.7
+ * @version 0.8
  * @module
  */
 public final class EPSGDataFormatter extends ScriptRunner {
@@ -190,7 +190,7 @@ public final class EPSGDataFormatter ext
     /**
      * Creates a new instance.
      *
-     * @param  c A dummy connection. Will be used for fetching metadata.
+     * @param  c  a dummy connection. Will be used for fetching metadata.
      * @throws SQLException if an error occurred while fetching metadata.
      */
     private EPSGDataFormatter(final Connection c) throws SQLException {
@@ -223,7 +223,7 @@ public final class EPSGDataFormatter ext
     /**
      * Returns {@code true} if the given line should be omitted from the script.
      *
-     * @param  line The line, without trailing {@code ';'}.
+     * @param  line  the line, without trailing {@code ';'}.
      * @return {@code true} if the line should be omitted.
      */
     private static boolean omit(final String line) {
@@ -234,9 +234,9 @@ public final class EPSGDataFormatter ext
     /**
      * Compacts the given file.
      *
-     * @param  inputFile    The input file where to read the SQL statements to compact.
-     * @param  outputFile   The output file where to write the compacted SQL statements.
-     * @param  encoding     The character encoding for both input and output files.
+     * @param  inputFile    the input file where to read the SQL statements to compact.
+     * @param  outputFile   the output file where to write the compacted SQL statements.
+     * @param  encoding     the character encoding for both input and output files.
      * @throws IOException  if an I/O operation failed.
      * @throws SQLException should never happen.
      */
@@ -276,11 +276,23 @@ public final class EPSGDataFormatter ext
     }
 
     /**
+     * Makes sure that {@link #execute(StringBuilder)} is invoked for every line. Whether the SQL statement
+     * is supported or not is irrelevant for this method since we do not know yet what will be the database
+     * engine; we just copy the SQL statements in a file without executing them.
+     *
+     * @return {@code true}.
+     */
+    @Override
+    protected boolean isSupported(final CharSequence sql) {
+        return true;
+    }
+
+    /**
      * "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.
      *
-     * @param  sql The SQL statement to compact.
-     * @return The number of rows added.
+     * @param  sql  the SQL statement to compact.
+     * @return the number of rows added.
      * @throws IOException if an I/O operation failed.
      * @throws SQLException if a syntax error happens.
      */
@@ -536,7 +548,7 @@ public final class EPSGDataFormatter ext
      * <p><b>Note:</b> current version does not use codepoint API
      * on the assumption that it is not needed for EPSG's SQL files.</p>
      *
-     * @param buffer The string in which to perform the removal.
+     * @param  buffer  the string in which to perform the removal.
      */
     static void removeLF(final StringBuilder buffer) {
         int i = buffer.length();

Modified: sis/branches/JDK8/ide-project/NetBeans/build.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/ide-project/NetBeans/build.xml?rev=1770881&r1=1770880&r2=1770881&view=diff
==============================================================================
--- sis/branches/JDK8/ide-project/NetBeans/build.xml (original)
+++ sis/branches/JDK8/ide-project/NetBeans/build.xml Tue Nov 22 20:08:04 2016
@@ -58,6 +58,9 @@
       <fileset dir="${project.root}/core/sis-utility/src/main/resources">
         <include name="**/*.properties"/>
       </fileset>
+      <fileset dir="${project.root}/core/sis-metadata/src/main/resources">
+        <include name="**/*.sql"/>
+      </fileset>
       <fileset dir="${project.root}/core/sis-referencing/src/main/resources">
         <include name="**/*.sql"/>
       </fileset>



Mime
View raw message