isis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ke...@apache.org
Subject svn commit: r1169477 - in /incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql: sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/ sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/testsyst...
Date Sun, 11 Sep 2011 16:47:24 GMT
Author: kevin
Date: Sun Sep 11 16:47:24 2011
New Revision: 1169477

URL: http://svn.apache.org/viewvc?rev=1169477&view=rev
Log:
ISIS-118: Disabled broken handling of polymorphism with classes (abstract classes, subclasses,
etc), in collections. Should still work with non-collections, though.

Added:
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/testsystem/dataclasses/polymorphism/PolySubClassThree.java
  (with props)
Modified:
    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-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/CombinedCollectionMapper.java
    incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/MultiColumnCombinedCollectionMapper.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/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/testsystem/dataclasses/polymorphism/PolyTestClass.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/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=1169477&r1=1169476&r2=1169477&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
Sun Sep 11 16:47:24 2011
@@ -110,31 +110,6 @@ public abstract class AbstractAutoMapper
 
         fields.addAll(specification.getAssociations());
 
-        if (specification.hasSubclasses()) {
-            getExtraFields(fields);
-
-            final List<ObjectSpecification> subclasses = specification.subclasses();
-
-            for (ObjectSpecification subclass : subclasses) {
-                final List<? extends ObjectAssociation> subAssociations = subclass.getAssociations();
-                for (ObjectAssociation subA : subAssociations) {
-                    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);
-                    }
-                }
-            }
-        }
-
         int simpleFieldCount = 0;
         int collectionFieldCount = 0;
         for (int i = 0; i < fields.size(); i++) {
@@ -178,6 +153,7 @@ public abstract class AbstractAutoMapper
                     // Let MultiColumnCombinedCollectionMapper find itself when a field is
a collection of the current
                     // field type.
                     if (this instanceof MultiColumnCombinedCollectionMapper) {
+                        // TODO: Polymorphism - is it sufficient for the collectionMapper
to handle the subclasses?
                         MultiColumnCombinedCollectionMapper mc = (MultiColumnCombinedCollectionMapper)
this;
 
                         if (mc.priorField == field) {

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/CombinedCollectionMapper.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/CombinedCollectionMapper.java?rev=1169477&r1=1169476&r2=1169477&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/CombinedCollectionMapper.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/CombinedCollectionMapper.java
Sun Sep 11 16:47:24 2011
@@ -55,6 +55,7 @@ public class CombinedCollectionMapper ex
     private final ObjectMappingLookup objectMapperLookup2;
 
     private ObjectMapping originalMapping = null;
+    private final boolean isAbstract;
 
     public CombinedCollectionMapper(final ObjectAssociation objectAssociation, final String
parameterBase,
         final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup) {
@@ -62,6 +63,8 @@ public class CombinedCollectionMapper ex
 
         this.field = objectAssociation;
 
+        isAbstract = field.getSpecification().isAbstract();
+
         objectMapperLookup2 = objectMapperLookup;
 
         idMapping = lookup.createIdMapping();
@@ -88,7 +91,7 @@ public class CombinedCollectionMapper ex
 
     @Override
     public boolean needsTables(final DatabaseConnector connection) {
-        return !connection.hasColumn(table, foreignKeyName);
+        return isAbstract || !connection.hasColumn(table, foreignKeyName);
     }
 
     @Override
@@ -102,6 +105,9 @@ public class CombinedCollectionMapper ex
 
     @Override
     public void createTables(final DatabaseConnector connection) {
+        if (isAbstract) {
+            return;
+        }
         final StringBuffer sql = new StringBuffer();
         sql.append("alter table ");
         sql.append(table);
@@ -114,6 +120,12 @@ public class CombinedCollectionMapper ex
     public void loadInternalCollection(final DatabaseConnector connector, final ObjectAdapter
parent,
         final boolean makeResolved) {
 
+        if (isAbstract) { // hasSubClasses, too?
+            // TODO: Polymorphism: loadInternalCollection must load the instance from all
the possible child tables.
+            LOG.debug("Is Abstract");
+            return;
+        }
+
         final ObjectAdapter collection = field.get(parent);
         if (collection.getResolveState().canChangeTo(ResolveState.RESOLVING)) {
             LOG.debug("loading internal collection " + field);
@@ -190,7 +202,14 @@ public class CombinedCollectionMapper ex
             return;
         }
 
+        if (isAbstract) {
+            // TODO: Polymorphism: saveInternalCollection must save instance into the appropriate
child tables.
+            LOG.debug("Is Abstract");
+            return;
+        }
+
         // Delete collection parent
+        // TODO: for polymorphism, must delete from all? appropriate child tables.
         final StringBuffer sql = new StringBuffer();
         sql.append("update ");
         sql.append(table);
@@ -201,8 +220,7 @@ public class CombinedCollectionMapper ex
         connector.update(sql.toString());
 
         // Reinstall collection parent
-        // sql = new StringBuffer();
-
+        // TODO: : for polymorphism, must load from all appropriate child tables.
         final StringBuffer update = new StringBuffer();
         update.append("update ");
         update.append(table);

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/MultiColumnCombinedCollectionMapper.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/MultiColumnCombinedCollectionMapper.java?rev=1169477&r1=1169476&r2=1169477&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/MultiColumnCombinedCollectionMapper.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-impl/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/auto/MultiColumnCombinedCollectionMapper.java
Sun Sep 11 16:47:24 2011
@@ -41,6 +41,8 @@ import org.apache.isis.runtimes.dflt.obj
 public class MultiColumnCombinedCollectionMapper extends CombinedCollectionMapper {
     private static final Logger LOG = Logger.getLogger(CombinedCollectionMapper.class);
 
+    // TODO: Needs to detect if field has subclasses, and to add FK_* column to *all* non-abstract
subclasses.
+
     public MultiColumnCombinedCollectionMapper(final ObjectAssociation objectAssociation,
final String parameterBase,
         final FieldMappingLookup lookup, final ObjectMappingLookup objectMapperLookup,
         AbstractAutoMapper abstractAutoMapper, ObjectAssociation field) {

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=1169477&r1=1169476&r2=1169477&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
Sun Sep 11 16:47:24 2011
@@ -34,6 +34,7 @@ import org.apache.isis.runtimes.dflt.obj
 import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.polymorphism.PolyInterfaceImplB;
 import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.polymorphism.PolySelfRefClass;
 import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.polymorphism.PolySubClassOne;
+import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.polymorphism.PolySubClassThree;
 import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.polymorphism.PolySubClassTwo;
 import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.polymorphism.PolyTestClass;
 
@@ -117,6 +118,11 @@ public class SqlDataClassFactory extends
         return object;
     }
 
+    public PolySubClassThree newPolySubClassThree() {
+        final PolySubClassThree object = newTransientInstance(PolySubClassThree.class);
+        return object;
+    }
+
     public PolySubClassTwo newPolySubClassTwo() {
         final PolySubClassTwo object = newTransientInstance(PolySubClassTwo.class);
         return object;

Added: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/testsystem/dataclasses/polymorphism/PolySubClassThree.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/dataclasses/polymorphism/PolySubClassThree.java?rev=1169477&view=auto
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/testsystem/dataclasses/polymorphism/PolySubClassThree.java
(added)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/testsystem/dataclasses/polymorphism/PolySubClassThree.java
Sun Sep 11 16:47:24 2011
@@ -0,0 +1,44 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+/**
+ * 
+ */
+package org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.polymorphism;
+
+/**
+ * @author Kevin
+ * 
+ */
+public class PolySubClassThree extends PolySubClassTwo {
+
+    // {{ String type
+    private String string;
+
+    public String getAnotherString() {
+        return string;
+    }
+
+    public void setAnotherString(final String string) {
+        this.string = string;
+    }
+
+    // }}
+
+}

Propchange: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/testsystem/dataclasses/polymorphism/PolySubClassThree.java
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/testsystem/dataclasses/polymorphism/PolyTestClass.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/dataclasses/polymorphism/PolyTestClass.java?rev=1169477&r1=1169476&r2=1169477&view=diff
==============================================================================
--- incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/testsystem/dataclasses/polymorphism/PolyTestClass.java
(original)
+++ incubator/isis/trunk/framework/runtimes/dflt/objectstores/sql/sql-tests-common/src/main/java/org/apache/isis/runtimes/dflt/objectstores/sql/testsystem/dataclasses/polymorphism/PolyTestClass.java
Sun Sep 11 16:47:24 2011
@@ -22,6 +22,9 @@
  */
 package org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.polymorphism;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.isis.applib.AbstractDomainObject;
 
 /**
@@ -50,16 +53,15 @@ public class PolyTestClass extends Abstr
     // }}
 
     // {{ PolyBaseClass
-    // private List<PolyBaseClass> polyBaseClasses = new ArrayList<PolyBaseClass>();
+    private List<PolyBaseClass> polyBaseClasses = new ArrayList<PolyBaseClass>();
+
+    public List<PolyBaseClass> getPolyBaseClasses() {
+        return polyBaseClasses;
+    }
 
-    // @MemberOrder(sequence = "1")
-    // public List<PolyBaseClass> getPolyBaseClasses() {
-    // return polyBaseClasses;
-    // }
-
-    // public void setPolyBaseClasses(final List<PolyBaseClass> polyBaseClasses) {
-    // this.polyBaseClasses = polyBaseClasses;
-    // }
+    public void setPolyBaseClasses(final List<PolyBaseClass> polyBaseClasses) {
+        this.polyBaseClasses = polyBaseClasses;
+    }
 
     // }}
 

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=1169477&r1=1169476&r2=1169477&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
Sun Sep 11 16:47:24 2011
@@ -6,10 +6,14 @@ import java.util.Properties;
 import org.apache.isis.runtimes.dflt.objectstores.sql.common.SqlIntegrationTestCommonBase;
 import org.apache.isis.runtimes.dflt.objectstores.sql.singleton.SqlIntegrationTestSingleton;
 import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.SqlDataClassFactory;
+import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.polymorphism.PolyBaseClass;
 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;
+import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.polymorphism.PolySubClassOne;
+import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.polymorphism.PolySubClassThree;
+import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.polymorphism.PolySubClassTwo;
 import org.apache.isis.runtimes.dflt.objectstores.sql.testsystem.dataclasses.polymorphism.PolyTestClass;
 
 public class PolymorphismTest extends SqlIntegrationTestCommonBase {
@@ -78,6 +82,7 @@ public class PolymorphismTest extends Sq
         SqlIntegrationTestSingleton.drop("ISIS_POLYTESTCLASS");
         SqlIntegrationTestSingleton.drop("ISIS_POLYSUBCLASSONE");
         SqlIntegrationTestSingleton.drop("ISIS_POLYSUBCLASSTWO");
+        SqlIntegrationTestSingleton.drop("ISIS_POLYSUBCLASSTHREE");
         SqlIntegrationTestSingleton.drop("ISIS_POLYINTERFACEIMPLA");
         SqlIntegrationTestSingleton.drop("ISIS_POLYINTERFACEIMPLB");
         SqlIntegrationTestSingleton.drop("ISIS_POLYSELFREFCLASS");
@@ -120,17 +125,23 @@ public class PolymorphismTest extends Sq
         polyTestClass.setPolyInterfaceType(polyIntImpA);
 
         // setup the polyTestClass
-        // PolySubClassOne polySubClassOne = factory.newPolySubClassOne();
-        // polySubClassOne.setString("PolySubClassOne 1");
+        PolySubClassOne polySubClassOne = factory.newPolySubClassOne();
+        polySubClassOne.setString("PolySubClassOne 1");
 
-        // PolySubClassTwo polySubClassTwo = factory.newPolySubClassTwo();
-        // polySubClassTwo.setString("PolySubClassTwo 1");
+        PolySubClassTwo polySubClassTwo = factory.newPolySubClassTwo();
+        polySubClassTwo.setString("PolySubClassTwo 1");
 
-        // polyTestClass.getPolyBaseClasses().add(polySubClassOne);
-        // polyTestClass.getPolyBaseClasses().add(polySubClassTwo);
-
-        // factory.save(polySubClassOne);
-        // factory.save(polySubClassTwo);
+        PolySubClassThree polySubClassThree = factory.newPolySubClassThree();
+        polySubClassThree.setString("PolySubClassThree 1");
+        polySubClassThree.setAnotherString("Another String");
+
+        polyTestClass.getPolyBaseClasses().add(polySubClassOne);
+        polyTestClass.getPolyBaseClasses().add(polySubClassTwo);
+        polyTestClass.getPolyBaseClasses().add(polySubClassThree);
+
+        factory.save(polySubClassOne);
+        factory.save(polySubClassTwo);
+        factory.save(polySubClassThree);
 
         // store it and step the state engine
         factory.save(polyTestClass);
@@ -154,6 +165,15 @@ public class PolymorphismTest extends Sq
         getSingletonInstance().setState(1);
     }
 
+    public void testPolymorphicLoad() {
+        final PolyTestClass polyTestClass = SqlIntegrationTestSingleton.getStaticPolyTestClass();
+
+        List<PolyBaseClass> polyBaseClasses = polyTestClass.getPolyBaseClasses();
+        // TODO Polymorphism test temporary disabled
+        // assertEquals(3, polyBaseClasses.size());
+
+    }
+
     public void testInterfaceLoad() {
         final SqlDataClassFactory factory = SqlIntegrationTestSingleton.getSqlDataClassFactory();
         final PolyTestClass polyTestClass = SqlIntegrationTestSingleton.getStaticPolyTestClass();



Mime
View raw message