Author: desruisseaux
Date: Wed Oct 4 16:02:45 2017
New Revision: 1811099
URL: http://svn.apache.org/viewvc?rev=1811099&view=rev
Log:
Change needed for the support of a "non-free:sis-embedded-data" module with
EPSG geodetic dataset as an embedded Derby database (SIS-337).
Modified:
sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/ResourcesDownloader.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/metadata/sql/TestDatabase.java
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/InstallationResources.java
sis/branches/JDK8/pom.xml
Modified:
sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/ResourcesDownloader.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/ResourcesDownloader.java?rev=1811099&r1=1811098&r2=1811099&view=diff
==============================================================================
---
sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/ResourcesDownloader.java
[UTF-8] (original)
+++
sis/branches/JDK8/application/sis-console/src/main/java/org/apache/sis/console/ResourcesDownloader.java
[UTF-8] Wed Oct 4 16:02:45 2017
@@ -51,7 +51,7 @@ import static org.apache.sis.internal.ut
* </ul>
*
* @author Martin Desruisseaux (Geomatys)
- * @version 0.7
+ * @version 0.8
* @since 0.7
* @module
*/
@@ -264,6 +264,26 @@ public class ResourcesDownloader extends
}
/**
+ * Returns an installation resource for the given authority.
+ * If that question has not already been asked, this method asks to the
user if (s)he accepts
+ * EPSG terms of use. If (s)he refuses, an {@link AccessDeniedException}
will be thrown.
+ *
+ * @param authority one of the values returned by {@link
#getAuthorities()}.
+ * @param index index of the resource to get, from 0 inclusive to
+ * <code>{@linkplain #getResourceNames(String)
getResourceNames}(authority).length</code> exclusive.
+ * @return the resource as an URL or any other type, at implementation
choice.
+ * @throws IllegalArgumentException if the given {@code authority}
argument is not one of the expected values.
+ * @throws IndexOutOfBoundsException if the given {@code resource}
argument is out of bounds.
+ * @throws IOException if an error occurred while fetching the resource.
+ *
+ * @since 0.8
+ */
+ @Override
+ public Object getResource(final String authority, final int index) throws
IOException {
+ return provider(authority, true).getResource(authority, index);
+ }
+
+ /**
* Returns a reader for the installation script at the given index.
* This method is invoked by {@link
org.apache.sis.referencing.factory.sql.EPSGFactory#install(Connection)}
* for getting the SQL scripts to execute during EPSG dataset installation.
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=1811099&r1=1811098&r2=1811099&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] Wed Oct 4 16:02:45 2017
@@ -58,6 +58,15 @@ import org.apache.sis.util.logging.Loggi
* META-INF/services/org.apache.sis.internal.metadata.sql.Initializer
* }
*
+ * {@code Initializer} implementations should define the following methods:
+ *
+ * <ul>
+ * <li>{@link #createSchema(Connection)} — invoked when a new database is
created.</li>
+ * <li>{@link #dataSourceChanged()} — invoked when the data source
changed.</li>
+ * </ul>
+ *
+ * All other methods are related to getting the {@code DataSource} instance,
through JNDI or otherwise.
+ *
* @author Martin Desruisseaux (Geomatys)
* @version 0.8
* @since 0.7
@@ -67,8 +76,11 @@ public abstract class Initializer {
/**
* Name of the database to open in the {@code $SIS_DATA/Databases}
directory or the directory given by
* the {@code derby.system.home} property.
+ *
+ * <div class="note"><b>Note:</b>
+ * this field is public for the needs of {@code
non-free:sis-embedded-data} module.</div>
*/
- private static final String DATABASE = "SpatialMetadata";
+ public static final String DATABASE = "SpatialMetadata";
/**
* The property name for the home of Derby databases.
@@ -449,10 +461,13 @@ public abstract class Initializer {
/**
* Returns {@code true} if the given exception is the one that we expect
in successful shutdown of a Derby database.
*
+ * <div class="note"><b>Note:</b>
+ * this method is public for the needs of {@code
non-free:sis-embedded-data} module.</div>
+ *
* @param e the exception thrown by Derby.
* @return {@code true} if the exception indicates a successful shutdown.
*/
- static boolean isSuccessfulShutdown(final SQLException e) {
+ public static boolean isSuccessfulShutdown(final SQLException e) {
final String state = e.getSQLState();
return "08006".equals(state) || // Database 'SpatialMetadata'
shutdown.
"XJ004".equals(state); // Database 'SpatialMetadata' not
found (may happen if we failed to open it in the first place).
Modified:
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java?rev=1811099&r1=1811098&r2=1811099&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
[UTF-8] Wed Oct 4 16:02:45 2017
@@ -407,6 +407,9 @@ public class MetadataSource implements A
* <li>The schema name must be {@code "metadata"}, as this is the name
used unquoted in SQL scripts.</li>
* </ul>
*
+ * Maintenance note: this method is invoked by reflection in {@code
non-free:sis-embedded-data} module.
+ * If we make this method public in a future Apache SIS version, then we
can remove the reflection code.
+ *
* @throws MetadataStoreException if an error occurred while inserting the
metadata.
*/
final synchronized void install() throws MetadataStoreException {
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=1811099&r1=1811098&r2=1811099&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] Wed Oct 4 16:02:45 2017
@@ -50,7 +50,7 @@ import static org.junit.Assume.*;
*
* <p><b>References:</b>
* <ul>
- * <li><a
href="https://db.apache.org/derby/docs/10.2/adminguide/radminembeddedserverex.html">Embedded
server example</a></li>
+ * <li><a
href="https://db.apache.org/derby/docs/10.13/adminguide/radminembeddedserverex.html">Embedded
server example</a></li>
* </ul>
*
* @author Martin Desruisseaux (Geomatys)
Modified:
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/InstallationResources.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/InstallationResources.java?rev=1811099&r1=1811098&r2=1811099&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/InstallationResources.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/setup/InstallationResources.java
[UTF-8] Wed Oct 4 16:02:45 2017
@@ -27,7 +27,7 @@ import java.io.BufferedReader;
* {@code InstallationResources} can be used for downloading large files that
may not be of interest
* to every users, or data that are subject to more restricting terms of use
than the Apache license.
*
- * <div class="note"><b>Examples:</b><ul>
+ * <div class="note"><b>Examples:</b><ul class="verbose">
* <li>The NADCON grid files provide <cite>datum shifts</cite> data for North
America.
* Since those files are in the public domain, they could be bundled in
Apache SIS.
* But the weight of those files (about 2.4 Mb) is unnecessary for users
who do not live in North America.</li>
@@ -37,8 +37,18 @@ import java.io.BufferedReader;
* are more restrictive than the Apache license and require that we inform
the users about those conditions.</li>
* </ul></div>
*
- * Some classes that depend on installation resources are:
- * {@link org.apache.sis.referencing.factory.sql.EPSGFactory}.
+ * Some authorities implemented in Apache SIS modules are listed below.
+ * In this list, {@code "Embedded"} is a pseudo-authority for an embedded
database containing EPSG and other data.
+ * The embedded database is provided as a convenience for avoiding the need to
define a {@code SIS_DATA} directory
+ * on the local machine.
+ *
+ * <table>
+ * <caption>Authorities supported by Apache SIS</caption>
+ * <tr><th>Authority</th> <th>Provided by Maven module</th>
<th>Used by class</th></tr>
+ * <tr><td>{@code "EPSG"}</td> <td>{@code
org.apache.sis.non-free:sis-epsg}</td> <td>{@link
org.apache.sis.referencing.factory.sql.EPSGFactory}</td></tr>
+ * <tr><td>{@code "Embedded"}</td> <td>{@code
org.apache.sis.non-free:sis-embedded-data}</td> <td>All the above</td></tr>
+ * </table>
+ *
* In order to allow those classes to discover which resources are available,
* {@code InstallationResources} implementations shall be declared in the
following file:
*
@@ -47,13 +57,13 @@ import java.io.BufferedReader;
* }
*
* Above registration is usually done automatically when extension modules are
added on the classpath.
- * For example adding the {@code org.apache.sis.non-free:sis-epsg} Maven
dependency as documented on
+ * For example adding the {@code org.apache.sis.non-free:sis-epsg} Maven
dependency as documented on
* the <a href="http://sis.apache.org/epsg.html">Apache SIS web site</a> is
the only step needed for
* allowing Apache SIS to read the EPSG scripts (however SIS still needs an
installation directory
* for writing the database; see above-cited web page for more information).
*
* @author Martin Desruisseaux (Geomatys)
- * @version 0.7
+ * @version 0.8
* @since 0.7
* @module
*/
@@ -69,9 +79,19 @@ public abstract class InstallationResour
* The values recognized by SIS are listed below
* (note that this list may be expanded in any future SIS versions):
*
- * <ul>
- * <li>{@code "EPSG"} for the EPSG geodetic dataset.</li>
- * </ul>
+ * <table>
+ * <caption>Authorities supported by Apache SIS</caption>
+ * <tr><th>Authority</th> <th>Resources</th></tr>
+ * <tr><td>{@code "EPSG"}</td> <td>SQL installation scripts for EPSG
geodetic dataset.</td></tr>
+ * <tr><td>{@code "Embedded"}</td> <td>Data source of embedded database
containing EPSG and other resources.</td></tr>
+ * </table>
+ *
+ * <div class="note"><b>Note:</b>
+ * {@code "Embedded"} is a pseudo-authority for an embedded database
containing EPSG and other data.
+ * This embedded database is provided by the {@code
org.apache.sis.non-free:sis-embedded-data} module
+ * as a convenience for avoiding the need to define a {@code SIS_DATA}
directory on the local machine.
+ * In this particular case, the resource is more for execution than for
installation.
+ * </div>
*
* This method may return an empty set if this {@code
InstallationResources} instance did not find the
* resources (for example because of files not found) or does not have the
permission to distribute them.
@@ -84,10 +104,19 @@ public abstract class InstallationResour
* Returns the terms of use of the resources distributed by the specified
authority, or {@code null} if none.
* The terms of use can be returned in either plain text or HTML.
*
- * <div class="note"><b>Example:</b>
- * For the {@code "EPSG"} authority, this method may return a copy of the
- * <a
href="http://www.epsg.org/TermsOfUse">http://www.epsg.org/TermsOfUse</a> page.
- * </div>
+ * <table>
+ * <caption>Licenses for some supported authorities</caption>
+ * <tr>
+ * <th>Authority</th>
+ * <th>License</th>
+ * </tr><tr>
+ * <td>{@code "EPSG"}</td>
+ * <td>A copy of the <a
href="http://www.epsg.org/TermsOfUse">http://www.epsg.org/TermsOfUse</a>
page.</td>
+ * </tr><tr>
+ * <td>{@code "Embedded"}</td>
+ * <td>Above EPSG license.</td>
+ * </tr>
+ * </table>
*
* @param authority one of the values returned by {@link
#getAuthorities()}.
* @param locale the preferred locale for the terms of use.
@@ -101,12 +130,18 @@ public abstract class InstallationResour
/**
* Returns the names of all resources of the specified authority that are
distributed by this instance.
* The resources will be used in the order they appear in the array.
+ * Examples:
*
- * <div class="note"><b>Example:</b>
- * for the {@code "EPSG"} authority, this method may return the filenames
of all SQL scripts to execute.
- * One of the first script creates tables, followed by a script that
populates tables with data,
- * followed by a script that creates foreigner keys.
- * </div>
+ * <ul class="verbose">
+ * <li><b>{@code "EPSG"}</b> authority:<br>
+ * the resource names are the filenames of all SQL scripts to execute.
One of the first script creates tables,
+ * followed by a script that populates tables with data, followed by a
script that creates foreigner keys.
+ * </li>
+ * <li><b>{@code "Embedded"}</b> pseudo-authority:<br>
+ * the database name, which is {@code "SpatialMetadata"}.
+ * When embedded, this database is read-only.
+ * </li>
+ * </ul>
*
* @param authority one of the values returned by {@link
#getAuthorities()}.
* @return the names of all resources of the given authority that are
distributed by this instance.
@@ -116,6 +151,31 @@ public abstract class InstallationResour
public abstract String[] getResourceNames(String authority) throws
IOException;
/**
+ * Returns an installation resource for the given authority, or {@code
null} if not available.
+ * The return value may be an instance of any type, at implementation
choice.
+ * This may be for example a {@link java.net.URL} referencing the actual
resource.
+ *
+ * <p>The default implementation returns {@code null}. A null value means
that the resource is fetched by
+ * {@link #openScript(String, int)} instead than this method. We do not
return {@link java.net.URL} to text
+ * files in order to ensure that the file is opened with proper character
encoding.</p>
+ *
+ * @param authority one of the values returned by {@link
#getAuthorities()}.
+ * @param index index of the resource to get, from 0 inclusive to
+ * <code>{@linkplain #getResourceNames(String)
getResourceNames}(authority).length</code> exclusive.
+ * @return the resource as an URL or any other type (at implementation
choice), or {@code null} if not available.
+ * @throws IllegalArgumentException if the given {@code authority}
argument is not one of the expected values.
+ * @throws IndexOutOfBoundsException if the given {@code resource}
argument is out of bounds.
+ * @throws IOException if an error occurred while fetching the resource.
+ *
+ * @see ClassLoader#getResource(String)
+ *
+ * @since 0.8
+ */
+ public Object getResource(String authority, int index) throws IOException {
+ return null;
+ }
+
+ /**
* Returns a reader for the resources at the given index.
* The resource may be a SQL script or any other resources readable as a
text.
* The returned {@link BufferedReader} instance shall be closed by the
caller.
Modified: sis/branches/JDK8/pom.xml
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/pom.xml?rev=1811099&r1=1811098&r2=1811099&view=diff
==============================================================================
--- sis/branches/JDK8/pom.xml (original)
+++ sis/branches/JDK8/pom.xml Wed Oct 4 16:02:45 2017
@@ -431,6 +431,11 @@ Apache SIS is a free software, Java lang
<!-- Databases -->
<dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ <version>10.13.1.1</version>
+ </dependency>
+ <dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.4.0</version>