sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1796404 - in /sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql: MetadataSource.java MetadataWriter.java
Date Sat, 27 May 2017 14:59:56 GMT
Author: desruisseaux
Date: Sat May 27 14:59:56 2017
New Revision: 1796404

URL: http://svn.apache.org/viewvc?rev=1796404&view=rev
Log:
All CodeList are ControlledVocabulary, but not all Enum are ControlledVocabulary.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataWriter.java

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=1796404&r1=1796403&r2=1796404&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] Sat May 27 14:59:56 2017
@@ -617,6 +617,8 @@ public class MetadataSource implements A
              */
             if (metadata instanceof ControlledVocabulary) {
                 identifier = Types.getCodeName((ControlledVocabulary) metadata);
+            } else if (metadata instanceof Enum<?>) {
+                identifier = ((Enum<?>) metadata).name();
             } else {
                 final String table;
                 final Map<String,Object> asMap;
@@ -680,6 +682,8 @@ public class MetadataSource implements A
             if (value != null) {
                 if (value instanceof ControlledVocabulary) {
                     value = Types.getCodeName((ControlledVocabulary) value);
+                } else if (value instanceof Enum<?>) {
+                    value = ((Enum<?>) value).name();
                 } else {
                     String dependency = proxy(value);
                     if (dependency != null) {
@@ -794,7 +798,7 @@ public class MetadataSource implements A
      *
      * @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 ControlledVocabulary} type ({@link CodeList} or
{@link Enum}).
+     *                     or the {@link 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.

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataWriter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataWriter.java?rev=1796404&r1=1796403&r2=1796404&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataWriter.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataWriter.java
[UTF-8] Sat May 27 14:59:56 2017
@@ -312,7 +312,7 @@ public class MetadataWriter extends Meta
                  */
                 int maxLength = maximumValueLength;
                 Class<?> rt = colTypes.get(column);
-                final boolean isCodeList = ControlledVocabulary.class.isAssignableFrom(rt);
    // Also enums.
+                final boolean isCodeList = ControlledVocabulary.class.isAssignableFrom(rt);
    // Accept also some enums.
                 if (isCodeList || standard.isMetadata(rt)) {
                     /*
                      * Found a reference to an other metadata. Remind that column for creating
a foreign key
@@ -321,13 +321,15 @@ public class MetadataWriter extends Meta
                      * may happen when the concrete class is not yet available in the GeoAPI
version that we
                      * are using.
                      */
-                    maxLength = maximumIdentifierLength;
                     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);
@@ -402,6 +404,8 @@ public class MetadataWriter extends Meta
             final Class<?> type = value.getClass();
             if (ControlledVocabulary.class.isAssignableFrom(type)) {
                 value = addCode(stmt, (ControlledVocabulary) value);
+            } else if (type.isEnum()) {
+                value = ((Enum<?>) value).name();
             } else if (standard.isMetadata(type)) {
                 String dependency = proxy(value);
                 if (dependency == null) {



Mime
View raw message