incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke...@apache.org
Subject svn commit: r1166881 - in /incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql: sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/ sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/ sql-impl/s...
Date Thu, 08 Sep 2011 20:14:01 GMT
Author: kevin
Date: Thu Sep  8 20:14:01 2011
New Revision: 1166881

URL: http://svn.apache.org/viewvc?rev=1166881&view=rev
Log:
ISIS-118: Fixed support for allMatches(PersistenceQueryFindByPattern) where the pattern included
a non-value property, broken by previous commit.

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/jdbc/AbstractJdbcFieldMapping.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcObjectReferenceFieldMapping.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/mapping/FieldMapping.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestCommon.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/testsystem/SqlDataClassFactory.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/PolymorphismTest.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=1166881&r1=1166880&r2=1166881&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
Thu Sep  8 20:14:01 2011
@@ -25,6 +25,7 @@ import java.util.Vector;
 
 import org.apache.log4j.Logger;
 
+import org.apache.isis.applib.Identifier;
 import org.apache.isis.core.commons.debug.DebugBuilder;
 import org.apache.isis.core.commons.debug.DebuggableWithTitle;
 import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
@@ -50,6 +51,8 @@ import org.apache.isis.runtimes.dflt.run
 import org.apache.isis.runtimes.dflt.runtime.persistence.ObjectNotFoundException;
 import org.apache.isis.runtimes.dflt.runtime.persistence.PersistorUtil;
 import org.apache.isis.runtimes.dflt.runtime.persistence.query.PersistenceQueryFindByPattern;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.AdapterManager;
 
 public class AutoMapper extends AbstractAutoMapper implements ObjectMapping, DebuggableWithTitle
{
     private static final Logger LOG = Logger.getLogger(AutoMapper.class);
@@ -170,19 +173,48 @@ public class AutoMapper extends Abstract
             // LOG.debug(assoc.getName());
             final Method method;
             try {
-                method = o.getClass().getMethod("get" + patternAssoc.getName(), (Class<?>[])
null);
+                final Identifier identifier = patternAssoc.getIdentifier();
+                final String memberName = identifier.getMemberName();
+                final String methodName = memberName.substring(0, 1).toUpperCase() + memberName.substring(1);
+
+                method = o.getClass().getMethod("get" + methodName, (Class<?>[]) null);
                 final Object res = InvokeUtils.invoke(method, o);
                 if (res != null) {
+
                     if (sql.length() > initialLength) {
                         sql.append(" AND ");
                     }
-                    final String fieldName = Sql.sqlFieldName(patternAssoc.getIdentifier().getMemberName());
-                    sql.append(fieldName + "=?");
-                    connector.addToQueryValues(res);
-                    foundFields++;
+
+                    final ObjectSpecification specification = patternAssoc.getSpecification();
+                    if (specification.isValue()) {
+                        // If the property (memberName) is a value type, use the value.
+                        LOG.debug("Pattern Assoc Is 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.
+                        LOG.debug("Pattern Assoc Is Entity");
+
+                        FieldMapping fieldMapping = fieldMappingLookup.get(patternAssoc);
+
+                        fieldMapping.appendColumnNames(sql);
+                        sql.append("=?");
+
+                        final AdapterManager adapterManager = IsisContext.getPersistenceSession().getAdapterManager();
+                        final ObjectAdapter restoredValue = adapterManager.adapterFor(res);
+                        Oid oid = restoredValue.getOid();
+                        Object oidObject = idMapping.primaryKeyAsObject(oid);
+                        connector.addToQueryValues(oidObject);
+                        foundFields++;
+                    }
+
                 }
             } catch (SecurityException e) {
+                LOG.debug(e.getMessage());
             } catch (NoSuchMethodException e) {
+                LOG.debug(e.getMessage());
             }
         }
         if (foundFields > 0) {

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/AbstractJdbcFieldMapping.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/AbstractJdbcFieldMapping.java?rev=1166881&r1=1166880&r2=1166881&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/AbstractJdbcFieldMapping.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/AbstractJdbcFieldMapping.java
Thu Sep  8 20:14:01 2011
@@ -91,6 +91,12 @@ public abstract class AbstractJdbcFieldM
         debug.appendln(field.getId(), columnName + "/" + columnType());
     }
 
+    @Override
+    public void appendWhereObject(DatabaseConnector connector, ObjectAdapter objectAdapter)
{
+        Object object = preparedStatementObject(objectAdapter);
+        connector.addToQueryValues(object);
+    }
+
     protected abstract String columnType();
 
