sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1728152 - in /sis/branches/JDK8/core: sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/ sis-referencing/src/main/java/org/apache/sis/referencing/ sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/ sis-refe...
Date Tue, 02 Feb 2016 15:42:03 GMT
Author: desruisseaux
Date: Tue Feb  2 15:42:03 2016
New Revision: 1728152

URL: http://svn.apache.org/viewvc?rev=1728152&view=rev
Log:
Change the way we construct EPSGFactory by specifying a map of properties instead than enumerating
the parameters.
This give us more freedom for future addition of properties, and avoid the problem of too
many parameters for
remembering what each argument is for (especially considering that all parameters/properties
are optional).

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/AuthorityFactories.java
    sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/factory/sql/EPSGFactory.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/GIGS2001.java
    sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java?rev=1728152&r1=1728151&r2=1728152&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
[UTF-8] Tue Feb  2 15:42:03 2016
@@ -80,6 +80,15 @@ public abstract class Initializer {
     public static final String JNDI = "jdbc/" + DATABASE;
 
     /**
+     * The class loader for JavaDB (i.e. the Derby database distributed with the JDK), created
when first needed.
+     * This field is never reset to {@code null} even if the classpath changed because this
class loader is for
+     * a JAR file the JDK installation directory, and we presume that the JDK installation
do not change.
+     *
+     * @see #forJavaDB(String)
+     */
+    private static URLClassLoader javadbLoader;
+
+    /**
      * The unique, SIS-wide, data source to the {@code $SIS_DATA/Databases/SpatialMetadata}
database.
      * Created when first needed, and cleared on shutdown.
      *
@@ -180,7 +189,8 @@ public abstract class Initializer {
          * Clears the data source anyway. In the worst case scenario, the application will
fetch
          * it again from a the JNDI context.
          */
-        @Override public void namingExceptionThrown(NamingExceptionEvent event) {
+        @Override
+        public void namingExceptionThrown(NamingExceptionEvent event) {
             Logging.unexpectedException(Logging.getLogger(Loggers.SYSTEM),
                     Listener.class, "namingExceptionThrown", event.getException());
             objectChanged(null);
@@ -227,11 +237,63 @@ public abstract class Initializer {
                 record.setLoggerName(Loggers.SQL);
                 Logging.log(Initializer.class, "getDataSource", record);
             }
+            /*
+             * At this point we determined that there is no JNDI context or no object binded
to "jdbc/SpatialMetadata".
+             * As a fallback, try to open the Derby database located in $SIS_DATA/Databases/SpatialMetadata
directory.
+             */
+            boolean create = false;
+            final String home = System.getProperty(HOME_KEY);
             final Path dir = DataDirectory.DATABASES.getDirectory();
             if (dir != null) {
-                source = forJavaDB(dir.resolve(DATABASE));
-            } else if (System.getProperty(HOME_KEY) != null) {
+                Path path = dir.resolve(DATABASE);
+                if (home != null) try {
+                    /*
+                     * If a "derby.system.home" property is set, we may be able to get a
shorter path by making it
+                     * relative to Derby home. The intend is to have a nicer URL like "jdbc:derby:SpatialMetadata"
+                     * instead than "jdbc:derby:/a/long/path/to/SIS/Data/Databases/SpatialMetadata".
In addition
+                     * to making loggings and EPSGDataAccess.getAuthority() output nicer,
it also reduces the risk
+                     * of encoding issues if the path contains spaces or non-ASCII characters.
+                     */
+                    path = Paths.get(home).relativize(path);
+                } catch (IllegalArgumentException | SecurityException e) {
+                    // The path can not be relativized. This is okay.
+                    Logging.recoverableException(Logging.getLogger(Loggers.SQL), Initializer.class,
"getDataSource", e);
+                }
+                /*
+                 * Create the Derby data source using the context class loader if possible,
+                 * or otherwise a URL class loader to the JavaDB distributed with the JDK.
+                 */
+                path   = path.normalize();
+                create = !Files.exists(path);
+                source = forJavaDB(path.toString());
+            } else if (home != null) {
                 source = forJavaDB(DATABASE);
+            } else {
+                return null;
+            }
+            /*
+             * Register the shutdown hook before to attempt any operation on the database
in order to close
+             * it properly if the schemas creation below fail.
+             */
+            Shutdown.register(() -> {
+                shutdown();
+                return null;
+            });
+            /*
+             * If the database does not exist, create it. We allow creation only if we are
inside
+             * the $SIS_DATA directory. The Java code creating the schemas is provided in
other
+             * SIS modules. For example sis-referencing may create the EPSG dataset.
+             */
+            if (create) {
+                final Method m = source.getClass().getMethod("setCreateDatabase", String.class);
+                m.invoke(source, "create");
+                try (Connection c = source.getConnection()) {
+                    for (Initializer init : ServiceLoader.load(Initializer.class)) {
+                        init.createSchema(c);
+                    }
+                } finally {
+                    m.invoke(source, "no");     // Any value other than "create".
+                }
             }
         }
         return source;
@@ -268,56 +330,6 @@ public abstract class Initializer {
     }
 
     /**
-     * Creates a data source for a Derby database at the given {@code $SIS_DATA/Databases/SpatialMetadata}
location.
-     * If the database does not exist, it will be created.
-     *
-     * @param  path  The {@code $SIS_DATA/Databases/SpatialMetadata} directory.
-     * @return The data source.
-     * @throws Exception if the data source can not be created.
-     */
-    private static DataSource forJavaDB(Path path) throws Exception {
-        /*
-         * If a "derby.system.home" property is set, we may be able to get a shorter path
by making it
-         * relative to Derby home. The intend is to have a nicer URL like "jdbc:derby:SpatialMetadata"
-         * instead than "jdbc:derby:/a/long/path/to/SIS/Data/Databases/SpatialMetadata".
In addition
-         * to making loggings and EPSGDataAccess.getAuthority() output nicer, it also reduces
the risk
-         * of encoding issues if the path contains spaces or non-ASCII characters.
-         */
-        try {
-            final String home = System.getProperty(HOME_KEY);
-            if (home != null) {
-                path = Paths.get(home).relativize(path);
-            }
-        } catch (IllegalArgumentException | SecurityException e) {
-            // The path can not be relativized. This is okay. Use the public method as the
logging source.
-            Logging.recoverableException(Logging.getLogger(Loggers.SQL), Initializer.class,
"getDataSource", e);
-        }
-        /*
-         * Create the Derby data source using the context class loader if possible,
-         * or otherwise a URL class loader to the JavaDB distributed with the JDK.
-         */
-        path = path.normalize();
-        final DataSource ds = forJavaDB(path.toString());
-        /*
-         * If the database does not exist, create it. We allow creation only here because
we are inside
-         * the $SIS_DATA directory. The Java code creating the schemas is provided in other
SIS modules.
-         * For example sis-referencing may create the EPSG dataset.
-         */
-        if (!Files.exists(path)) {
-            final Method m = ds.getClass().getMethod("setCreateDatabase", String.class);
-            m.invoke(ds, "create");
-            try (Connection c = ds.getConnection()) {
-                for (Initializer init : ServiceLoader.load(Initializer.class)) {
-                    init.createSchema(c);
-                }
-            } finally {
-                m.invoke(ds, "no");     // Any value other than "create".
-            }
-        }
-        return ds;
-    }
-
-    /**
      * Creates a data source for a Derby database at the given location. The location may
be either the
      * {@code $SIS_DATA/Databases/SpatialMetadata} directory, or the {@code SpatialMetadata}
database
      * in the directory given by the {@code derby.system.home} property.
@@ -325,29 +337,39 @@ public abstract class Initializer {
      * <p>This method does <strong>not</strong> create the database if
it does not exist, because this
      * method does not know if we are inside the {@code $SIS_DATA} directory.</p>
      *
+     * <p>It is caller's responsibility to shutdown the Derby database after usage.</p>
+     *
      * @param  path  Relative or absolute path to the database.
      * @return The data source.
      * @throws Exception if the data source can not be created.
      */
-    private static DataSource forJavaDB(final String path) throws Exception {
+    public static DataSource forJavaDB(final String path) throws Exception {
         try {
             return forJavaDB(path, Thread.currentThread().getContextClassLoader());
         } catch (ClassNotFoundException e) {
-            final String home = System.getProperty("java.home");
-            if (home != null) {
-                final Path file = Paths.get(home).resolveSibling("db/lib/derby.jar");
-                if (Files.isRegularFile(file)) {
-                    return forJavaDB(path, new URLClassLoader(new URL[] {file.toUri().toURL()}));
+            URLClassLoader loader;
+            synchronized (Initializer.class) {
+                loader = javadbLoader;
+                if (loader == null) {
+                    final String home = System.getProperty("java.home");
+                    if (home != null) {
+                        final Path file = Paths.get(home).resolveSibling("db/lib/derby.jar");
+                        if (Files.isRegularFile(file)) {
+                            javadbLoader = loader = new URLClassLoader(new URL[] {file.toUri().toURL()});
+                        }
+                    }
                 }
             }
-            throw e;
+            if (loader == null) {
+                throw e;
+            }
+            return forJavaDB(path, loader);
         }
     }
 
     /**
-     * Creates a data source for the given path using the given class loader.
-     * If this method succeed in creating a data source, then it registers a shutdown hook
-     * for shutting down the database at JVM shutdown time of Servlet/OSGi bundle uninstall
time.
+     * Creates a Derby data source for the given path using the given class loader.
+     * It is caller's responsibility to shutdown the Derby database after usage.
      *
      * @throws ClassNotFoundException if Derby is not on the classpath.
      */
@@ -357,10 +379,6 @@ public abstract class Initializer {
         final Class<?>[] args = {String.class};
         c.getMethod("setDatabaseName", args).invoke(ds, path);
         c.getMethod("setDataSourceName", args).invoke(ds, "Apache SIS spatial metadata");
-        Shutdown.register(() -> {
-            shutdown();
-            return null;
-        });
         return ds;
     }
 
@@ -379,7 +397,7 @@ public abstract class Initializer {
             try {
                 ds.getConnection().close();     // Does the actual shutdown.
             } catch (SQLException e) {          // This is the expected exception.
-                final LogRecord record = new LogRecord(Level.CONFIG, e.getLocalizedMessage());
 // Not WARNING.
+                final LogRecord record = new LogRecord(Level.CONFIG, e.getLocalizedMessage());
     // Not WARNING.
                 record.setLoggerName(Loggers.SQL);
                 Logging.log(Initializer.class, "shutdown", record);
             }

Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/AuthorityFactories.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/AuthorityFactories.java?rev=1728152&r1=1728151&r2=1728152&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/AuthorityFactories.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/AuthorityFactories.java
[UTF-8] Tue Feb  2 15:42:03 2016
@@ -106,7 +106,7 @@ final class AuthorityFactories<T extends
         synchronized (EPSG) {
             AuthorityFactory factory = EPSG[0];
             if (factory == null) try {
-                factory = new EPSGFactory();
+                factory = new EPSGFactory(null);
             } catch (FactoryException e) {
                 final LogRecord record = new LogRecord(Level.CONFIG, e.getLocalizedMessage());
                 record.setLoggerName(Loggers.CRS_FACTORY);

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=1728152&r1=1728151&r2=1728152&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] Tue Feb  2 15:42:03 2016
@@ -55,6 +55,13 @@ import java.nio.file.Path;
  * when first needed using the {@link DataSource} specified at construction time. The geodetic
objects are cached
  * for reuse and the idle connections are closed after a timeout.
  *
+ * <div class="section">EPSG dataset creation</div>
+ * This class tries to automatically detect in which database schema are located the EPSG
tables
+ * (see {@link SQLTranslator} for information on the search process). If the tables are not
found,
+ * then the {@link #install(Connection)} method will be invoked for creating the EPSG schema.
+ * The {@code install(…)} method can perform its work only if the definition files are
reachable
+ * on the classpath, or if the directory containing the files have been specified.
+ *
  * <div class="section">Note for subclasses</div>
  * If there is no cached object for a given code, then {@code EPSGFactory} creates an {@link
EPSGDataAccess} instance
  * for performing the actual creation work. Developers who need to customize the geodetic
object creation can override
@@ -117,6 +124,17 @@ public class EPSGFactory extends Concurr
     protected final MathTransformFactory mtFactory;
 
     /**
+     * The database schema where the EPSG tables are located, or {@code null} if no schema.
+     */
+    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.
+     */
+    private final Path scriptDirectory;
+
+    /**
      * The translator from the SQL statements using MS-Access dialect to SQL statements using
the dialect
      * of the actual database. If null, will be created when first needed.
      */
@@ -127,72 +145,110 @@ public class EPSGFactory extends Concurr
      *
      * @see #getLocale()
      */
-    private volatile Locale locale;
+    private final Locale locale;
 
     /**
-     * Creates a factory using the default data source and object factories.
-     * Invoking this constructor is equivalent to invoking the constructor below with a all
arguments set to null.
-     *
-     * @throws FactoryException if the data source can not be obtained.
-     */
-    public EPSGFactory() throws FactoryException {
-        this(null, null, null, null, null, null, null);
-    }
-
-    /**
-     * Creates a factory using the given data source and object factories.
-     *
-     * <div class="section">Default argument values</div>
-     * Any or all arguments given to this constructor can be {@code null}, in which case
default values are used.
+     * Creates a factory using the given configuration. The properties recognized by this
constructor
+     * are listed in the table below. Any property not listed below will be ignored by this
constructor.
+     * All properties are optional and can {@code null} or omitted, in which case default
values are used.
      * Those default values are implementation-specific and may change in any future SIS
version.
      *
-     * @param dataSource    The factory to use for creating {@link Connection}s to the EPSG
database.
-     * @param nameFactory   The factory to use for creating {@link org.opengis.util.GenericName}
instances.
-     * @param datumFactory  The factory to use for creating {@link Datum} instances.
-     * @param csFactory     The factory to use for creating {@link CoordinateSystem} instances.
-     * @param crsFactory    The factory to use for creating {@link CoordinateReferenceSystem}
instances.
-     * @param copFactory    The factory to use for creating {@link CoordinateOperation} instances.
-     * @param mtFactory     The factory to use for creating {@link MathTransform} instances.
+     * <table class="sis">
+     *  <caption>Recognized properties</caption>
+     *  <tr>
+     *   <th>Key</th>
+     *   <th>Value class</th>
+     *   <th>Description</th>
+     *  </tr><tr>
+     *   <td>{@code dataSource}</td>
+     *   <td>{@link DataSource}</td>
+     *   <td>The factory to use for creating {@link Connection}s to the EPSG database.</td>
+     *  </tr><tr>
+     *   <td>{@code nameFactory}</td>
+     *   <td>{@link NameFactory}</td>
+     *   <td>The factory to use for creating {@link org.opengis.util.GenericName} instances.</td>
+     *  </tr><tr>
+     *   <td>{@code datumFactory}</td>
+     *   <td>{@link DatumAuthorityFactory}</td>
+     *   <td>The factory to use for creating {@link Datum} instances.</td>
+     *  </tr><tr>
+     *   <td>{@code csFactory}</td>
+     *   <td>{@link CSAuthorityFactory}</td>
+     *   <td>The factory to use for creating {@link CoordinateSystem} instances.</td>
+     *  </tr><tr>
+     *   <td>{@code crsFactory}</td>
+     *   <td>{@link CRSAuthorityFactory}</td>
+     *   <td>The factory to use for creating {@link CoordinateReferenceSystem} instances.</td>
+     *  </tr><tr>
+     *   <td>{@code copFactory}</td>
+     *   <td>{@link CoordinateOperationAuthorityFactory}</td>
+     *   <td>The factory to use for creating {@link CoordinateOperation} instances.</td>
+     *  </tr><tr>
+     *   <td>{@code mtFactory}</td>
+     *   <td>{@link MathTransformFactory}</td>
+     *   <td>The factory to use for creating {@link MathTransform} instances.</td>
+     *  </tr><tr>
+     *   <td>{@code schema}</td>
+     *   <td>{@link String}</td>
+     *   <td>The database schema where the EPSG tables are located (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 where the EPSG definition files are located (see {@linkplain
#install install}).</td>
+     *  </tr><tr>
+     *   <td>{@code locale}</td>
+     *   <td>{@link Locale}</td>
+     *   <td>The locale for producing error messages on a <cite>best effort</cite>
basis.</td>
+     *  </tr>
+     * </table>
+     *
+     * @param  properties The data source, authority factories and other configuration properties,
+     *                    or {@code null} for the default values.
+     * @throws ClassCastException if a property value is not of the expected class.
+     * @throws IllegalArgumentException if a property value is invalid.
      * @throws FactoryException if an error occurred while creating the EPSG factory.
      */
-    public EPSGFactory(final DataSource                 dataSource,
-                       final NameFactory                nameFactory,
-                       final DatumFactory               datumFactory,
-                       final CSFactory                  csFactory,
-                       final CRSFactory                 crsFactory,
-                       final CoordinateOperationFactory copFactory,
-                       final MathTransformFactory       mtFactory)
-            throws FactoryException
-    {
+    public EPSGFactory(Map<String,?> properties) throws FactoryException {
         super(EPSGDataAccess.class);
-        if (dataSource != null) {
-            this.dataSource = dataSource;
-        } else try {
-            this.dataSource = Initializer.getDataSource();
-            if (this.dataSource == null) {
-                throw new UnavailableFactoryException(Initializer.unspecified(null));
+        if (properties == null) {
+            properties = Collections.emptyMap();
+        }
+        DataSource ds   = (DataSource) properties.get("dataSource");
+        Locale locale   = ObjectConverters.convert(properties.get("locale"), Locale.class);
+        String schema   = ObjectConverters.convert(properties.get("schema"), String.class);
+        scriptDirectory = ObjectConverters.convert(properties.get("scriptDirectory"), Path.class);
+        if (locale == null) {
+            locale = Locale.getDefault(Locale.Category.DISPLAY);
+        }
+        if (schema == null && !properties.containsKey("schema")) {
+            schema = Constants.EPSG;
+        }
+        this.locale = locale;
+        this.schema = schema;
+        if (ds == null) try {
+            ds = Initializer.getDataSource();
+            if (ds == null) {
+                throw new UnavailableFactoryException(Initializer.unspecified(locale));
             }
         } catch (Exception e) {
             throw new UnavailableFactoryException(e.getLocalizedMessage(), e);
         }
-        this.nameFactory  = factory(NameFactory.class, nameFactory);
-        this.datumFactory = factory(DatumFactory.class, datumFactory);
-        this.csFactory    = factory(CSFactory.class, csFactory);
-        this.crsFactory   = factory(CRSFactory.class, crsFactory);
-        this.copFactory   = factory(CoordinateOperationFactory.class, copFactory);
-        this.mtFactory    = factory(MathTransformFactory.class, mtFactory);
-        this.locale       = Locale.getDefault(Locale.Category.DISPLAY);
+        dataSource   = ds;
+        nameFactory  = factory(NameFactory.class,                "nameFactory",  properties);
+        datumFactory = factory(DatumFactory.class,               "datumFactory", properties);
+        csFactory    = factory(CSFactory.class,                  "csFactory",    properties);
+        crsFactory   = factory(CRSFactory.class,                 "crsFactory",   properties);
+        copFactory   = factory(CoordinateOperationFactory.class, "copFactory",   properties);
+        mtFactory    = factory(MathTransformFactory.class,       "mtFactory",    properties);
         super.setTimeout(10, TimeUnit.SECONDS);
     }
 
     /**
-     * Returns the given factory if non-null, or the default factory instance otherwise.
+     * Returns the factory for the given key if it exists, or the default factory instance
otherwise.
      */
-    private static <F> F factory(final Class<F> type, F factory) {
-        if (factory == null) {
-            factory = DefaultFactories.forBuildin(type);
-        }
-        return factory;
+    private static <F> F factory(final Class<F> type, final String key, final
Map<String,?> properties) {
+        final F factory = type.cast(properties.get(key));
+        return (factory != null) ? factory : DefaultFactories.forBuildin(type);
     }
 
     /**
@@ -217,27 +273,15 @@ public class EPSGFactory extends Concurr
     }
 
     /**
-     * Sets the locale to use for producing error messages.
-     * The given locale will be honored on a <cite>best effort</cite> basis.
-     * It does not change the way data are read from the EPSG database.
-     *
-     * @param locale The new locale to use for error message.
-     */
-    public void setLocale(final Locale locale) {
-        ArgumentChecks.ensureNonNull("locale", locale);
-        this.locale = locale;
-    }
-
-    /**
      * Creates the EPSG schema in the database and populates the tables with geodetic definitions.
      * This method is invoked automatically when {@link #newDataAccess()} detects that the
EPSG dataset is not installed.
-     * Users can also invoke this method explicitely if they wish to install the dataset
with custom properties.
+     * Users can also invoke this method explicitely if they wish to force the dataset installation.
      *
-     * <p>The {@code properties} map is optional.
-     * If non-null, the following properties are recognized (all other properties are ignored):</p>
+     * <p>This method uses the following properties from the map specified at
+     * {@linkplain #EPSGFactory(Map) construction time}:</p>
      *
      * <ul class="verbose">
-     *   <li><b>{@code schema}:</b>
+     *   <li><b>{@code schema}:</b><br>
      *     a {@link String} giving the name of the database schema where to create the tables.
      *     That schema shall not exist prior this method call as it will be created by this
{@code install(…)} method.
      *     If no schema is specified or if the schema is null, then the tables will be created
without schema.
@@ -245,7 +289,7 @@ public class EPSGFactory extends Concurr
      *     schema in table definitions} or in {@linkplain DatabaseMetaData#supportsSchemasInDataManipulation()
      *     data manipulation}, then this property is ignored.</li>
      *
-     *   <li><b>{@code scriptDirectory}:</b>
+     *   <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).
@@ -262,17 +306,11 @@ public class EPSGFactory extends Concurr
      * See <a href="https://issues.apache.org/jira/browse/LEGAL-183">LEGAL-183</a>
for more information.</p>
      *
      * @param  connection Connection to the database where to create the EPSG schema.
-     * @param  properties Properties controlling the schema name and location of SQL scripts,
or {@code null} if none.
      * @throws IOException if the SQL script can not be found or an I/O error occurred while
reading them.
      * @throws SQLException if an error occurred while writing to the database.
      */
-    public synchronized void install(final Connection connection, Map<?,?> properties)
throws IOException, SQLException {
+    public synchronized void install(final Connection connection) throws IOException, SQLException
{
         ArgumentChecks.ensureNonNull("connection", connection);
-        if (properties == null) {
-            properties = Collections.emptyMap();
-        }
-        final String schema = ObjectConverters.convert(properties.get("schema"), String.class);
-        final Path scriptDirectory = ObjectConverters.convert(properties.get("scriptDirectory"),
Path.class);
         try (EPSGInstaller installer = new EPSGInstaller(connection)) {
             final boolean ac = connection.getAutoCommit();
             if (ac) {
@@ -310,7 +348,7 @@ public class EPSGFactory extends Concurr
      * <ol>
      *   <li>Gets a new connection from the {@link #dataSource}.</li>
      *   <li>If this method is invoked for the first time, verifies if the EPSG tables
exists.
-     *       If the tables are not found, invokes {@link #install(Connection, Map)}.</li>
+     *       If the tables are not found, invokes {@link #install(Connection)}.</li>
      *   <li>Delegates to {@link #newDataAccess(Connection, SQLTranslator)}, which
provides an easier
      *       overriding point for subclasses wanting to return a custom {@link EPSGDataAccess}
instance.</li>
      * </ol>
@@ -332,7 +370,7 @@ public class EPSGFactory extends Concurr
                         tr = new SQLTranslator(connection.getMetaData());
                         try {
                             if (!tr.isSchemaFound()) {
-                                install(connection, Collections.singletonMap("schema", Constants.EPSG));
+                                install(connection);
                                 tr.setSchemaFound(connection.getMetaData());   // Set only
on success.
                             }
                         } finally {

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/GIGS2001.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/GIGS2001.java?rev=1728152&r1=1728151&r2=1728152&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/GIGS2001.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/GIGS2001.java
[UTF-8] Tue Feb  2 15:42:03 2016
@@ -73,7 +73,7 @@ public final strictfp class GIGS2001 ext
     @BeforeClass
     public static void createFactory() throws FactoryException {
         if (INSTANCE == null) try {
-            INSTANCE = new EPSGFactory();
+            INSTANCE = new EPSGFactory(null);
         } catch (UnavailableFactoryException e) {
             final String message = e.toString();
             if (!message.equals(failure)) {

Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java?rev=1728152&r1=1728151&r2=1728152&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/factory/sql/EPSGFactoryTest.java
[UTF-8] Tue Feb  2 15:42:03 2016
@@ -16,9 +16,11 @@
  */
 package org.apache.sis.referencing.factory.sql;
 
+import java.util.Map;
 import java.util.Set;
 import java.util.List;
 import java.util.Locale;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Collections;
 import javax.measure.unit.Unit;
@@ -102,8 +104,12 @@ public final strictfp class EPSGFactoryT
     @BeforeClass
     public static void createFactory() throws FactoryException {
         final GeodeticObjectFactory f = new GeodeticObjectFactory();
+        final Map<String,Object> properties = new HashMap<>(6);
+        assertNull(properties.put("datumFactory", f));
+        assertNull(properties.put("csFactory", f));
+        assertNull(properties.put("crsFactory", f));
         try {
-            factory = new EPSGFactory(null, null, f, f, f, null, null);
+            factory = new EPSGFactory(properties);
         } catch (UnavailableFactoryException e) {
             Logging.getLogger(Loggers.CRS_FACTORY).warning(e.toString());
             // Leave INSTANCE to null. This will have the effect of skipping tests.



Mime
View raw message