sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1729793 - in /sis/branches/JDK8: core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/ ide-project/NetBeans/
Date Thu, 11 Feb 2016 10:37:22 GMT
Author: desruisseaux
Date: Thu Feb 11 10:37:22 2016
New Revision: 1729793

URL: http://svn.apache.org/viewvc?rev=1729793&view=rev
Log:
Complete the InstallationScriptProvider support by searching for user-provided instances on
the classpath.

Modified:
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGFactory.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGInstaller.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/InstallationScriptProvider.java
    sis/branches/JDK8/ide-project/NetBeans/build.xml

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGFactory.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGFactory.java?rev=1729793&r1=1729792&r2=1729793&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGFactory.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGFactory.java
[UTF-8] Thu Feb 11 10:37:22 2016
@@ -332,7 +332,9 @@ public class EPSGFactory extends Concurr
      *
      *   <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 for
+     *     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>

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=1729793&r1=1729792&r2=1729793&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] Thu Feb 11 10:37:22 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;
@@ -220,9 +221,9 @@ final class EPSGInstaller extends Script
      */
     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()));
+        log(Messages.getResources(null).getLogRecord(Level.INFO, Messages.Keys.CreatingSchema_2,
Constants.EPSG, getSimplifiedURL()));
         if (scriptProvider == null) {
-            scriptProvider = new InstallationScriptProvider.Default();
+            scriptProvider = lookupProvider();
         }
         final String[] scripts = scriptProvider.getScriptNames();
         int numRows = 0;
@@ -238,10 +239,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/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/InstallationScriptProvider.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/InstallationScriptProvider.java?rev=1729793&r1=1729792&r2=1729793&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/InstallationScriptProvider.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/InstallationScriptProvider.java
[UTF-8] Thu Feb 11 10:37:22 2016
@@ -50,13 +50,17 @@ import java.nio.file.Path;
  * }
  *
  * <div class="section">How this interface is used</div>
- * The first time that an {@link EPSGDataAccess} needs to be instantiated, {@link EPSGFactory}
verifies if the
- * EPSG database exists.  If it does not, then the {@link EPSGFactory#install(Connection)}
method searches for
- * the first {@code InstallationScriptProvider} instance for which {@link #getAuthority}
returns {@code "EPSG"}.
- * The {@linkplain #getLicense license} may be shown to the user if the application allows
that (for example when
- * running as a {@linkplain org.apache.sis.console console application}). If the installation
process is allowed
- * to continue, it will iterate over all readers provided by {@link #getScriptContent(int)}
and execute the SQL
- * statements (not necessarily verbatim; the installation process may adapt to the target
database).
+ * The first time that an {@link EPSGDataAccess} needs to be instantiated, {@link EPSGFactory}
verifies
+ * if the EPSG database exists. If it does not, then:
+ * <ol>
+ *   <li>{@link EPSGFactory#install(Connection)} searches for the first {@code InstallationScriptProvider}
instance
+ *       for which {@link #getAuthority()} returns {@code "EPSG"}.</li>
+ *   <li>The {@linkplain #getLicense license} may be shown to the user if the application
allows that
+ *       (for example when running as a {@linkplain org.apache.sis.console console application}).</li>
+ *   <li>If the installation process is allowed to continue, it will iterate over all
readers provided by
+ *       {@link #getScriptContent(int)} and execute the SQL statements (not necessarily verbatim;
+ *       the installation process may adapt to the target database).</li>
+ * </ol>
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.7
@@ -287,7 +291,7 @@ public abstract class InstallationScript
          * Opens the input stream for the SQL script of the given name.
          *
          * @param  name Name of the script file to open.
-         * @return An input stream opened of the given script file.
+         * @return An input stream opened of the given script file, or {@code null} if the
resource was not found.
          * @throws IOException if an error occurred while opening the file.
          */
         @Override

Modified: sis/branches/JDK8/ide-project/NetBeans/build.xml
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/ide-project/NetBeans/build.xml?rev=1729793&r1=1729792&r2=1729793&view=diff
==============================================================================
--- sis/branches/JDK8/ide-project/NetBeans/build.xml (original)
+++ sis/branches/JDK8/ide-project/NetBeans/build.xml Thu Feb 11 10:37:22 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>



Mime
View raw message