sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Documentation fixes, addition of more metadata (to be used later by sis-earthobservation module), and first step toward a https://issues.apache.org/jira/browse/SIS-395 fix.
Date Tue, 14 Aug 2018 13:36:20 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 7327706  Documentation fixes, addition of more metadata (to be used later by sis-earthobservation
module), and first step toward a https://issues.apache.org/jira/browse/SIS-395 fix.
7327706 is described below

commit 7327706e6a18dbef59718e571dddb0747c9b9846
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Tue Aug 14 15:33:52 2018 +0200

    Documentation fixes, addition of more metadata (to be used later by sis-earthobservation
module),
    and first step toward a https://issues.apache.org/jira/browse/SIS-395 fix.
---
 .../sis/internal/metadata/sql/Initializer.java     | 55 +++++++++++++++++++++-
 .../org/apache/sis/metadata/sql/Installer.java     | 13 ++++-
 .../org/apache/sis/metadata/sql/Contents.sql       | 32 +++++++++++++
 .../org/apache/sis/metadata/sql/Metadata.sql       | 15 ++++++
 .../org/apache/sis/metadata/sql/Referencing.sql    | 25 ++++++++++
 .../apache/sis/util/logging/MonolineFormatter.java |  2 +-
 .../sis/util/collection/WeakValueHashMapTest.java  |  2 +-
 7 files changed, 139 insertions(+), 5 deletions(-)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
index 0d23aae..625bbf3 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
@@ -17,13 +17,14 @@
 package org.apache.sis.internal.metadata.sql;
 
 import java.util.Locale;
+import java.util.function.Supplier;
+import java.util.concurrent.Callable;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.io.IOException;
-import java.util.concurrent.Callable;
 import java.util.logging.Level;
 import java.util.logging.LogRecord;
 import java.security.AccessController;
@@ -49,6 +50,7 @@ import org.apache.sis.internal.system.Shutdown;
 import org.apache.sis.internal.system.Loggers;
 import org.apache.sis.util.resources.Messages;
 import org.apache.sis.util.logging.Logging;
+import org.apache.sis.util.Configuration;
 
 
 /**
@@ -105,10 +107,20 @@ public abstract class Initializer {
      * a JAR file the JDK installation directory, and we presume that the JDK installation
do not change.
      *
      * @see #forJavaDB(String)
+     *
+     * @deprecated to be removed after we migrate to Java 9, since Derby is no longer distributed
with the JDK.
      */
