You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ke...@apache.org on 2011/10/10 16:55:44 UTC

svn commit: r1181010 - in /incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql: auto/AutoMapper.java auto/ForeignKeyCollectionMapper.java jdbc/JdbcGeneralValueMapper.java

Author: kevin
Date: Mon Oct 10 14:55:43 2011
New Revision: 1181010

URL: http://svn.apache.org/viewvc?rev=1181010&view=rev
Log:
ISIS-122 and ISIS-118: Issues with transient entities in the History / bread crumb trail. Fixed by using Facets in AutoMapper, as originally done. Except when interfaces and values are used, when getXXX method must still be called. Also added fix to handle Boolean class properly in JdbcGeneralValueMapper.

Modified:
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/AutoMapper.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/ForeignKeyCollectionMapper.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcGeneralValueMapper.java

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/AutoMapper.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/AutoMapper.java?rev=1181010&r1=1181009&r2=1181010&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/AutoMapper.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/AutoMapper.java Mon Oct 10 14:55:43 2011
@@ -186,43 +186,40 @@ public class AutoMapper extends Abstract
             final String methodName = memberName.substring(0, 1).toUpperCase() + memberName.substring(1);
 
             try {
-                // TODO: replace this back to the original method that uses Facets, instead of directly invoking
-                // "getXXX"
-                method = o.getClass().getMethod("get" + methodName, (Class<?>[]) null);
-                final Object res = InvokeUtils.invoke(method, o);
-                if (res != null) {
-
-                    if (foundFields == 0) {
-                        sql.append(" WHERE ");
-                        initialLength = sql.length();
-                    }
-
-                    if (sql.length() > initialLength) {
-                        sql.append(" AND ");
-                    }
-
-                    final ObjectSpecification specification = patternAssoc.getSpecification();
-                    if (specification.isValue()) {
-                        // If the property (memberName) is a value type, use the value.
-                        final String fieldName = Sql.sqlFieldName(identifier.getMemberName());
-                        sql.append(fieldName + "=?");
-                        connector.addToQueryValues(res);
-                        foundFields++;
-                    } else {
-                        // If the property (memberName) is an entity, use the ID.
-                        FieldMapping fieldMapping = fieldMappingLookup.get(patternAssoc);
-
-                        fieldMapping.appendColumnNames(sql);
-                        sql.append("=?");
-
-                        // If you get errors here, bring the definition of adapterManager from above, back to here.
-                        final ObjectAdapter restoredValue = adapterManager.adapterFor(res);
-                        Oid oid = restoredValue.getOid();
-                        Object oidObject = idMapping.primaryKeyAsObject(oid);
-                        connector.addToQueryValues(oidObject);
+                if (true) {
+                    final ObjectAdapter field = patternAssoc.get(pattern);
+                    if (field != null) {
+
+                        if (foundFields == 0) {
+                            sql.append(" WHERE ");
+                            initialLength = sql.length();
+                        }
+
+                        if (sql.length() > initialLength) {
+                            sql.append(" AND ");
+                        }
+
+                        final FieldMapping fieldMapping = fieldMappingFor(patternAssoc);
+                        if (fieldMapping != null) {
+                            fieldMapping.appendWhereClause(connector, sql, pattern);
+                        } else {
+                            // Have to use getXXX method if the fieldMapping is null..
+                            final ObjectSpecification specification = patternAssoc.getSpecification();
+
+                            method = o.getClass().getMethod("get" + methodName, (Class<?>[]) null);
+                            final Object res = InvokeUtils.invoke(method, o);
+
+                            if (specification.isValue()) {
+                                // If the property (memberName) is a value type, use the value.
+                                final String fieldName = Sql.sqlFieldName(identifier.getMemberName());
+                                sql.append(fieldName + "=?");
+                                connector.addToQueryValues(res);
+                            } else {
+                                throw new SqlObjectStoreException("Unhandled combination!");
+                            }
+                        }
                         foundFields++;
                     }
-
                 }
             } catch (SecurityException e) {
                 LOG.debug(e.getMessage());

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/ForeignKeyCollectionMapper.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/ForeignKeyCollectionMapper.java?rev=1181010&r1=1181009&r2=1181010&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/ForeignKeyCollectionMapper.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/ForeignKeyCollectionMapper.java Mon Oct 10 14:55:43 2011
@@ -212,7 +212,7 @@ public class ForeignKeyCollectionMapper 
                 for (ObjectAdapter field : list) {
                     // final ObjectMapping mapping = objectMappingLookup.getMapping(field, connector);
                     if (field.getSpecification().isOfType(parent.getSpecification())) {
-                        loadInternalCollection(connector, field, false);
+                        loadInternalCollection(connector, field, true);
                     }
                 }
             }
@@ -220,8 +220,9 @@ public class ForeignKeyCollectionMapper 
     }
 
     protected void loadCollectionIntoList(final DatabaseConnector connector, final ObjectAdapter parent,
-        final boolean makeResolved, final String table, ObjectSpecification specification, final IdMappingAbstract idMappingAbstract,
-        final List<FieldMapping> fieldMappings, final VersionMapping versionMapping, final List<ObjectAdapter> list) {
+        final boolean makeResolved, final String table, ObjectSpecification specification,
+        final IdMappingAbstract idMappingAbstract, final List<FieldMapping> fieldMappings,
+        final VersionMapping versionMapping, final List<ObjectAdapter> list) {
 
         final StringBuffer sql = new StringBuffer();
         sql.append("select ");

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcGeneralValueMapper.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcGeneralValueMapper.java?rev=1181010&r1=1181009&r2=1181010&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcGeneralValueMapper.java (original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcGeneralValueMapper.java Mon Oct 10 14:55:43 2011
@@ -67,6 +67,8 @@ public class JdbcGeneralValueMapper exte
             return ((Password) o).getPassword();
         } else if (o instanceof String) {
             return o;
+        } else if (o instanceof Boolean) {
+            return o;
         } else {
             if (columnType().contains("CHAR")) {
                 final EncodableFacet facet = value.getSpecification().getFacet(EncodableFacet.class);