sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1729801 - in /sis/branches/JDK7: ./ core/ core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ core/sis-referencing/ core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/ core/sis-referencing/src/main/...
Date Thu, 11 Feb 2016 10:59:46 GMT
Author: desruisseaux
Date: Thu Feb 11 10:59:45 2016
New Revision: 1729801

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

Added:
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/InstallationScriptProvider.java
      - copied unchanged from r1729794, sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/InstallationScriptProvider.java
    sis/branches/JDK7/core/sis-referencing/src/main/resources/org/
      - copied from r1729794, sis/branches/JDK8/core/sis-referencing/src/main/resources/org/
Modified:
    sis/branches/JDK7/   (props changed)
    sis/branches/JDK7/core/pom.xml
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ScriptRunner.java
    sis/branches/JDK7/core/sis-referencing/pom.xml
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGFactory.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/package-info.java
    sis/branches/JDK7/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/EPSGInstallerTest.java
    sis/branches/JDK7/ide-project/NetBeans/build.xml
    sis/branches/JDK7/pom.xml

Propchange: sis/branches/JDK7/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Feb 11 10:59:45 2016
@@ -1,4 +1,4 @@
 /sis/branches/Android:1430670-1480699
 /sis/branches/JDK6:1394913-1508480
-/sis/branches/JDK8:1584960-1729283
+/sis/branches/JDK8:1584960-1729794
 /sis/trunk:1394364-1508466,1519089-1519674

Modified: sis/branches/JDK7/core/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/pom.xml?rev=1729801&r1=1729800&r2=1729801&view=diff
==============================================================================
--- sis/branches/JDK7/core/pom.xml (original)
+++ sis/branches/JDK7/core/pom.xml Thu Feb 11 10:59:45 2016
@@ -67,6 +67,17 @@
       </roles>
     </developer>
     <developer>
+      <name>Rémi Maréchal</name>
+      <id>rmarechal</id>
+      <email>remi.marechal@geomatys.com</email>
+      <organization>Geomatys</organization>
+      <organizationUrl>http://www.geomatys.com/</organizationUrl>
+      <timezone>+1</timezone>
+      <roles>
+        <role>developer</role>
+      </roles>
+    </developer>
+    <developer>
       <name>Travis L. Pinney</name>
       <id>tlpinney</id>
       <email>travis.pinney@gmail.com</email>

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=1729801&r1=1729800&r2=1729801&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] Thu Feb 11 10:59:45 2016
@@ -21,8 +21,7 @@ import java.util.HashMap;
 import java.util.Locale;
 import java.io.EOFException;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
+import java.io.BufferedReader;
 import java.io.LineNumberReader;
 import java.io.StringReader;
 import java.sql.Statement;
@@ -98,12 +97,6 @@ public class ScriptRunner implements Aut
     private static final String ESCAPE = "$BODY$";
 
     /**
-     * The character encoding of SQL scripts. Typical values are {@code "UTF-8"} or {@code
"ISO-8859-1"}.
-     * For SQL scripts provided by the EPSG, the encoding shall be {@code "ISO-8859-1"}.
-     */
-    private final String encoding;
-
-    /**
      * The presumed dialect spoken by the database.
      */
     private final Dialect dialect;
@@ -230,17 +223,13 @@ public class ScriptRunner implements Aut
      * </ul>
      *
      * @param connection        The connection to the database.
-     * @param encoding          The encoding of SQL scripts. Typical values are {@code "UTF-8"}
or {@code "ISO-8859-1"}.
-     *                          For SQL scripts provided by the EPSG authority, the encoding
shall be {@code "ISO-8859-1"}.
      * @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, final String encoding, int maxRowsPerInsert)
