sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1795376 - /sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.java
Date Tue, 16 May 2017 21:55:35 GMT
Author: desruisseaux
Date: Tue May 16 21:55:35 2017
New Revision: 1795376

URL: http://svn.apache.org/viewvc?rev=1795376&view=rev
Log:
Compute the column name at reading time in a way more consistent with the way it is computed
at writing time.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/metadata/sql/MetadataSource.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=1795376&r1=1795375&r2=1795376&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] Tue May 16 21:55:35 2017
@@ -266,6 +266,17 @@ public class MetadataSource implements A
     private transient volatile ObjectConverter<?,?> lastConverter;
 
     /**
+     * The last "method name to column name" map returned by {@link #asNameMap(Class)}.
+     * Cached on assumption that the same map will be used more than once before to move
to another metadata object.
+     */
+    private transient Map<String,String> lastNameMap;
+
+    /**
+     * The {@code type} argument in the last call to {@link #asNameMap(Class)}.
+     */
+    private transient Class<?> lastNameMapType;
+
+    /**
      * Where to report the warnings. This is not necessarily a logger, since users can register
listeners.
      *
      * @see #getValue(Class, Method, Dispatcher)
@@ -544,18 +555,6 @@ public class MetadataSource implements A
     }
 
     /**
-     * Returns the column name for the specified method.
-     */
-    private static String getColumnName(final Method method) {
-        final UML annotation = method.getAnnotation(UML.class);
-        if (annotation == null) {
-            return method.getName();
-        }
-        final String name = annotation.identifier();
-        return name.substring(name.lastIndexOf('.') + 1);
-    }
-
-    /**
      * If the given metadata is a proxy generated by this {@code MetadataSource}, returns
the
      * identifier of that proxy. Such metadata do not need to be inserted again in the database.
      *
@@ -567,6 +566,24 @@ public class MetadataSource implements A
     }
 
     /**
+     * Maps method names to the name of columns in the table for the given metadata. The
values in the
+     * returned map must be the same than the keys in the map returned by {@link #asValueMap(Object)}.
+     *
+     * @param  type  the type of metadata object for which to get column names.
+     * @return a map from method names to column names.
+     * @throws ClassCastException if the metadata object type does not extend a metadata
interface
+     *         of the expected package.
+     */
+    @SuppressWarnings("ReturnOfCollectionOrArrayField")
+    private Map<String,String> asNameMap(final Class<?> type) throws ClassCastException
{
+        assert Thread.holdsLock(this);
+        if (type != lastNameMapType) {
+            lastNameMap = standard.asNameMap(type, KeyNamePolicy.METHOD_NAME, KeyNamePolicy.UML_IDENTIFIER);
+        }
+        return lastNameMap;
+    }
+
+    /**
      * Returns a view of the given metadata as a map. This method returns always a map using
UML identifier
      * and containing all entries including the null ones because the {@code MetadataSource}
implementation
      * assumes so.
@@ -837,10 +854,11 @@ public class MetadataSource implements A
         final Class<?> elementType    = wantCollection ? Classes.boundOfParameterizedProperty(method)
: returnType;
         final boolean  isMetadata     = standard.isMetadata(elementType);
         final String   tableName      = getTableName(type);
-        final String   columnName     = getColumnName(method);
+        final String   columnName;
         final boolean  isArray;
         Object value;
         synchronized (this) {
+            columnName = asNameMap(type).get(method.getName());
             if (!getExistingColumns(tableName).contains(columnName)) {
                 value   = null;
                 isArray = false;



Mime
View raw message