sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 01/03: Split the Create.sql script in two parts: Citations.sql and Contents.sql. The former is for constants in Citations class, while the second is for storage modules.
Date Wed, 25 Jul 2018 17:33:17 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

commit f3934dd649a13ed309bd3e0ccd4dbb5c1766ed8d
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Wed Jul 25 10:28:34 2018 +0200

    Split the Create.sql script in two parts: Citations.sql and Contents.sql.
    The former is for constants in Citations class, while the second is for storage modules.
---
 .../org/apache/sis/metadata/sql/Installer.java     |   7 +-
 .../apache/sis/metadata/sql/MetadataFallback.java  |   2 +-
 .../sis/metadata/sql/{Create.sql => Citations.sql} | 229 +++++++++------------
 .../org/apache/sis/metadata/sql/Contents.sql       |  60 ++++++
 .../sis/metadata/sql/MetadataFallbackVerifier.java |   2 +-
 5 files changed, 162 insertions(+), 138 deletions(-)

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 6a0c53f..2f90497 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
@@ -51,7 +51,7 @@ final class Installer extends ScriptRunner {
             enumTypes = null;
         } else {
             enumTypes = new String[] {
-                "RoleCode", "DateTypeCode", "PresentationFormCode", "OnLineFunctionCode"
+                "RoleCode", "DateTypeCode", "PresentationFormCode", "OnLineFunctionCode",
"TransferFunctionTypeCode"
             };
             for (int i=0; i<enumTypes.length; i++) {
                 enumTypes[i] = "metadata.\"" + enumTypes[i] + '"';
@@ -60,10 +60,11 @@ final class Installer extends ScriptRunner {
     }
 
     /**
-     * Runs the installation script.
+     * Runs the installation scripts.
      */
     public void run() throws IOException, SQLException {
-        run(Installer.class, "Create.sql");
+        run(Installer.class, "Citations.sql");
+        run(Installer.class, "Contents.sql");
     }
 
     /**
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataFallback.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataFallback.java
index 4c3ef6a..0fc0514 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataFallback.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataFallback.java
@@ -97,7 +97,7 @@ final class MetadataFallback extends MetadataSource {
     /**
      * Returns the build-in citation for the given primary key, or {@code null}.
      * The content in this method should be consistent with the content provided
-     * in the {@code "Create.sql"} script (this is verified by JUnit tests).
+     * in the {@code "Citations.sql"} script (this is verified by JUnit tests).
      *
      * @param  key  the primary key of the desired citation.
      * @return the requested citation, or {@code null} if unknown.
diff --git a/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Create.sql b/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Citations.sql
similarity index 84%
rename from core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Create.sql
rename to core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Citations.sql
index 57bfa75..ee95cb5 100644
--- a/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Create.sql
+++ b/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Citations.sql
@@ -3,134 +3,36 @@
 -- http://www.apache.org/licenses/LICENSE-2.0
 --
 
+--
+-- This script creates some tables needed for SIS pre-defined Citation constants.
+-- We do not need to create all tables or all table columns here; missing tables
+-- and columns will be added on-the-fly by SIS as needed. Enumeration values are
+-- replaced by VARCHAR on databases that do not support the ENUM type.
+--
+-- In this schema, the following arbitrary lengths are used:
+--
+--   VARCHAR(15)  for primary keys or foreigner keys.
+--   VARCHAR(120) for character sequences.
+--
 CREATE SCHEMA metadata;
 GRANT USAGE ON SCHEMA metadata TO PUBLIC;
 COMMENT ON SCHEMA metadata IS 'ISO 19115 metadata';
 
 
+
 --
--- CodeLists are represented as enumeration on PostgreSQL.
--- Those declarations will be omitted on databases that do
--- no support enumerations; VARCHAR is used instead.
+-- All URLs referenced in this SQL file. Unless otherwise specified, the function of all
those URLs
+-- is 'information'. URLs may appear in citations or in contact information of responsible
parties.
 --
-CREATE TYPE metadata."PresentationFormCode" AS ENUM (
-  'documentDigital', 'documentHardcopy',
-  'imageDigital',    'imageHardcopy',
-  'mapDigital',      'mapHardcopy',
-  'modelDigital',    'modelHardcopy',
-  'profileDigital',  'profileHardcopy',
-  'tableDigital',    'tableHardcopy',
-  'videoDigital',    'videoHardcopy');
-
-CREATE TYPE metadata."RoleCode" AS ENUM (
-  'resourceProvider', 'custodian', 'owner', 'user', 'distributor', 'originator', 'pointOfContact',
-  'principalInvestigator', 'processor', 'publisher', 'author', 'sponsor', 'coAuthor', 'collaborator',
-  'editor', 'mediator', 'rightsHolder', 'contributor', 'funder', 'stakeholder');
-
-CREATE TYPE metadata."DateTypeCode" AS ENUM (
-  'creation', 'publication', 'revision', 'expiry', 'lastUpdate', 'lastRevision', 'nextUpdate',
-  'unavailable', 'inForce', 'adopted', 'deprecated', 'superseded', 'validityBegins', 'validityExpires',
-  'released', 'distribution');
-
 CREATE TYPE metadata."OnLineFunctionCode" AS ENUM (
   'download', 'information', 'offlineAccess', 'order', 'search', 'completeMetadata', 'browseGraphic',
   'upload', 'emailService', 'browsing', 'fileAccess');
 
-CREATE TYPE metadata."TransferFunctionTypeCode" AS ENUM (
-  'linear', 'logarithmic', 'exponential');
-
-
-
---
--- This script creates some tables needed for SIS pre-defined metadata.
--- We do not need to create all tables or all columns in tables here.
--- Missing tables and columns will be added on-the-fly by SIS as needed.
---
--- VARCHAR(15) are for primary keys or foreigner keys.
--- VARCHAR(120) are for character sequences.
---
-CREATE TABLE metadata."Identifier" (
-  "ID"        VARCHAR(15) NOT NULL PRIMARY KEY,
-  "authority" VARCHAR(15),
-  "code"      VARCHAR(120),
-  "codeSpace" VARCHAR(120),
-  "version"   VARCHAR(120));
-
-
-
-CREATE TABLE metadata."Party" (
-  "ID"   VARCHAR(15) NOT NULL PRIMARY KEY,
-  "name" VARCHAR(120));
-
-
-
---
--- "ID" and "name" columns are inherited from the "Party" parent table.
--- But we nevertheless repeat them for databases that do not support table inheritance.
--- On PostgreSQL, those duplicated declarations are merged in single columns.
---
-CREATE TABLE metadata."Organisation" (
-  "ID"   VARCHAR(15) NOT NULL PRIMARY KEY,
-  "name" VARCHAR(120))
-INHERITS (metadata."Party");
-
-
-
---
--- Foreigner key should reference the "Party" parent table, but it does not yet work on PostgreSQL
--- (tested on 9.5.13). For the purpose of this file, we need to reference "Organisation"
only.
--- This constraint can be dropped at end of this script.
---
-CREATE TABLE metadata."Responsibility" (
-  "ID"    VARCHAR(15) NOT NULL PRIMARY KEY,
-  "role"  metadata."RoleCode",
-  "party" VARCHAR(15) REFERENCES metadata."Organisation" ("ID") ON UPDATE RESTRICT ON DELETE
RESTRICT);
-
-
-
-CREATE TABLE metadata."Date" (
-  "ID"       VARCHAR(15) NOT NULL PRIMARY KEY,
-  "date"     TIMESTAMP,
-  "dateType" metadata."DateTypeCode");
-
-
-
 CREATE TABLE metadata."OnlineResource" (
   "ID"       VARCHAR(15) NOT NULL PRIMARY KEY,
   "linkage"  VARCHAR(120),
   "function" metadata."OnLineFunctionCode");
 
-
-
-CREATE TABLE metadata."Citation" (
-  "ID"                    VARCHAR(15) NOT NULL PRIMARY KEY,
-  "title"                 VARCHAR(120),
-  "alternateTitle"        VARCHAR(120),
-  "date"                  VARCHAR(15) REFERENCES metadata."Date" ("ID") ON UPDATE RESTRICT
ON DELETE RESTRICT,
-  "edition"               VARCHAR(120),
-  "editionDate"           TIMESTAMP,
-  "identifier"            VARCHAR(15) REFERENCES metadata."Identifier"     ("ID") ON UPDATE
RESTRICT ON DELETE RESTRICT,
-  "citedResponsibleParty" VARCHAR(15) REFERENCES metadata."Responsibility" ("ID") ON UPDATE
RESTRICT ON DELETE RESTRICT,
-  "presentationForm"      metadata."PresentationFormCode",
-  "onlineResource"        VARCHAR(15) REFERENCES metadata."OnlineResource" ("ID") ON UPDATE
RESTRICT ON DELETE RESTRICT);
-
-ALTER TABLE metadata."Identifier" ADD CONSTRAINT fk_identifier_citation
-FOREIGN KEY ("authority") REFERENCES metadata."Citation" ("ID") ON UPDATE RESTRICT ON DELETE
RESTRICT;
-
-
-
-CREATE TABLE metadata."Format" (
-  "ID"                          VARCHAR(15) NOT NULL PRIMARY KEY,
-  "formatSpecificationCitation" VARCHAR(15) REFERENCES metadata."Citation" ("ID") ON UPDATE
RESTRICT ON DELETE RESTRICT,
-  "amendmentNumber"             VARCHAR(120),
-  "fileDecompressionTechnique"  VARCHAR(120));
-
-
-
---
--- All URLs referenced in this SQL file. Unless otherwise specified, the function of all
those URLs
--- is 'information'. URLs may appear in citations or in contact information of responsible
parties.
---
 INSERT INTO metadata."OnlineResource" ("ID", "linkage") VALUES
   ('EPSG',    'http://www.epsg.org/'),
   ('ESRI',    'http://www.esri.com/'),
@@ -153,6 +55,40 @@ INSERT INTO metadata."OnlineResource" ("ID", "linkage") VALUES
 UPDATE metadata."OnlineResource" SET "function" = 'information';
 
 
+
+--
+-- The "ID" and "name" columns in "Organisation" table are inherited from the "Party" parent
table.
+-- But we nevertheless repeat those columns for databases that do not support table inheritance.
+-- On PostgreSQL, those duplicated declarations are merged in single columns.
+--
+CREATE TABLE metadata."Party" (
+  "ID"   VARCHAR(15) NOT NULL PRIMARY KEY,
+  "name" VARCHAR(120));
+
+CREATE TABLE metadata."Organisation" (
+  "ID"   VARCHAR(15) NOT NULL PRIMARY KEY,
+  "name" VARCHAR(120))
+INHERITS (metadata."Party");
+
+CREATE TYPE metadata."RoleCode" AS ENUM (
+  'resourceProvider', 'custodian', 'owner', 'user', 'distributor', 'originator', 'pointOfContact',
+  'principalInvestigator', 'processor', 'publisher', 'author', 'sponsor', 'coAuthor', 'collaborator',
+  'editor', 'mediator', 'rightsHolder', 'contributor', 'funder', 'stakeholder');
+
+
+
+--
+-- Foreigner key should reference the "Party" parent table, but it does not yet work on PostgreSQL
+-- (tested on 9.5.13). For the purpose of this file, we need to reference "Organisation"
only.
+-- This constraint can be dropped at end of the installation scripts.
+--
+CREATE TABLE metadata."Responsibility" (
+  "ID"    VARCHAR(15) NOT NULL PRIMARY KEY,
+  "role"  metadata."RoleCode",
+  "party" VARCHAR(15) REFERENCES metadata."Organisation" ("ID") ON UPDATE RESTRICT ON DELETE
RESTRICT);
+
+
+
 --
 -- All parties referenced in this SQL file. We currently have only organisations, no individuals.
 -- This SQL file has a one-to-one relationship between "Party" (organisation) and "Responsibility"
@@ -187,6 +123,52 @@ INSERT INTO metadata."Responsibility" ("ID", "party", "role") VALUES
 
 
 --
+-- Definition of the Citations and its dependencies.
+--
+CREATE TYPE metadata."DateTypeCode" AS ENUM (
+  'creation', 'publication', 'revision', 'expiry', 'lastUpdate', 'lastRevision', 'nextUpdate',
+  'unavailable', 'inForce', 'adopted', 'deprecated', 'superseded', 'validityBegins', 'validityExpires',
+  'released', 'distribution');
+
+CREATE TABLE metadata."Date" (
+  "ID"       VARCHAR(15) NOT NULL PRIMARY KEY,
+  "date"     TIMESTAMP,
+  "dateType" metadata."DateTypeCode");
+
+CREATE TYPE metadata."PresentationFormCode" AS ENUM (
+  'documentDigital', 'documentHardcopy',
+  'imageDigital',    'imageHardcopy',
+  'mapDigital',      'mapHardcopy',
+  'modelDigital',    'modelHardcopy',
+  'profileDigital',  'profileHardcopy',
+  'tableDigital',    'tableHardcopy',
+  'videoDigital',    'videoHardcopy');
+
+CREATE TABLE metadata."Identifier" (
+  "ID"        VARCHAR(15) NOT NULL PRIMARY KEY,
+  "authority" VARCHAR(15),
+  "code"      VARCHAR(120),
+  "codeSpace" VARCHAR(120),
+  "version"   VARCHAR(120));
+
+CREATE TABLE metadata."Citation" (
+  "ID"                    VARCHAR(15) NOT NULL PRIMARY KEY,
+  "title"                 VARCHAR(120),
+  "alternateTitle"        VARCHAR(120),
+  "date"                  VARCHAR(15) REFERENCES metadata."Date" ("ID") ON UPDATE RESTRICT
ON DELETE RESTRICT,
+  "edition"               VARCHAR(120),
+  "editionDate"           TIMESTAMP,
+  "identifier"            VARCHAR(15) REFERENCES metadata."Identifier"     ("ID") ON UPDATE
RESTRICT ON DELETE RESTRICT,
+  "citedResponsibleParty" VARCHAR(15) REFERENCES metadata."Responsibility" ("ID") ON UPDATE
RESTRICT ON DELETE RESTRICT,
+  "presentationForm"      metadata."PresentationFormCode",
+  "onlineResource"        VARCHAR(15) REFERENCES metadata."OnlineResource" ("ID") ON UPDATE
RESTRICT ON DELETE RESTRICT);
+
+ALTER TABLE metadata."Identifier" ADD CONSTRAINT fk_identifier_citation
+FOREIGN KEY ("authority") REFERENCES metadata."Citation" ("ID") ON UPDATE RESTRICT ON DELETE
RESTRICT;
+
+
+
+--
 -- Specifications, data or softwares referenced by the "Citations" class.
 -- Those citations are not organizations; they are resources published by
 -- organizations. Each identifier codespace identifies the organization.
@@ -224,6 +206,8 @@ INSERT INTO metadata."Citation" ("ID", "onlineResource", "edition", "citedRespon
   ('Proj4',      'Proj4', NULL,                 'OSGeo',   NULL,             'Proj',    
    'PROJ coordinate transformation software library'),
   ('SIS',        'SIS',   NULL,                 'Apache',  NULL,             'Apache SIS',
  'Apache Spatial Information System');
 
+
+
 --
 -- Citations for organizations. They should not be citations; they are "responsible parties"
instead.
 -- But we have to declare some organizations as "citations" because this is the kind of object
required
@@ -242,24 +226,3 @@ INSERT INTO metadata."Citation" ("ID", "onlineResource", "citedResponsibleParty"
   ('IOGP', 'IOGP',  'IOGP', 'documentDigital', 'IOGP Surveying and Positioning Guidance Note
7');
 
 UPDATE metadata."Citation" SET "identifier" = "ID" WHERE "ID"<>'ISBN' AND "ID"<>'ISSN'
AND "ID"<>'MGRS';
-
-
-
---
--- File formats. Those entries are referenced by DataStore implementations.
---
-INSERT INTO metadata."Citation" ("ID", "alternateTitle", "title") VALUES
-  ('GeoTIFF', 'GeoTIFF', 'GeoTIFF Coverage Encoding Profile'),
-  ('NetCDF',  'NetCDF',  'NetCDF Classic and 64-bit Offset Format'),
-  ('PNG',     'PNG',     'PNG (Portable Network Graphics) Specification'),
-  ('CSV',     'CSV',     'Common Format and MIME Type for Comma-Separated Values (CSV) Files'),
-  ('CSV-MF',  'CSV',     'OGC Moving Features Encoding Extension: Simple Comma-Separated
Values (CSV)'),
-  ('GPX',     'GPX',     'GPS Exchange Format');
-
-INSERT INTO metadata."Format" ("ID", "formatSpecificationCitation") VALUES
-  ('GeoTIFF', 'GeoTIFF'),
-  ('NetCDF',  'NetCDF'),
-  ('PNG',     'PNG'),
-  ('CSV',     'CSV'),
-  ('CSV-MF',  'CSV-MF'),
-  ('GPX',     'GPX');
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
new file mode 100644
index 0000000..4b7125d
--- /dev/null
+++ b/core/sis-metadata/src/main/resources/org/apache/sis/metadata/sql/Contents.sql
@@ -0,0 +1,60 @@
+--
+-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license
agreements.
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+
+--
+-- Definition of file formats. Those entries are referenced by DataStore implementations.
+-- This script requires "Citations.sql" to be executed first.
+--
+CREATE TABLE metadata."Format" (
+  "ID"                          VARCHAR(15) NOT NULL PRIMARY KEY,
+  "formatSpecificationCitation" VARCHAR(15) REFERENCES metadata."Citation" ("ID") ON UPDATE
RESTRICT ON DELETE RESTRICT,
+  "amendmentNumber"             VARCHAR(120),
+  "fileDecompressionTechnique"  VARCHAR(120));
+
+INSERT INTO metadata."Citation" ("ID", "alternateTitle", "title") VALUES
+  ('GeoTIFF', 'GeoTIFF', 'GeoTIFF Coverage Encoding Profile'),
+  ('NetCDF',  'NetCDF',  'NetCDF Classic and 64-bit Offset Format'),
+  ('PNG',     'PNG',     'PNG (Portable Network Graphics) Specification'),
+  ('CSV',     'CSV',     'Common Format and MIME Type for Comma-Separated Values (CSV) Files'),
+  ('CSV-MF',  'CSV',     'OGC Moving Features Encoding Extension: Simple Comma-Separated
Values (CSV)'),
+  ('GPX',     'GPX',     'GPS Exchange Format');
+
+INSERT INTO metadata."Format" ("ID", "formatSpecificationCitation") VALUES
+  ('GeoTIFF', 'GeoTIFF'),
+  ('NetCDF',  'NetCDF'),
+  ('PNG',     'PNG'),
+  ('CSV',     'CSV'),
+  ('CSV-MF',  'CSV-MF'),
+  ('GPX',     'GPX');
+
+
+
+--
+-- Description of bands in rasters. Not used directly by "sis-metadata" module,
+-- but used by some storage modules.
+--
+CREATE TYPE metadata."TransferFunctionTypeCode" AS ENUM (
+  'linear', 'logarithmic', 'exponential');
+
+CREATE TABLE metadata."RangeDimension" (
+  "ID"                 VARCHAR(15) NOT NULL PRIMARY KEY,
+  "sequenceIdentifier" VARCHAR(15),
+  "description"        VARCHAR(120)
+);
+
+CREATE TABLE metadata."SampleDimension" (
+  "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")
+INHERITS (metadata."RangeDimension");
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataFallbackVerifier.java
b/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataFallbackVerifier.java
index 3353cf3..4161629 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataFallbackVerifier.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/metadata/sql/MetadataFallbackVerifier.java
@@ -35,7 +35,7 @@ import static org.apache.sis.internal.util.CollectionsExt.first;
 
 
 /**
- * Compares the {@link MetadataFallback} hard-coded values with the {@code Create.sql} content.
+ * Compares the {@link MetadataFallback} hard-coded values with the {@code Citations.sql}
content.
  * This test is actually invoked by {@link MetadataSourceTest} in order to opportunistically
use
  * the database created by the later (i.e. for avoiding to recreate the same database many
times).
  *


Mime
View raw message