cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r718496 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/reflect/ test/java/org/apache/cayenne/reflect/
Date Tue, 18 Nov 2008 06:33:23 GMT
Author: aadamchik
Date: Mon Nov 17 22:33:22 2008
New Revision: 718496

URL: http://svn.apache.org/viewvc?rev=718496&view=rev
Log:
CAY-795 Horizontal inheritance

adding a method to resolve multiple DbEntity roots to ClassDescriptor

Added:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/ClassDescriptorInheritanceInContextTest.java
      - copied, changed from r718495, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/PersistentDescriptorVisitTest.java
Removed:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/PersistentDescriptorVisitTest.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ClassDescriptor.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/LazyClassDescriptorDecorator.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptor.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/MockClassDescriptor.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ClassDescriptor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ClassDescriptor.java?rev=718496&r1=718495&r2=718496&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ClassDescriptor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ClassDescriptor.java
Mon Nov 17 22:33:22 2008
@@ -19,10 +19,12 @@
 
 package org.apache.cayenne.reflect;
 
+import java.util.Collection;
 import java.util.Iterator;
 
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.ObjEntity;
 
 /**
@@ -40,6 +42,16 @@
     ObjEntity getEntity();
 
     /**
+     * Returns a collection of DbEntities that are the root tables for this descriptor's
+     * ObjEntity. Usually such collection would contain only one entity, however in cases
+     * involving subclass horizontal inheritance, it will be more than one, and in cases
+     * of abstract entities with no subclasses, the collection will be empty.
+     * 
+     * @since 3.0
+     */
+    Collection<DbEntity> getRootDbEntities();
+
+    /**
      * Returns a class mapped by this descriptor.
      */
     Class<?> getObjectClass();

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/LazyClassDescriptorDecorator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/LazyClassDescriptorDecorator.java?rev=718496&r1=718495&r2=718496&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/LazyClassDescriptorDecorator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/LazyClassDescriptorDecorator.java
Mon Nov 17 22:33:22 2008
@@ -18,10 +18,12 @@
  ****************************************************************/
 package org.apache.cayenne.reflect;
 