+    @Deprecated
     private static URLClassLoader javadbLoader;
 
     /**
+     * Data source specified by the user, to be used if no data source is specified by JNDI.
+     *
+     * @see #setDefault(Supplier)
+     */
+    private static Supplier<DataSource> supplier;
+
+    /**
      * The unique, SIS-wide, data source to the {@code $SIS_DATA/Databases/SpatialMetadata}
database.
      * Created when first needed, and cleared on shutdown.
      *
@@ -145,7 +157,7 @@ public abstract class Initializer {
     /**
      * A JNDI listener for being informed of changes in the {@link DataSource} associated
to {@code "jdbc/SpatialMetadata"}.
      * This listener clears the {@link Initializer#source} field, so the next call to {@link
Initializer#getDataSource()}
-     * will fetch a new one.
+     * will fetch a new one. This listener is registered only if {@link Initializer#source}
has been fetched from JNDI.
      */
     private static final class Listener implements ObjectChangeListener, Callable<Object>
{
         /**
@@ -226,11 +238,36 @@ public abstract class Initializer {
     }
 
     /**
+     * Specifies the data source to use if there is no JNDI environment or if no data source
is binded
+     * to {@code jdbc/SpatialMetadata}. Data source specified by JNDI has precedence over
this supplier
+     * in order to let users control their data source. This method does nothing if the data
source has
+     * already been initialized.
+     *
+     * @param  ds  supplier of data source to set, or {@code null} for removing previous
supplier.
+     *             This supplier may return {@code null}, in which case it will be ignored.
+     * @return whether the given data source supplier has been successfully set.
+     *
+     * @since 1.0
+     */
+    @Configuration
+    public static synchronized boolean setDefault(final Supplier<DataSource> ds) {
+        if (source == null) {
+            supplier = ds;
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
      * Returns the data source for the SIS-wide "SpatialMetadata" database.
      * This method returns the first of the following steps that succeed:
      *
      * <ol>
      *   <li>If a JNDI context exists, the data source registered under the {@code
jdbc/SpatialMetadata} name.</li>
+     *   <li>Otherwise if a default data source {@linkplain #setDefault has been supplied},
use that data source.</li>
+     *   <li>Otherwise if the {@code non-free:sis-embedded-data} module is present
on the classpath and there is no
+     *       database already installed in the {@code SIS_DATA} directory, use the embedded
database.</li>
      *   <li>If the {@code SIS_DATA} environment variable is defined, {@code jdbc:derby:$SIS_DATA/Databases/SpatialMetadata}.
      *       This database will be created if it does not exist. Note that this is the only
case where we allow database
      *       creation since we are in the directory managed by SIS.</li>
@@ -262,6 +299,8 @@ public abstract class Initializer {
                 /*
                  * No Derby shutdown hook for DataSource fetched fron JNDI.
                  * We presume that shutdowns are handled by the container.
+                 * We do not clear the 'supplier' field in case 'source'
+                 * is cleaned by the listener.
                  */
             } catch (NameNotFoundException e) {
                 final LogRecord record = Messages.getResources(null).getLogRecord(
@@ -271,6 +310,17 @@ public abstract class Initializer {
             }
             /*
              * At this point we determined that there is no JNDI context or no object binded
to "jdbc/SpatialMetadata".
+             * Check for programmatically supplied data source. We verify only after JNDI
in order to let users control
+             * their data source if desired.
+             */
+            if (supplier != null) {
+                source = supplier.get();
+                if (source != null) {
+                    supplier = null;
+                    return source;
+                }
+            }
+            /*
              * As a fallback, try to open the Derby database located in $SIS_DATA/Databases/SpatialMetadata
directory.
              * Only if the SIS_DATA environment variable is not set, verify first if the
'sis-embedded-data' module is
              * on the classpath. Note that if SIS_DATA is defined and valid, it has precedence.
@@ -327,6 +377,7 @@ public abstract class Initializer {
                     source = forJavaDB(dbURL);
                 }
             }
+            supplier = null;        // Not needed anymore.
             /*
              * Register the shutdown hook before to attempt any operation on the database
in order to close
              * it properly if the schemas creation below fail.
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/Installer.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/Installer.java
index 2f90497..2170cab 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/Installer.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/Installer.java
@@ -27,6 +27,12 @@ import org.apache.sis.util.StringBuilders;
 /**
  * Executes the installation scripts for the "metadata" schema in the "SpatialMetadata" database.
  *
+ * @todo We should replace the SQL {@code "CREATE TABLE"} statements in SQL scripts by something
like
+ *       {@code "GENERATE TABLE"}, to be handled in a special way by this {@code Installer} class.
+ *       The {@code "GENERATE TABLE"} statement would enumerate only the columns, and this
installer
+ *       would delegate to {@link MetadataWriter} for inferring the column types and the
{@code ENUM}
+ *       dependencies.
+ *
  * @author  Martin Desruisseaux (Geomatys)
  * @version 1.0
  * @since   0.8
@@ -36,6 +42,8 @@ final class Installer extends ScriptRunner {
     /**
      * List of enumeration types to replace by {@code VARCHAR}
      * on implementations that do not support {@code ENUM} type.
+     *
+     * @todo This field can be removed if we apply the "todo" documented in class javadoc.
      */
     private final String[] enumTypes;
 
@@ -51,7 +59,8 @@ final class Installer extends ScriptRunner {
             enumTypes = null;
         } else {
             enumTypes = new String[] {
-                "RoleCode", "DateTypeCode", "PresentationFormCode", "OnLineFunctionCode",
"TransferFunctionTypeCode"
+                "RoleCode", "DateTypeCode", "PresentationFormCode", "OnLineFunctionCode",
"TransferFunctionTypeCode",
+                "AxisDirection"
             };
             for (int i=0; i<enumTypes.length; i++) {
                 enumTypes[i] = "metadata.\"" + enumTypes[i] + '"';
@@ -65,6 +74,8 @@ final class Installer extends ScriptRunner {
     public void run() throws IOException, SQLException {
         run(Installer.class, "Citations.sql");
         run(Installer.class, "Contents.sql");
+        run(Installer.class, "Metadata.sql");
+        run(Installer.class, "Referencing.sql");
     }
 
     /**
diff --git a/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Contents.sql
b/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Contents.sql
index 4b7125d..3d5fdcc 100644
--- a/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Contents.sql
+++ b/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Contents.sql
@@ -58,3 +58,35 @@ CREATE TABLE metadata."SampleDimension" (
   "offset"               DOUBLE PRECISION,
   "transferFunctionType" metadata."TransferFunctionTypeCode")
 INHERITS (metadata."RangeDimension");
+
+CREATE TABLE metadata."Band" (
+  "ID"                   VARCHAR(15) NOT NULL PRIMARY KEY,
+  "sequenceIdentifier"   VARCHAR(15),
+  "description"          VARCHAR(120),
+  "minValue"             DOUBLE PRECISION,
+  "maxValue"             DOUBLE PRECISION,
+  "meanValue"            DOUBLE PRECISION,
+  "numberOfValues"       INTEGER,
+  "standardDeviation"    DOUBLE PRECISION,
+  "units"                VARCHAR(15),
+  "scaleFactor"          DOUBLE PRECISION,
+  "offset"               DOUBLE PRECISION,
+  "transferFunctionType" metadata."TransferFunctionTypeCode",
+  "boundMin"             DOUBLE PRECISION,
+  "boundMax"             DOUBLE PRECISION,
+  "boundUnits"           VARCHAR(15),
+  "peakResponse"         DOUBLE PRECISION)
+INHERITS (metadata."SampleDimension");
+
+INSERT INTO metadata."Band" ("ID", "sequenceIdentifier", "description", "boundMin", "boundMax",
"boundUnits", "peakResponse") VALUES
+  ('Landsat 8-01',  '1', 'Ultra Blue (coastal/aerosol)',         435.0,  451.0, 'nm',   443.0),
+  ('Landsat 8-02',  '2', 'Blue',                                 452.0,  512.1, 'nm',   482.0),
+  ('Landsat 8-03',  '3', 'Green',                                532.7,  590.1, 'nm',   561.4),
+  ('Landsat 8-04',  '4', 'Red',                                  635.9,  673.3, 'nm',   654.6),
+  ('Landsat 8-05',  '5', 'Near-Infrared',                        850.5,  878.8, 'nm',   864.7),
+  ('Landsat 8-06',  '6', 'Short Wavelength Infrared (SWIR) 1',  1566.5, 1651.2, 'nm',  1608.9),
+  ('Landsat 8-07',  '7', 'Short Wavelength Infrared (SWIR) 2',  2107.4, 2294.1, 'nm',  2200.7),
+  ('Landsat 8-08',  '8', 'Panchromatic',                         503.3,  675.7, 'nm',   589.5),
+  ('Landsat 8-09',  '9', 'Cirrus',                              1363.2, 1383.6, 'nm',  1373.4),
+  ('Landsat 8-10', '10', 'Thermal Infrared Sensor (TIRS) 1',     10.60,  11.19, 'µm',  10.800),
+  ('Landsat 8-11', '11', 'Thermal Infrared Sensor (TIRS) 2',     11.50,  12.51, 'µm',  12.000);
diff --git a/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Metadata.sql
b/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Metadata.sql
new file mode 100644
index 0000000..9494ce1
--- /dev/null
+++ b/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Metadata.sql
@@ -0,0 +1,15 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license
agreements.
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+
+--
+-- Definition of main metadata table.
+-- This script requires "Citations.sql" and "Contents.sql" to be executed first.
+-- Current version contains very few columns. This will be expanded in future versions.
+--
+CREATE TABLE metadata."Metadata" (
+  "ID"                   VARCHAR(15) NOT NULL PRIMARY KEY,
+  "metadataIdentifier"   VARCHAR(15) REFERENCES metadata."Identifier"     ("ID") ON UPDATE
RESTRICT ON DELETE RESTRICT,
+  "parentMetadata"       VARCHAR(15) REFERENCES metadata."Citation"       ("ID") ON UPDATE
RESTRICT ON DELETE RESTRICT
+);
diff --git a/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Referencing.sql
b/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Referencing.sql
new file mode 100644
index 0000000..6aa2300
--- /dev/null
+++ b/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Referencing.sql
@@ -0,0 +1,25 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license
agreements.
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+
+--
+-- Definition of a few types for referencing by coordinates (ISO 19111).
+-- A database schema is already defined by the EPSG geodetic dataset.
+-- This script adds only a few enumerations to be considered as a kind
+-- of metadata.
+--
+CREATE TYPE metadata."AxisDirection" AS ENUM (
+  'north', 'northNorthEast', 'northEast', 'eastNorthEast',
+  'east',  'eastSouthEast',  'southEast', 'southSouthEast',
+  'south', 'southSouthWest', 'southWest', 'westSouthWest',
+  'west',  'westNorthWest',  'northWest', 'northNorthWest',
+  'up',    'down',
+  'geocentricX',    'geocentricY',    'geocentricZ',
+  'columnPositive', 'columnNegative', 'rowPositive', 'rowNegative',
+  'displayRight',   'displayLeft',    'displayUp',   'displayDown',
+  'forward',        'aft',
+  'port',           'starboard',
+  'clockwise',      'counterClockwise',
+  'towards',        'awayFrom',
+  'future',         'past');
diff --git a/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java
b/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java
index 706ec2d..bc460e2 100644
--- a/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java
+++ b/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java
@@ -931,7 +931,7 @@ loop:   for (int i=0; ; i++) {
      * @throws SecurityException if this method does not have the permission to install the
formatter.
      */
     @Configuration
-    public static MonolineFormatter install()  throws SecurityException {
+    public static MonolineFormatter install() throws SecurityException {
         return install(Logging.getLogger(""), null);
     }
 
diff --git a/core/sis-utility/src/test/java/org/apache/sis/util/collection/WeakValueHashMapTest.java
b/core/sis-utility/src/test/java/org/apache/sis/util/collection/WeakValueHashMapTest.java
index f779ce3..92160d8 100644
--- a/core/sis-utility/src/test/java/org/apache/sis/util/collection/WeakValueHashMapTest.java
+++ b/core/sis-utility/src/test/java/org/apache/sis/util/collection/WeakValueHashMapTest.java
@@ -106,7 +106,7 @@ public final strictfp class WeakValueHashMapTest extends TestCase {
      * Implementation of the {@link #testWeakReferences()} method,
      * to be reused by {@link CacheTest}.
      *
-     * @param weakMap The map implementation to test.
+     * @param weakMap  the map implementation to test.
      */
     @SuppressWarnings("UnnecessaryBoxing")
     static void testWeakReferences(final Map<Integer,Integer> weakMap) throws InterruptedException
{


Mime
View raw message