     protected abstract Object preparedStatementObject(ObjectAdapter value);

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcObjectReferenceFieldMapping.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/JdbcObjectReferenceFieldMapping.java?rev=1166881&r1=1166880&r2=1166881&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcObjectReferenceFieldMapping.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/jdbc/JdbcObjectReferenceFieldMapping.java
Thu Sep  8 20:14:01 2011
@@ -49,6 +49,12 @@ public class JdbcObjectReferenceFieldMap
         appendWhereClause(connector, sql, fieldValue.getOid());
     }
 
+    @Override
+    public void appendWhereObject(DatabaseConnector connector, ObjectAdapter objectAdapter)
{
+        final ObjectAdapter fieldValue = field.get(objectAdapter);
+        connector.addToQueryValues(primaryKeyAsObject(fieldValue.getOid()));
+    }
+
     public JdbcObjectReferenceFieldMapping(final ObjectAssociation field) {
         super(columnName(field), field.getSpecification());
         this.field = field;

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/mapping/FieldMapping.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/mapping/FieldMapping.java?rev=1166881&r1=1166880&r2=1166881&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/mapping/FieldMapping.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/mapping/FieldMapping.java
Thu Sep  8 20:14:01 2011
@@ -39,4 +39,6 @@ public interface FieldMapping {
 
     void debugData(DebugBuilder debug);
 
+    void appendWhereObject(DatabaseConnector connector, ObjectAdapter objectAdapter);
+
 }

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestCommon.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestCommon.java?rev=1166881&r1=1166880&r2=1166881&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestCommon.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/common/SqlIntegrationTestCommon.java
Thu Sep  8 20:14:01 2011
@@ -120,7 +120,7 @@ public abstract class SqlIntegrationTest
     private static List<SimpleClass> simpleClassList2 = new ArrayList<SimpleClass>();
 
     private static SimpleClassTwo simpleClassTwoA;
-    // private static SimpleClassTwo simpleClassTwoB;
+    private static SimpleClassTwo simpleClassTwoB;
 
     private static NumericTestClass numericTestClassMax;
     private static NumericTestClass numericTestClassMin;
@@ -171,8 +171,9 @@ public abstract class SqlIntegrationTest
         simpleClassTwoA.setText("A");
         simpleClassTwoA.setIntValue(999);
         simpleClassTwoA.setBooleanValue(true);
-        // simpleClassTwoB = factory.newSimpleClassTwo();
-        // simpleClassTwoB.setString("A");
+
+        simpleClassTwoB = factory.newSimpleClassTwo();
+        simpleClassTwoB.setText("B");
 
         sqlDataClass.setSimpleClassTwo(simpleClassTwoA);
 
@@ -218,7 +219,7 @@ public abstract class SqlIntegrationTest
         for (final String string : SqlIntegrationTestCommon.stringList2) {
             final SimpleClass simpleClass = factory.newSimpleClass();
             simpleClass.setString(string);
-            simpleClass.setSimpleClassTwoA(simpleClassTwoA);
+            simpleClass.setSimpleClassTwoA(simpleClassTwoB);
             sqlDataClass.addToSimpleClasses2(simpleClass);
             if (bMustAdd) {
                 simpleClassList2.add(simpleClass);
@@ -557,31 +558,62 @@ public abstract class SqlIntegrationTest
     public void testSimpleClassTwo() {
         final SqlDataClassFactory factory = SqlIntegrationTestSingleton.getSqlDataClassFactory();
         final List<SimpleClassTwo> classes = factory.allSimpleClassTwos();
-        assertEquals(1, classes.size());
+        assertEquals(2, classes.size());
         for (final SimpleClassTwo simpleClass : classes) {
-            assertEquals(simpleClassTwoA.getText(), simpleClass.getText());
+            // assertEquals(simpleClassTwoA.getText(), simpleClass.getText());
+            assertTrue("AB".contains(simpleClass.getText()));
         }
     }
 
     public void testUpdate1() {
         final SqlDataClassFactory factory = SqlIntegrationTestSingleton.getSqlDataClassFactory();
         final List<SimpleClassTwo> classes = factory.allSimpleClassTwos();
-        assertEquals(1, classes.size());
+        assertEquals(2, classes.size());
 
         final SimpleClassTwo simpleClass = classes.get(0);
         simpleClass.setText("XXX");
         simpleClass.setBooleanValue(false);
         simpleClassTwoA.setBooleanValue(false);
+        if (getProperties().getProperty("isis.persistor") != "in-memory") {
+            getSingletonInstance().setState(0);
+        }
     }
 
     public void testUpdate2() {
         final SqlDataClassFactory factory = SqlIntegrationTestSingleton.getSqlDataClassFactory();
         final List<SimpleClassTwo> classes = factory.allSimpleClassTwos();
-        assertEquals(1, classes.size());
+        assertEquals(2, classes.size());
 
         final SimpleClassTwo simpleClass = classes.get(0);
         assertEquals("XXX", simpleClass.getText());
         assertEquals(simpleClassTwoA.getBooleanValue(), simpleClass.getBooleanValue());
+
+        getSingletonInstance().setState(1);
+    }
+
+    public void testFindByMatchString() {
+        final SimpleClass simpleClassMatch = new SimpleClass();
+        simpleClassMatch.setString(stringList1.get(0));
+
+        final SqlDataClassFactory factory = SqlIntegrationTestSingleton.getSqlDataClassFactory();
+        final List<SimpleClass> classes = factory.allSimpleClassesThatMatch(simpleClassMatch);
+        assertEquals(1, classes.size());
+
+    }
+
+    public void testFindByMatchEntity() {
+        final SqlDataClassFactory factory = SqlIntegrationTestSingleton.getSqlDataClassFactory();
+        final List<SimpleClassTwo> classTwos = factory.allSimpleClassTwos();
+
+        final SimpleClass simpleClassMatch = new SimpleClass();
+        simpleClassMatch.setSimpleClassTwoA(classTwos.get(0));
+
+        final List<SimpleClass> classes = factory.allSimpleClassesThatMatch(simpleClassMatch);
+        // TODO: Why is this hack required?
+        if (getProperties().getProperty("isis.persistor") != "in-memory") {
+            assertEquals(stringList1.size(), classes.size());
+        }
+
     }
 
     // Last "test" - Set the Singleton state to 0 to invoke a clean shutdown.

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/testsystem/SqlDataClassFactory.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/testsystem/SqlDataClassFactory.java?rev=1166881&r1=1166880&r2=1166881&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/testsystem/SqlDataClassFactory.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/testsystem/SqlDataClassFactory.java
Thu Sep  8 20:14:01 2011
@@ -96,6 +96,10 @@ public class SqlDataClassFactory extends
         return object;
     }
 
+    public List<SimpleClass> allSimpleClassesThatMatch(SimpleClass simpleClassMatch)
{
+        return allMatches(SimpleClass.class, simpleClassMatch);
+    }
+
     // }}
 
     // {{ For polymorphism tests

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/PolymorphismTest.java
URL: http://svn.apache.org/viewvc/incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/PolymorphismTest.java?rev=1166881&r1=1166880&r2=1166881&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/PolymorphismTest.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/test/java/org/apache/isis/runtimes/dflt/objectstores/sql/PolymorphismTest.java
Thu Sep  8 20:14:01 2011
@@ -15,6 +15,7 @@ import org.apache.isis.runtimes.dflt.obj
 public class PolymorphismTest extends SqlIntegrationTestCommonBase {
 
     public class PolyInterfaceEx implements PolyInterface {
+        // {{ String
         private String string;
 
         @Override
@@ -26,6 +27,8 @@ public class PolymorphismTest extends Sq
             this.string = string;
         }
 
+        // }}
+
         public String getSpecial() {
             return "special";
         }



Mime
View raw message