+import java.util.Collection;
 import java.util.Iterator;
 
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.ObjEntity;
 
 /**
@@ -75,6 +77,11 @@
         return descriptor.getEntity();
     }
 
+    public Collection<DbEntity> getRootDbEntities() {
+        checkDescriptorInitialized();
+        return descriptor.getRootDbEntities();
+    }
+
     public Class<?> getObjectClass() {
 
         // note that we can resolve Object class without triggering descriptor resolution.

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptor.java?rev=718496&r1=718495&r2=718496&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptor.java
Mon Nov 17 22:33:22 2008
@@ -21,6 +21,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -28,6 +29,7 @@
 import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
@@ -54,6 +56,7 @@
     protected Accessor persistenceStateAccessor;
 
     protected ObjEntity entity;
+    protected Collection<DbEntity> rootDbEntities;
 
     // combines declared and super properties
     protected Collection<Property> idProperties;
@@ -72,6 +75,7 @@
         this.declaredProperties = new HashMap<String, Property>();
         this.superProperties = new HashMap<String, Property>();
         this.subclassDescriptors = new HashMap<String, ClassDescriptor>();
+        this.rootDbEntities = new HashSet<DbEntity>(1);
     }
 
     public void setDiscriminatorColumns(Collection<DbAttribute> columns) {
@@ -100,6 +104,13 @@
         indexAddedProperty(property);
     }
 
+    /**
+     * Adds a root DbEntity to the list of roots, filtering duplicates.
+     */
+    public void addRootDbEntity(DbEntity dbEntity) {
+        this.rootDbEntities.add(dbEntity);
+    }
+
     void indexAddedProperty(Property property) {
         if (property instanceof AttributeProperty) {
             ObjAttribute attribute = ((AttributeProperty) property).getAttribute();
@@ -160,6 +171,13 @@
         return entity;
     }
 
+    /**
+     * @since 3.0
+     */
+    public Collection<DbEntity> getRootDbEntities() {
+        return rootDbEntities;
+    }
+
     public boolean isFault(Object object) {
         if (superclassDescriptor != null) {
             return superclassDescriptor.isFault(object);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java?rev=718496&r1=718495&r2=718496&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java
Mon Nov 17 22:33:22 2008
@@ -125,6 +125,10 @@
                 .lookupInheritanceTree(descriptor.getEntity());
         indexSubclassDescriptors(descriptor, inheritanceTree);
         indexQualifiers(descriptor, inheritanceTree);
+
+        appendDeclaredRootDbEntity(descriptor, descriptor.getEntity());
+        indexRootDbEntities(descriptor, inheritanceTree);
+
         indexSuperclassProperties(descriptor);
 
         return descriptor;
@@ -216,6 +220,38 @@
         }
     }
 
+    protected void indexRootDbEntities(
+            PersistentDescriptor descriptor,
+            EntityInheritanceTree inheritanceTree) {
+
+        if (inheritanceTree != null) {
+
+            for (EntityInheritanceTree child : inheritanceTree.getChildren()) {
+                ObjEntity childEntity = child.getEntity();
+                appendDeclaredRootDbEntity(descriptor, childEntity);
+                indexRootDbEntities(descriptor, child);
+            }
+        }
+    }
+
+    private void appendDeclaredRootDbEntity(
+            PersistentDescriptor descriptor,
+            ObjEntity entity) {
+        // since we don't want the entity to look up its super DbEntity (which is
+        // already registered), lookup DbEntity ourselves by name
+        String dbEntityName = entity.getDbEntityName();
+        if (dbEntityName != null) {
+
+            DbEntity dbEntity = entity.getDataMap().getDbEntity(dbEntityName);
+            if (dbEntity != null) {
+
+                // descriptor takes care of weeding off duplicates, although the duplicate
+                // here is highly unlikely
+                descriptor.addRootDbEntity(dbEntity);
+            }
+        }
+    }
+
     protected void indexQualifiers(
             final PersistentDescriptor descriptor,
             EntityInheritanceTree inheritanceTree) {

Copied: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/ClassDescriptorInheritanceInContextTest.java
(from r718495, cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/PersistentDescriptorVisitTest.java)
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/ClassDescriptorInheritanceInContextTest.java?p2=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/ClassDescriptorInheritanceInContextTest.java&p1=cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/PersistentDescriptorVisitTest.java&r1=718495&r2=718496&rev=718496&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/PersistentDescriptorVisitTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/ClassDescriptorInheritanceInContextTest.java
Mon Nov 17 22:33:22 2008
@@ -18,11 +18,14 @@
  ****************************************************************/
 package org.apache.cayenne.reflect;
 
+import java.util.Collection;
+
+import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.testdo.horizontalinherit.SubEntity2;
 import org.apache.cayenne.unit.InheritanceCase;
 
-public class PersistentDescriptorVisitTest extends InheritanceCase {
+public class ClassDescriptorInheritanceInContextTest extends InheritanceCase {
 
     public void testVisitDeclaredProperties() {
 
@@ -102,4 +105,22 @@
 
         assertEquals(3, attributeCount[0]);
     }
+
+    public void testGetRootDbEntities() {
+        ClassDescriptor abstractSuper = getDomain()
+                .getEntityResolver()
+                .getClassDescriptor("AbstractSuperEntity");
+        Collection<DbEntity> abstractSuperRoots = abstractSuper.getRootDbEntities();
+        assertEquals(3, abstractSuperRoots.size());
+
+        ClassDescriptor sub1 = getDomain().getEntityResolver().getClassDescriptor(
+                "SubEntity1");
+        Collection<DbEntity> sub1Roots = sub1.getRootDbEntities();
+        assertEquals(1, sub1Roots.size());
+
+        ClassDescriptor sub2 = getDomain().getEntityResolver().getClassDescriptor(
+                "SubEntity2");
+        Collection<DbEntity> sub2Roots = sub2.getRootDbEntities();
+        assertEquals(1, sub2Roots.size());
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/MockClassDescriptor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/MockClassDescriptor.java?rev=718496&r1=718495&r2=718496&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/MockClassDescriptor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/reflect/MockClassDescriptor.java
Mon Nov 17 22:33:22 2008
@@ -19,17 +19,14 @@
 
 package org.apache.cayenne.reflect;
 
+import java.util.Collection;
+import java.util.Collections;
 import java.util.Iterator;
 
-import org.apache.cayenne.ejbql.EJBQLExpression;
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.ObjEntity;
-import org.apache.cayenne.reflect.Accessor;
-import org.apache.cayenne.reflect.ClassDescriptor;
-import org.apache.cayenne.reflect.Property;
-import org.apache.cayenne.reflect.PropertyException;
-import org.apache.cayenne.reflect.PropertyVisitor;
 
 public class MockClassDescriptor implements ClassDescriptor {
 
@@ -40,6 +37,13 @@
     public ObjEntity getEntity() {
         return null;
     }
+    
+    /**
+     * @since 3.0
+     */
+    public Collection<DbEntity> getRootDbEntities() {
+        return Collections.emptyList();
+    }
 
     public boolean isFault(Object object) {
         return false;



Mime
View raw message