incubator-isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke...@apache.org
Subject svn commit: r1166295 - in /incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql: sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/ sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/ sql-tests-commo...
Date Wed, 07 Sep 2011 18:14:59 GMT
Author: kevin
Date: Wed Sep  7 18:14:58 2011
New Revision: 1166295

URL: http://svn.apache.org/viewvc?rev=1166295&view=rev
Log:
ISIS-118 and ISIS-119: Working on getting collections to load and resolve properly. Added
support for allInstances to return instances of subclasses, too.

Modified:
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlObjectStore.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/AbstractAutoMapper.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/SqlObjectStore.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/SqlObjectStore.java?rev=1166295&r1=1166294&r2=1166295&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlObjectStore.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/SqlObjectStore.java
Wed Sep  7 18:14:58 2011
@@ -22,6 +22,8 @@ package org.apache.isis.runtimes.dflt.ob
 import java.util.List;
 import java.util.Vector;
 
+import org.apache.log4j.Logger;
+
 import org.apache.isis.core.commons.debug.DebugBuilder;
 import org.apache.isis.core.commons.debug.DebugString;
 import org.apache.isis.core.commons.exceptions.IsisException;
@@ -44,7 +46,6 @@ import org.apache.isis.runtimes.dflt.run
 import org.apache.isis.runtimes.dflt.runtime.system.transaction.IsisTransactionManager;
 import org.apache.isis.runtimes.dflt.runtime.system.transaction.MessageBroker;
 import org.apache.isis.runtimes.dflt.runtime.system.transaction.UpdateNotifier;
-import org.apache.log4j.Logger;
 
 public final class SqlObjectStore implements ObjectStore {
     private static final String TABLE_NAME = "isis_admin_services";
@@ -207,8 +208,11 @@ public final class SqlObjectStore implem
     private ObjectAdapter[] findByPattern(final PersistenceQueryFindByPattern query) {
         final ObjectSpecification specification = query.getSpecification();
         final DatabaseConnector connector = connectionPool.acquire();
+
+        // TODO find derived types, too.
         final ObjectMapping mapper = objectMappingLookup.getMapping(specification, connector);
         final ObjectAdapter instances[] = mapper.getInstances(connector, specification, query);
+
         connectionPool.release(connector);
         return instances;
     }
@@ -218,21 +222,38 @@ public final class SqlObjectStore implem
         return allInstances(spec);
     }
 
-    // TODO: allInstances of should find all derived types, too.
     private ObjectAdapter[] allInstances(final ObjectSpecification spec) {
         final DatabaseConnector connector = connectionPool.acquire();
-        final ObjectMapping mapper = objectMappingLookup.getMapping(spec, connector);
-        final ObjectAdapter[] instances = mapper.getInstances(connector, spec);
         final Vector<ObjectAdapter> matchingInstances = new Vector<ObjectAdapter>();
-        for (final ObjectAdapter instance : instances) {
-            matchingInstances.addElement(instance);
+
+        // Abstract entities will never be created.
+        if (!spec.isAbstract()) {
+            addSpecInstances(spec, connector, matchingInstances);
         }
+
+        // Search for subclasses, too.
+        if (spec.hasSubclasses()) {
+            final List<ObjectSpecification> subclasses = spec.subclasses();
+            for (ObjectSpecification subclassSpec : subclasses) {
+                addSpecInstances(subclassSpec, connector, matchingInstances);
+            }
+        }
+
         connectionPool.release(connector);
         final ObjectAdapter[] instanceArray = new ObjectAdapter[matchingInstances.size()];
         matchingInstances.copyInto(instanceArray);
         return instanceArray;
     }
 
+    private void addSpecInstances(ObjectSpecification spec, DatabaseConnector connector,
+        Vector<ObjectAdapter> matchingInstances) {
+        final ObjectMapping mapper = objectMappingLookup.getMapping(spec, connector);
+        final ObjectAdapter[] instances = mapper.getInstances(connector, spec);
+        for (final ObjectAdapter instance : instances) {
+            matchingInstances.addElement(instance);
+        }
+    }
+
     private ObjectAdapter[] findByTitle(final PersistenceQueryFindByTitle criteria) {
         final ObjectSpecification spec = criteria.getSpecification();
         final DatabaseConnector connector = connectionPool.acquire();

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/AbstractAutoMapper.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/AbstractAutoMapper.java?rev=1166295&r1=1166294&r2=1166295&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/AbstractAutoMapper.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/AbstractAutoMapper.java
Wed Sep  7 18:14:58 2011
@@ -117,7 +117,17 @@ public abstract class AbstractAutoMapper
             for (ObjectSpecification subclass : subclasses) {
                 final List<? extends ObjectAssociation> subAssociations = subclass.getAssociations();
                 for (ObjectAssociation subA : subAssociations) {
-                    if (fields.contains(subA) == false) {
+                    boolean found = false;
+                    String name = subA.getName();
+
+                    for (ObjectAssociation existingField : fields) {
+                        if (existingField.getName().equals(name)) {
+                            found = true;
+                            continue;
+                        }
+                    }
+
+                    if (found == false) {
                         fields.add(subA);
                     }
                 }

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=1166295&r1=1166294&r2=1166295&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
Wed Sep  7 18:14:58 2011
@@ -29,6 +29,7 @@ import org.apache.isis.runtimes.dflt.obj
 import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.SimpleClass;
 import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.SimpleClassTwo;
 import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.SqlDataClass;
+import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.polymorphism.PolyInterface;
 import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.polymorphism.PolyInterfaceImplA;
 import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.polymorphism.PolyInterfaceImplB;
 import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.polymorphism.PolySelfRefClass;
@@ -132,6 +133,10 @@ public class SqlDataClassFactory extends
         return object;
     }
 
+    public List<PolyInterface> allPolyInterfaces() {
+        return allInstances(PolyInterface.class);
+    }
+
     // }}
 
 }

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=1166295&r1=1166294&r2=1166295&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
Wed Sep  7 18:14:58 2011
@@ -159,8 +159,9 @@ public class PolymorphismTest extends Sq
         assertEquals(CHILD_1, polySelfRefChild1.title());
 
         final SqlDataClassFactory factory = SqlIntegrationTestSingleton.getSqlDataClassFactory();
-        factory.resolve(polySelfRefChild1);
         List<PolySelfRefClass> list2 = polySelfRefChild1.getPolySelfRefClasses();
+        factory.resolve(polySelfRefChild1);
+        list2 = polySelfRefChild1.getPolySelfRefClasses();
         assertEquals(1, list2.size());
     }
 
@@ -188,7 +189,12 @@ public class PolymorphismTest extends Sq
         final PolyTestClass polyTestClass = SqlIntegrationTestSingleton.getStaticPolyTestClass();
         PolyInterface loaded = polyTestClass.getPolyInterfaceType();
         assertEquals(polyIntImpB.getString(), loaded.getString());
+    }
 
+    public void testAllInterfacesInstancesLoaded() {
+        final SqlDataClassFactory factory = SqlIntegrationTestSingleton.getSqlDataClassFactory();
+        List<PolyInterface> list = factory.allPolyInterfaces();
+        assertEquals(2, list.size());
     }
 
     // Last "test" - Set the Singleton state to 0 to invoke a clean shutdown.



Mime
View raw message