sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1796396 - /sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataWriter.java
Date Sat, 27 May 2017 13:54:05 GMT
Author: desruisseaux
Date: Sat May 27 13:54:04 2017
New Revision: 1796396

URL: http://svn.apache.org/viewvc?rev=1796396&view=rev
Log:
Do not create foreigner key constraint when the CodeList or Enum type is abstract.
This case never happen on Apache SIS branches, but happen on trunk because CI_TelephoneTypeCode
was not present in GeoAPI 3.0.

Modified:
    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/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=1796396&r1=1796395&r2=1796396&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 13:54:04 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.metadata.Identifier;
 import org.opengis.metadata.citation.Citation;
@@ -305,18 +306,26 @@ 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 (ControlledVocabulary.class.isAssignableFrom(rt) || standard.isMetadata(rt))
{
+                final boolean isCodeList = ControlledVocabulary.class.isAssignableFrom(rt);
    // Also enums.
+                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.
                 }



Mime
View raw message