sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1796411 - in /sis/trunk: ./ core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataWriter.java
Date Sat, 27 May 2017 15:09:24 GMT
Author: desruisseaux
Date: Sat May 27 15:09:24 2017
New Revision: 1796411

URL: http://svn.apache.org/viewvc?rev=1796411&view=rev
Log:
Merge Enum support for JDK7 branch.

Modified:
    sis/trunk/   (props changed)
    sis/trunk/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
    sis/trunk/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataWriter.java

Propchange: sis/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sat May 27 15:09:24 2017
@@ -1,5 +1,5 @@
 /sis/branches/Android:1430670-1480699
 /sis/branches/JDK6:1394364-1758914
-/sis/branches/JDK7:1394913-1796387
-/sis/branches/JDK8:1584960-1796385
+/sis/branches/JDK7:1394913-1796407
+/sis/branches/JDK8:1584960-1796404
 /sis/branches/JDK9:1773327-1789983

Modified: sis/trunk/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java?rev=1796411&r1=1796410&r2=1796411&view=diff
==============================================================================
--- sis/trunk/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
[UTF-8] (original)
+++ sis/trunk/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
[UTF-8] Sat May 27 15:09:24 2017
@@ -622,7 +622,9 @@ public class MetadataSource implements A
              * those tables are not used in any way by the org.apache.sis.metadata.sql package.
              */
             if (metadata instanceof CodeList<?>) {
-                identifier = ((CodeList<?>) metadata).name();
+                identifier = Types.getCodeName((CodeList<?>) metadata);
+            } else if (metadata instanceof Enum<?>) {
+                identifier = ((Enum<?>) metadata).name();
             } else {
                 final String table;
                 final Map<String,Object> asMap;
@@ -685,7 +687,9 @@ public class MetadataSource implements A
              */
             if (value != null) {
                 if (value instanceof CodeList<?>) {
-                    value = ((CodeList<?>) value).name();
+                    value = Types.getCodeName((CodeList<?>) value);
+                } else if (value instanceof Enum<?>) {
+                    value = ((Enum<?>) value).name();
                 } else {
                     String dependency = proxy(value);
                     if (dependency != null) {
@@ -795,11 +799,12 @@ public class MetadataSource implements A
 
     /**
      * Returns an implementation of the specified metadata interface filled with the data
referenced
-     * by the specified identifier. Alternatively, this method can also return a {@link CodeList}
element.
+     * by the specified identifier. Alternatively, this method can also return a {@link CodeList}
or
+     * {@link Enum} element.
      *
      * @param  <T>         the parameterized type of the {@code type} argument.
      * @param  type        the interface to implement (e.g. {@link org.opengis.metadata.citation.Citation}),
-     *                     or the {@link CodeList} type.
+     *                     or the {@code ControlledVocabulary} type ({@link CodeList} or
some {@link Enum}).
      * @param  identifier  the identifier of the record for the metadata entity to be created.
      *                     This is usually the primary key of the record to search for.
      * @return an implementation of the required interface, or the code list element.
@@ -981,9 +986,9 @@ public class MetadataSource implements A
      * Returns the code of the given type and name. This method is defined for avoiding the
compiler warning
      * message when the actual class is unknown (it must have been checked dynamically by
the caller however).
      */
-    @SuppressWarnings({"unchecked","rawtypes"})
+    @SuppressWarnings("unchecked")
     private static CodeList<?> getCodeList(final Class<?> type, final String
name) {
-        return Types.forCodeName((Class) type, name, true);
+        return Types.forCodeName(type.asSubclass(CodeList.class), name, true);
     }
 
     /**

Modified: sis/trunk/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataWriter.java
URL: http://svn.apache.org/viewvc/sis/trunk/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataWriter.java?rev=1796411&r1=1796410&r2=1796411&view=diff
==============================================================================
--- sis/trunk/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataWriter.java
[UTF-8] (original)
+++ sis/trunk/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataWriter.java
[UTF-8] Sat May 27 15:09:24 2017
@@ -29,6 +29,7 @@ import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import javax.sql.DataSource;
+import java.lang.reflect.Modifier;
 
 import org.opengis.util.CodeList;
 import org.opengis.metadata.Identifier;
@@ -39,6 +40,7 @@ import org.apache.sis.util.ArgumentCheck
 import org.apache.sis.util.resources.Errors;
 import org.apache.sis.util.resources.Messages;
 import org.apache.sis.util.iso.DefaultNameSpace;
+import org.apache.sis.util.iso.Types;
 import org.apache.sis.util.collection.Containers;
 import org.apache.sis.metadata.MetadataStandard;
 import org.apache.sis.metadata.KeyNamePolicy;
@@ -305,20 +307,30 @@ public class MetadataWriter extends Meta
                     }
                 }
                 /*
-                 * Determine the column data type.
+                 * Determine the column data type. We infer that type from the method return
value, not from the
+                 * actual value for in the given metadata object, since the value type for
the same property may
+                 * be different in future calls to this method.
                  */
                 int maxLength = maximumValueLength;
                 Class<?> rt = colTypes.get(column);
-                if (CodeList.class.isAssignableFrom(rt) || standard.isMetadata(rt)) {
+                final boolean isCodeList = CodeList.class.isAssignableFrom(rt);
+                if (isCodeList || standard.isMetadata(rt)) {
                     /*
-                     * Found a reference to an other metadata. Remind that
-                     * column for creating a foreign key constraint later.
+                     * Found a reference to an other metadata. Remind that column for creating
a foreign key
+                     * constraint later, except if the return type is an abstract CodeList
or Enum (in which
+                     * case the reference could be to any CodeList or Enum table). Abstract
CodeList or Enum
+                     * may happen when the concrete class is not yet available in the GeoAPI
version that we
+                     * are using.
                      */
-                    maxLength = maximumIdentifierLength;
-                    if (foreigners.put(column, new FKey(addTo, rt, null)) != null) {
-                        throw new AssertionError(column);                               //
Should never happen.
+                    if (!isCodeList || !Modifier.isAbstract(rt.getModifiers())) {
+                        if (foreigners.put(column, new FKey(addTo, rt, null)) != null) {
+                            throw new AssertionError(column);                           //
Should never happen.
+                        }
                     }
                     rt = null;                                                          //
For forcing VARCHAR type.
+                    maxLength = maximumIdentifierLength;
+                } else if (rt.isEnum()) {
+                    maxLength = maximumIdentifierLength;
                 }
                 stmt.executeUpdate(helper.createColumn(schema(), addTo, column, rt, maxLength));
                 columns.add(column);
@@ -393,6 +405,8 @@ public class MetadataWriter extends Meta
             final Class<?> type = value.getClass();
             if (CodeList.class.isAssignableFrom(type)) {
                 value = addCode(stmt, (CodeList<?>) value);
+            } else if (type.isEnum()) {
+                value = ((Enum<?>) value).name();
             } else if (standard.isMetadata(type)) {
                 String dependency = proxy(value);
                 if (dependency == null) {
@@ -478,9 +492,9 @@ public class MetadataWriter extends Meta
                 final String column = entry.getKey();
                 final String target = getTableName(rt);
                 stmt.executeUpdate(helper.createForeignKey(
-                        schema(), fkey.tableName, column,               // Source (schema.table.column)
-                        target, primaryKey,                             // Target (table.column)
-                        !isCodeList));                                  // CASCADE if metadata,
RESTRICT if CodeList.
+                        schema(), fkey.tableName, column,       // Source (schema.table.column)
+                        target, primaryKey,                     // Target (table.column)
+                        !isCodeList));                          // CASCADE if metadata, RESTRICT
if CodeList or Enum.
                 /*
                  * In a classical object-oriented model, the constraint would be inherited
by child tables.
                  * However this is not yet supported as of PostgreSQL 9.6. If inheritance
is not supported,
@@ -637,7 +651,7 @@ public class MetadataWriter extends Meta
             stmt.executeUpdate(createTable(table, CODE_COLUMN));
             columns.add(CODE_COLUMN);
         }
-        final String identifier = code.name();
+        final String identifier = Types.getCodeName(code);
         final String query = helper().clear().append("SELECT ").append(CODE_COLUMN)
                 .append(" FROM ").appendIdentifier(schema(), table).append(" WHERE ")
                 .append(CODE_COLUMN).appendCondition(identifier).toString();



Mime
View raw message