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: Bug fix: where reading metadata from PostgreSQL, enumeration types need to be read as strings. Opportunistic documentation improvement.
Date Mon, 26 Nov 2018 10:54:16 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 68b153a  Bug fix: where reading metadata from PostgreSQL, enumeration types need
to be read as strings. Opportunistic documentation improvement.
68b153a is described below

commit 68b153ae9b0993d1cec989b769436a6bc9b6d1d0
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Mon Nov 26 11:53:18 2018 +0100

    Bug fix: where reading metadata from PostgreSQL, enumeration types need to be read as
strings.
    Opportunistic documentation improvement.
---
 .../java/org/apache/sis/metadata/sql/CachedStatement.java | 15 +++++++++++++--
 .../referencing/operation/transform/MathTransforms.java   |  7 ++++---
 .../org/apache/sis/storage/netcdf/MetadataReader.java     |  2 ++
 .../java/org/apache/sis/storage/netcdf/NetcdfStore.java   |  4 ----
 4 files changed, 19 insertions(+), 9 deletions(-)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/CachedStatement.java
b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/CachedStatement.java
index d7ff9e2..306dd04 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/CachedStatement.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/CachedStatement.java
@@ -22,6 +22,7 @@ import java.util.logging.LogRecord;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.Types;
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.logging.WarningListeners;
 import org.apache.sis.internal.system.Loggers;
@@ -44,7 +45,7 @@ import org.apache.sis.internal.system.Loggers;
  * the {@code CachedStatement} instance. This object is closed by a background thread of
{@link MetadataSource}.</div>
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.8
  * @module
  */
@@ -124,7 +125,17 @@ final class CachedStatement implements AutoCloseable {
             results = r;
             identifier = id;
         }
-        return r.getObject(attribute);
+        /*
+         * As of Java 10, enumerations have no constants defined in java.sql.Types.
+         * Consequently databases returns an implementation-specific object, e.g.
+         * org.postgresql.util.PGobject. To avoid implementation-specific code,
+         * we are better to get those enumeration values as strings.
+         */
+        final int column = r.findColumn(attribute);
+        switch (r.getMetaData().getColumnType(column)) {
+            case Types.OTHER: return r.getString(column);       // For enumeration values.
+            default:          return r.getObject(column);       // For all standard types.
+        }
     }
 
     /**
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
index 0d42310..0236156 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
@@ -156,12 +156,13 @@ public final class MathTransforms extends Static {
 
     /**
      * Returns a linear (usually affine) transform which approximates the given transform
in the vicinity of the given position.
-     * If the given transform is already an instance of {@link LinearTransform}, then it
is returned.
+     * If the given transform is already an instance of {@link LinearTransform}, then it
is returned as-is.
      * Otherwise an approximation for the given position is created using the
      * {@linkplain MathTransform#derivative(DirectPosition) transform derivative} at that
position.
      *
-     * <p><b>Invariant:</b> transforming the given position using the given
transform produces the same result
-     * (ignoring rounding error) than transforming the same position using the returned transform.</p>
+     * <p><b>Invariant:</b> transforming the given {@code position} using
the given {@code transform} produces the same result
+     * (ignoring rounding error) than transforming the same {@code position} using the returned
transform. This invariant holds
+     * only for that particular position; the transformation of any other positions may produce
different results.</p>
      *
      * @param  transform  the transform to approximate by an affine transform.
      * @param  position   position in source CRS around which to get the an affine transform
approximation.
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
index df50a78..1e64841 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
@@ -1013,6 +1013,7 @@ split:  while ((start = CharSequences.skipLeadingWhitespaces(value,
start, lengt
 
     /**
      * Creates an ISO {@code Metadata} object from the information found in the netCDF file.
+     * The returned metadata is unmodifiable, for allowing the caller to share a unique instance.
      *
      * @return the ISO metadata object.
      * @throws IOException if an I/O operation was necessary but failed.
@@ -1063,6 +1064,7 @@ split:  while ((start = CharSequences.skipLeadingWhitespaces(value,
start, lengt
         final DefaultMetadata metadata = build(false);
         metadata.setMetadataStandards(Citations.ISO_19115);
         addCompleteMetadata(createURI(stringValue(METADATA_LINK)));
+        metadata.transition(DefaultMetadata.State.FINAL);
         return metadata;
     }
 }
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java
index 5b4c071..e7838fa 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/NetcdfStore.java
@@ -34,7 +34,6 @@ import org.apache.sis.storage.Aggregate;
 import org.apache.sis.internal.netcdf.Decoder;
 import org.apache.sis.internal.storage.URIDataStore;
 import org.apache.sis.internal.util.UnmodifiableArrayList;
-import org.apache.sis.metadata.ModifiableMetadata;
 import org.apache.sis.setup.OptionKey;
 import org.apache.sis.storage.Resource;
 import org.apache.sis.storage.event.ChangeEvent;
@@ -181,9 +180,6 @@ public class NetcdfStore extends DataStore implements Aggregate {
         if (metadata == null) try {
             final MetadataReader reader = new MetadataReader(decoder);
             metadata = reader.read();
-            if (metadata instanceof ModifiableMetadata) {
-                ((ModifiableMetadata) metadata).transition(ModifiableMetadata.State.FINAL);
-            }
         } catch (IOException | ArithmeticException e) {
             throw new DataStoreException(e);
         }


Mime
View raw message