throws SQLException {
+    protected ScriptRunner(final Connection connection, int maxRowsPerInsert) throws SQLException
{
         ArgumentChecks.ensureNonNull("connection", connection);
-        ArgumentChecks.ensureNonNull("encoding", encoding);
         ArgumentChecks.ensurePositive("maxRowsPerInsert", maxRowsPerInsert);
         final DatabaseMetaData metadata = connection.getMetaData();
-        this.encoding           = encoding;
         this.dialect            = Dialect.guess(metadata);
         this.identifierQuote    = metadata.getIdentifierQuoteString();
         this.isSchemaSupported  = metadata.supportsSchemasInTableDefinitions() &&
@@ -352,39 +341,22 @@ public class ScriptRunner implements Aut
      * @throws SQLException if an error occurred while executing a SQL statement.
      */
     public final int run(final String statement) throws IOException, SQLException {
-        return run(new LineNumberReader(new StringReader(statement)));
-    }
-
-    /**
-     * Runs the SQL script from the given input stream, which will be closed.
-     * 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. <strong>This stream will be closed</strong>
at the end.
-     * @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.
-     */
-    public final int run(final String filename, final InputStream in) throws IOException,
SQLException {
-        currentFile = filename;
-        final int count;
-        try (LineNumberReader reader = new LineNumberReader(new InputStreamReader(in, encoding)))
{
-            count = run(reader);
-        }
-        currentFile = null;
-        return count;
+        return run(null, new LineNumberReader(new StringReader(statement)));
     }
 
     /**
      * Run 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.
      * @throws IOException if an error occurred while reading the input.
      * @throws SQLException if an error occurred while executing a SQL statement.
      */
-    private int run(final LineNumberReader in) throws IOException, SQLException {
+    public final int run(final String filename, final BufferedReader in) throws IOException,
SQLException {
+        currentFile = filename;
+        currentLine = 0;
         int     statementCount     = 0;         // For informative purpose only.
         int     posOpeningQuote    = -1;        // -1 if we are not inside a text.
         boolean isInsideIdentifier = false;
@@ -399,7 +371,9 @@ public class ScriptRunner implements Aut
                 if (s >= line.length() || line.regionMatches(s, COMMENT, 0, COMMENT.length()))
{
                     continue;
                 }
-                currentLine = in.getLineNumber();
+                if (in instanceof LineNumberReader) {
+                    currentLine = ((LineNumberReader) in).getLineNumber();
+                }
             } else {
                 buffer.append('\n');
             }
@@ -533,6 +507,7 @@ parseLine:  while (pos < length) {
         if (!line.isEmpty() && !line.startsWith(COMMENT)) {
             throw new EOFException(Errors.format(Errors.Keys.UnexpectedEndOfString_1, line));
         }
+        currentFile = null;
         return statementCount;
     }
 
@@ -643,7 +618,8 @@ parseLine:  while (pos < length) {
     public String status(final Locale locale) {
         String position = null;
         if (currentFile != null) {
-            position = Errors.getResources(locale).getString(Errors.Keys.ErrorInFileAtLine_2,
currentFile, currentLine);
+            position = Errors.getResources(locale).getString(Errors.Keys.ErrorInFileAtLine_2,
currentFile,
+                    (currentLine != 0) ? currentLine : '?');
         }
         if (currentSQL != null) {
             final StringBuilder buffer = new StringBuilder();

Modified: sis/branches/JDK7/core/sis-referencing/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/pom.xml?rev=1729801&r1=1729800&r2=1729801&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/pom.xml (original)
+++ sis/branches/JDK7/core/sis-referencing/pom.xml Thu Feb 11 10:59:45 2016
@@ -70,6 +70,17 @@ Implementations of Coordinate Reference
         <role>developer</role>
       </roles>
     </developer>
+    <developer>
+      <name>Rémi Maréchal</name>
+      <id>rmarechal</id>
+      <email>remi.marechal@geomatys.com</email>
+      <organization>Geomatys</organization>
+      <organizationUrl>http://www.geomatys.com/</organizationUrl>
+      <timezone>+1</timezone>
+      <roles>
+        <role>developer</role>
+      </roles>
+    </developer>
   </developers>
 
 

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGFactory.java?rev=1729801&r1=1729800&r2=1729801&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGFactory.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGFactory.java
[UTF-8] Thu Feb 11 10:59:45 2016
@@ -44,10 +44,6 @@ import org.apache.sis.referencing.factor
 import org.apache.sis.referencing.factory.UnavailableFactoryException;
 import org.apache.sis.util.ArgumentChecks;
 import org.apache.sis.util.Localized;
-import org.apache.sis.util.ObjectConverters;
-
-// Branch-dependent imports
-import java.nio.file.Path;
 
 
 /**
@@ -152,10 +148,10 @@ public class EPSGFactory extends Concurr
     private final String schema;
 
     /**
-     * The path where to search for EPSG definition files if {@code EPSGFactory} needs to
create the database,
-     * or {@code null} for searching in the {@linkplain Class#getResource(String) resources}
instead.
+     * A provider of SQL scripts to use if {@code EPSGFactory} needs to create the database,
+     * or {@code null} for the default mechanism.
      */
-    private final Path scriptDirectory;
+    private final InstallationScriptProvider scriptProvider;
 
     /**
      * The translator from the SQL statements using MS-Access dialect to SQL statements using
the dialect
@@ -219,9 +215,9 @@ public class EPSGFactory extends Concurr
      *   <td>{@link String}</td>
      *   <td>The database schema that contains the EPSG tables (see {@linkplain #install
install}).</td>
      *  </tr><tr>
-     *   <td>{@code scriptDirectory}</td>
-     *   <td>{@link java.nio.file.Path}, {@link java.io.File} or {@link java.net.URL}</td>
-     *   <td>The directory that contains the EPSG definition files (see {@linkplain
#install install}).</td>
+     *   <td>{@code scriptProvider}</td>
+     *   <td>{@link InstallationScriptProvider}</td>
+     *   <td>A provider of SQL scripts to use if {@code EPSGFactory} needs to create
the database.</td>
      *  </tr><tr>
      *   <td>{@code locale}</td>
      *   <td>{@link Locale}</td>
@@ -250,11 +246,11 @@ public class EPSGFactory extends Concurr
         if (properties == null) {
             properties = Collections.emptyMap();
         }
-        DataSource ds   = (DataSource) properties.get("dataSource");
-        Locale locale   = ObjectConverters.convert(properties.get("locale"),  Locale.class);
-        schema          = ObjectConverters.convert(properties.get("schema"),  String.class);
-        catalog         = ObjectConverters.convert(properties.get("catalog"), String.class);
-        scriptDirectory = ObjectConverters.convert(properties.get("scriptDirectory"), Path.class);
+        DataSource ds  = (DataSource)                 properties.get("dataSource");
+        Locale locale  = (Locale)                     properties.get("locale");
+        schema         = (String)                     properties.get("schema");
+        catalog        = (String)                     properties.get("catalog");
+        scriptProvider = (InstallationScriptProvider) properties.get("scriptProvider");
         if (locale == null) {
             locale = Locale.getDefault(Locale.Category.DISPLAY);
         }
@@ -334,14 +330,13 @@ public class EPSGFactory extends Concurr
      *     schemas in table definitions} or in {@linkplain DatabaseMetaData#supportsSchemasInDataManipulation()
      *     data manipulation}, then this property is ignored.</li>
      *
-     *   <li><b>{@code scriptDirectory}:</b><br>
-     *     a {@link java.nio.file.Path}, {@link java.io.File} or {@link java.net.URL} to
a directory containing
-     *     the SQL scripts to execute. If non-null, that directory shall contain at least
files matching the
-     *     {@code *Tables*.sql}, {@code *Data*.sql} and {@code *FKeys*.sql} patterns (those
files are provided by EPSG).
-     *     Files matching the {@code *Patches*.sql}, {@code *Indexes*.sql} and {@code *Grant*.sql}
patterns
-     *     (provided by Apache SIS) are optional but recommended.
-     *     If no directory is specified, then this method will search for resources provided
by the
-     *     {@code geotk-epsg.jar} bundle.</li>
+     *   <li><b>{@code scriptProvider}:</b><br>
+     *     an {@link InstallationScriptProvider} giving the SQL scripts to execute for creating
the EPSG database.
+     *     If no provider is specified, then this method will search on the classpath (with
{@link java.util.ServiceLoader})
+     *     for user-provided implementations of {@code InstallationScriptProvider}.
+     *     If no user-specified provider is found, then this method will search for
+     *     {@code "EPSG_Tables.sql"}, {@code "EPSG_Data.sql"} and {@code "EPSG_FKeys.sql"}
files in the
+     *     {@code $SIS_DATA/Databases/ExternalSources} directory.</li>
      * </ul>
      *
      * <p><b>Legal constraint:</b>
@@ -369,7 +364,7 @@ public class EPSGFactory extends Concurr
                         installer.prependNamespace(catalog);
                     }
                 }
-                installer.run(scriptDirectory);
+                installer.run(scriptProvider);
                 success = true;
             } finally {
                 if (ac) {

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=1729801&r1=1729800&r2=1729801&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] Thu Feb 11 10:59:45 2016
@@ -17,6 +17,7 @@
 package org.apache.sis.referencing.factory.sql;
 
 import java.util.Locale;
+import java.util.ServiceLoader;
 import java.io.IOException;
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
@@ -27,24 +28,18 @@ import java.util.logging.Level;
 import java.util.logging.LogRecord;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
-import java.io.FileNotFoundException;
-import java.io.InputStream;
+import java.io.BufferedReader;
 import org.apache.sis.util.StringBuilders;
 import org.apache.sis.internal.metadata.sql.ScriptRunner;
 import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.internal.util.Constants;
 import org.apache.sis.util.CharSequences;
-import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.resources.Messages;
 import org.apache.sis.util.logging.Logging;
 import org.apache.sis.util.logging.PerformanceLevel;
 
-// Branch-specific imports
-import java.nio.file.Files;
-import java.nio.file.Path;
 import org.apache.sis.internal.jdk8.BiFunction;
 
-
 /**
  * Runs the SQL scripts for creating an EPSG database.
  *
@@ -55,19 +50,6 @@ import org.apache.sis.internal.jdk8.BiFu
  */
 final class EPSGInstaller extends ScriptRunner {
     /**
-     * The embedded SQL scripts to execute for creating the EPSG database, in that order.
-     * The {@code ".sql"} suffix is omitted. The {@code "Grant"} script must be last.
-     */
-    private static final String[] SCRIPTS = {
-        "Tables", "Data", "Patches", "FKeys", "Indexes", "Grant"         // "Grant" must
be last.
-    };
-
-    /**
-     * The encoding used in the SQL scripts.
-     */
-    static final String ENCODING = "ISO-8859-1";
-
-    /**
      * The pattern for an {@code "UPDATE … SET … REPLACE"} instruction.
      * Example:
      *
@@ -100,7 +82,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, ENCODING, 100);
+        super(connection, 100);
         boolean isReplaceSupported = false;
         final DatabaseMetaData metadata = connection.getMetaData();
         final String functions = metadata.getStringFunctions();
@@ -224,6 +206,9 @@ final class EPSGInstaller extends Script
         if (CharSequences.equalsIgnoreCase(sql, "COMMIT")) {
             return 0;
         }
+        if (!isGrantOnTableSupported && CharSequences.regionMatches(sql, 0, "GRANT"))
{
+            return 0;
+        }
         if (statementToSkip != null && statementToSkip.reset(sql).matches()) {
             return 0;
         }
@@ -234,47 +219,23 @@ final class EPSGInstaller extends Script
     }
 
     /**
-     * Processes to the creation of the EPSG database using the files in the given directory.
-     * The given directory should contain at least files similar to the following ones
-     * (files without {@code ".sql"} extension are ignored):
-     *
-     * <ul>
-     *   <li>{@code EPSG_v8_18.mdb_Tables_PostgreSQL.sql}</li>
-     *   <li>{@code EPSG_v6_18.mdb_Data_PostgreSQL.sql}</li>
-     *   <li>{@code EPSG_v6_18.mdb_FKeys_PostgreSQL.sql}</li>
-     *   <li>Optional but recommended: {@code EPSG_v6_18.mdb_Indexes_PostgreSQL.sql}.</li>
-     * </ul>
-     *
-     * The suffix may be different (for example {@code "_MySQL.sql"} instead of {@code "_PostgreSQL.sql"})
-     * and the version number may be different.
-     *
-     * <p>If the given directory is {@code null}, then the scripts will be read from
the resources.
-     * If no resources is found, then an exception will be thrown.
+     * Processes to the creation of the EPSG database using the SQL scripts from the given
provider.
      *
      * @throws IOException if an error occurred while reading an input.
      * @throws SQLException if an error occurred while executing a SQL statement.
      */
-    public void run(final Path scriptDirectory) throws SQLException, IOException {
+    public void run(InstallationScriptProvider scriptProvider) throws SQLException, IOException
{
         long time = System.nanoTime();
-        log(Messages.getResources(null).getLogRecord(Level.INFO, Messages.Keys.CreatingSchema_2,
Constants.EPSG, getURL()));
-        int numScripts = SCRIPTS.length;
-        if (!isGrantOnTableSupported) {
-            numScripts--;
+        log(Messages.getResources(null).getLogRecord(Level.INFO, Messages.Keys.CreatingSchema_2,
Constants.EPSG, getSimplifiedURL()));
+        if (scriptProvider == null) {
+            scriptProvider = lookupProvider();
         }
+        final String[] scripts = scriptProvider.getScriptNames();
         int numRows = 0;
-        for (int i=0; i<numScripts; i++) {
-            final String script = SCRIPTS[i] + ".sql";
-            final InputStream in;
-            if (scriptDirectory != null) {
-                in = Files.newInputStream(scriptDirectory.resolve(script));
-            } else {
-                in = EPSGInstaller.class.getResourceAsStream(script);
-                if (in == null) {
-                    throw new FileNotFoundException(Errors.format(Errors.Keys.FileNotFound_1,
script));
-                }
+        for (int i=0; i<scripts.length; i++) {
+            try (BufferedReader in = scriptProvider.getScriptContent(i)) {
+                numRows += run(scripts[i], in);
             }
-            numRows += run(script, in);
-            // The stream will be closed by the run method.
         }
         time = System.nanoTime() - time;
         log(Messages.getResources(null).getLogRecord(
@@ -283,10 +244,22 @@ final class EPSGInstaller extends Script
     }
 
     /**
+     * Searches for a SQL script provider on the classpath before to fallback on the default
provider.
+     */
+    private static InstallationScriptProvider lookupProvider() {
+        for (final InstallationScriptProvider p : ServiceLoader.load(InstallationScriptProvider.class))
{
+            if (Constants.EPSG.equals(p.getAuthority())) {
+                return p;
+            }
+        }
+        return new InstallationScriptProvider.Default();
+    }
+
+    /**
      * Returns a simplified form of the URL (truncated before the first ? or ; character),
      * for logging purpose only.
      */
-    private String getURL() throws SQLException {
+    private String getSimplifiedURL() 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();

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/package-info.java?rev=1729801&r1=1729800&r2=1729801&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/package-info.java
[UTF-8] Thu Feb 11 10:59:45 2016
@@ -16,9 +16,12 @@
  */
 
 /**
- * Factories for geodetic objects defined in a SQL database.
+ * Factories for geodetic objects defined in a SQL database, typically the EPSG dataset.
  * The main class in this package is {@link org.apache.sis.referencing.factory.sql.EPSGFactory},
  * which requires a {@link javax.sql.DataSource} providing connections to an EPSG database.
+ *
+ *
+ * <div class="section">Connection to the database</div>
  * By default Apache SIS used Apache Derby (a.k.a. JavaDB), but the database can also be
PostgreSQL or MS-Access.
  * The connection is obtained by the first of the following data sources which is found:
  *
@@ -44,17 +47,20 @@
  * For example the two following method calls fetch the same object:
  *
  * <ul>
- *   <li>{@code createProjectedCRS("NTF (Paris) / Lambert zone II")}</li>
  *   <li>{@code createProjectedCRS("27572")}</li>
+ *   <li>{@code createProjectedCRS("NTF (Paris) / Lambert zone II")}</li>
  * </ul>
  *
- * However names may be ambiguous since the same name may be used for more than one object.
+ * <div class="note"><b>Note:</b> names may be ambiguous since the same
name may be used for more than one object.
  * This is the case of <cite>"WGS 84"</cite> for example. If such an ambiguity
is found, an exception will be thrown.
+ * For more determinism, the numerical codes are preferred.</div>
+ *
  *
- * <p>When an error is discovered in a Coordinate Reference System (CRS) definition,
the EPSG group does not apply the
+ * <div class="section">How deprecated entries are handled</div>
+ * When an error is discovered in a Coordinate Reference System (CRS) definition, the EPSG
group does not apply the
  * correction directly on the erroneous object (unless the correction is very minor).
  * Instead, the erroneous object is deprecated and a new one is created.
- * Apache SIS handles deprecated objects as below:</p>
+ * Apache SIS handles deprecated objects as below:
  *
  * <ul>
  *   <li>Deprecated objects are not listed in the collection returned by the

Modified: sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGDataFormatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGDataFormatter.java?rev=1729801&r1=1729800&r2=1729801&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGDataFormatter.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGDataFormatter.java
[UTF-8] Thu Feb 11 10:59:45 2016
@@ -21,10 +21,11 @@ import java.util.HashMap;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.LineNumberReader;
+import java.io.InputStreamReader;
 import java.io.Writer;
 import java.io.BufferedWriter;
 import java.io.OutputStreamWriter;
-import java.io.InputStream;
 import java.io.IOException;
 import java.sql.Connection;
 import java.sql.SQLException;
@@ -35,6 +36,9 @@ import org.apache.sis.util.CharSequences
 import org.apache.sis.internal.metadata.sql.ScriptRunner;
 import org.apache.sis.internal.metadata.sql.TestDatabase;
 
+// Branch-dependent imports
+import java.nio.charset.StandardCharsets;
+
 
 /**
  * Rewrites the {@code INSERT TO ...} statements in a SQL script in a more compact form.
@@ -182,7 +186,7 @@ public final class EPSGDataFormatter ext
      * @throws SQLException if an error occurred while fetching metadata.
      */
     private EPSGDataFormatter(final Connection c) throws SQLException {
-        super(c, EPSGInstaller.ENCODING, Integer.MAX_VALUE);
+        super(c, Integer.MAX_VALUE);
         numBooleanColumnsForTables = new HashMap<>();
         numBooleanColumnsForTables.put("epsg_alias",                     0);
         numBooleanColumnsForTables.put("epsg_area",                      1);
@@ -231,8 +235,10 @@ public final class EPSGDataFormatter ext
         if (inputFile.equals(outputFile)) {
             throw new IllegalArgumentException("Input and output files are the same.");
         }
-        out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile),
EPSGInstaller.ENCODING));
-        try (final InputStream in = new FileInputStream(inputFile)) {
+        out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile),
StandardCharsets.ISO_8859_1));
+        try (final LineNumberReader in = new LineNumberReader(
+                new InputStreamReader(new FileInputStream(inputFile), StandardCharsets.ISO_8859_1)))
+        {
             run(inputFile.getName(), in);
         } finally {
             out.close();

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=1729801&r1=1729800&r2=1729801&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] Thu Feb 11 10:59:45 2016
@@ -47,9 +47,6 @@ import org.junit.Test;
 import static org.junit.Assert.*;
 import static org.junit.Assume.*;
 
-// Branch-dependent imports
-import java.nio.file.Path;
-
 
 /**
  * Tests {@link EPSGInstaller} indirectly, through {@link EPSGFactory#install(Connection)}.
@@ -112,6 +109,17 @@ public final strictfp class EPSGInstalle
     }
 
     /**
+     * Returns the SQL scripts needed for testing the database creation,
+     * or skip the JUnit test if those scripts are not found.
+     */
+    private static InstallationScriptProvider getScripts() {
+        final InstallationScriptProvider scripts = new InstallationScriptProvider.Default();
+        assumeTrue("EPSG scripts not found in Databases/ExternalSources directory.",
+                scripts.getAuthority().equals("EPSG"));
+        return scripts;
+    }
+
+    /**
      * Tests the creation of an EPSG database on Derby.
      * This test is skipped if Derby/JavaDB is not found, or if the SQL scripts are not found.
      *
@@ -119,8 +127,7 @@ public final strictfp class EPSGInstalle
      */
     @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 InstallationScriptProvider scripts = getScripts();            // Needs to be
invoked first.
         final DataSource ds = TestDatabase.create("test");
         try {
             createAndTest(ds, scripts);
@@ -144,7 +151,7 @@ public final strictfp class EPSGInstalle
     @Test
     @Ignore("Skipped for protecting java.util.logging configuration against changes.")
     public void testCreationOnHSQLDB() throws Exception {
-        final Path scripts = TestDatabase.directory("ExternalSources");
+        final InstallationScriptProvider scripts = getScripts();            // Needs to be
invoked first.
         final DataSource ds = (DataSource) Class.forName("org.hsqldb.jdbc.JDBCDataSource").newInstance();
         ds.getClass().getMethod("setURL", String.class).invoke(ds, "jdbc:hsqldb:mem:test");
         try {
@@ -162,11 +169,13 @@ public final strictfp class EPSGInstalle
      * 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 void createAndTest(final DataSource ds, final Path scripts) throws SQLException,
FactoryException {
+    private void createAndTest(final DataSource ds, final InstallationScriptProvider scriptProvider)
+            throws SQLException, FactoryException
+    {
         listener.maximumLogCount = 100;
         final Map<String,Object> properties = new HashMap<>();
         assertNull(properties.put("dataSource", ds));
-        assertNull(properties.put("scriptDirectory", scripts));
+        assertNull(properties.put("scriptProvider", scriptProvider));
         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)) {

Modified: sis/branches/JDK7/ide-project/NetBeans/build.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/ide-project/NetBeans/build.xml?rev=1729801&r1=1729800&r2=1729801&view=diff
==============================================================================
--- sis/branches/JDK7/ide-project/NetBeans/build.xml (original)
+++ sis/branches/JDK7/ide-project/NetBeans/build.xml Thu Feb 11 10:59:45 2016
@@ -45,11 +45,14 @@
     </copy>
     -->
 
-    <!-- Following are classical properties resources files. -->
+    <!-- Resources (properties files, SQL scripts). -->
     <copy todir="${build.classes.dir}">
       <fileset dir="${project.root}/core/sis-utility/src/main/resources">
         <include name="**/*.properties"/>
       </fileset>
+      <fileset dir="${project.root}/core/sis-referencing/src/main/resources">
+        <include name="**/*.sql"/>
+      </fileset>
       <fileset dir="${project.root}/application/sis-console/src/main/resources">
         <include name="**/*.properties"/>
       </fileset>

Modified: sis/branches/JDK7/pom.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/pom.xml?rev=1729801&r1=1729800&r2=1729801&view=diff
==============================================================================
--- sis/branches/JDK7/pom.xml (original)
+++ sis/branches/JDK7/pom.xml Thu Feb 11 10:59:45 2016
@@ -209,6 +209,17 @@ Apache SIS is a free software, Java lang
         <role>committer</role>
       </roles>
     </developer>
+    <developer>
+      <name>Rémi Maréchal</name>
+      <id>rmarechal</id>
+      <email>remi.marechal@geomatys.com</email>
+      <organization>Geomatys</organization>
+      <organizationUrl>http://www.geomatys.com/</organizationUrl>
+      <timezone>+1</timezone>
+      <roles>
+        <role>developer</role>
+      </roles>
+    </developer>
   </developers>
 
   <contributors>



Mime
View raw message