cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r609468 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/jdbc/ main/java/org/apache/cayenne/reflect/ test/java/org/apache/cayenne/access/ test/java/org/apache/cayenne/reflect/
Date Sun, 06 Jan 2008 23:22:29 GMT
Author: aadamchik
Date: Sun Jan  6 15:22:29 2008
New Revision: 609468

URL: http://svn.apache.org/viewvc?rev=609468&view=rev
Log:
CAY-954 EJBQL Query: Support for single table inheritance
(cleanup/optimization of inheritance handling)

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLJoinAppender.java
    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/access/DataContextEJBQLInheritanceTest.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/access/jdbc/EJBQLJoinAppender.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLJoinAppender.java?rev=609468&r1=609467&r2=609468&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLJoinAppender.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/jdbc/EJBQLJoinAppender.java
Sun Jan  6 15:22:29 2008
@@ -30,8 +30,6 @@
 import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.map.DbJoin;
 import org.apache.cayenne.map.DbRelationship;
-import org.apache.cayenne.map.EntityInheritanceTree;
-import org.apache.cayenne.map.ObjEntity;
 
 /**
  * Handles appending joins to the content buffer at a marked position.
@@ -176,17 +174,9 @@
         // append inheritance qualifier...
         if (id.isPrimaryTable()) {
 
-            // TODO: andrus 1/6/2008 - this is *extremely* inefficient, especially
-            // 'ejbqlQualifierForEntityAndSubclasses'. Cache inheritance qualifier in
-            // the ClassDescriptor
-
-            ObjEntity entity = context.getEntityDescriptor(id.getEntityId()).getEntity();
-            EntityInheritanceTree inheritanceTree = context
-                    .getEntityResolver()
-                    .lookupInheritanceTree(entity);
-
-            Expression qualifier = inheritanceTree != null ? inheritanceTree
-                    .qualifierForEntityAndSubclasses() : entity.getDeclaredQualifier();
+            Expression qualifier = context
+                    .getEntityDescriptor(id.getEntityId())
+                    .getEntityQualifier();
 
             if (qualifier != null) {
 
@@ -235,5 +225,4 @@
 
         return result[0];
     }
-
 }

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=609468&r1=609467&r2=609468&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
Sun Jan  6 15:22:29 2008
@@ -21,6 +21,7 @@
 
 import java.util.Iterator;
 
+import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.ObjEntity;
 
@@ -116,6 +117,14 @@
      * @since 3.0
      */
     Iterator<DbAttribute> getDiscriminatorColumns();
+
+    /**
+     * Returns entity qualifier as a Cayenne expression that includes qualifiers for this
+     * entity and all subentities.
+     * 
+     * @since 3.0
+     */
+    Expression getEntityQualifier();
 
     /**
      * Returns an iterator over the arc properties whose reverse arcs are to-many maps.

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=609468&r1=609467&r2=609468&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
Sun Jan  6 15:22:29 2008
@@ -20,6 +20,7 @@
 
 import java.util.Iterator;
 
+import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.ObjEntity;
 
@@ -76,7 +77,7 @@
     }
 
     public Class<?> getObjectClass() {
-        
+
         // note that we can resolve Object class without triggering descriptor resolution.
         // This is very helpful when compiling POJO relationships
         if (descriptor == null) {
@@ -104,10 +105,15 @@
         checkDescriptorInitialized();
         return descriptor.getIdProperties();
     }
-    
+
     public Iterator<DbAttribute> getDiscriminatorColumns() {
         checkDescriptorInitialized();
         return descriptor.getDiscriminatorColumns();
+    }
+
+    public Expression getEntityQualifier() {
+        checkDescriptorInitialized();
+        return descriptor.getEntityQualifier();
     }
 
     public Iterator<ArcProperty> getMapArcProperties() {

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=609468&r1=609467&r2=609468&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
Sun Jan  6 15:22:29 2008
@@ -26,6 +26,7 @@
 
 import org.apache.cayenne.CayenneRuntimeException;
 import org.apache.cayenne.PersistenceState;
+import org.apache.cayenne.exp.Expression;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
@@ -59,6 +60,7 @@
 
     // inheritance information
     protected Collection<DbAttribute> allDiscriminatorColumns;
+    protected Expression entityQualifier;
 
     /**
      * Creates a PersistentDescriptor.
@@ -380,5 +382,13 @@
 
     public void setSuperclassDescriptor(ClassDescriptor superclassDescriptor) {
         this.superclassDescriptor = superclassDescriptor;
+    }
+
+    public Expression getEntityQualifier() {
+        return entityQualifier;
+    }
+
+    public void setEntityQualifier(Expression entityQualifier) {
+        this.entityQualifier = entityQualifier;
     }
 }

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=609468&r1=609467&r2=609468&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
Sun Jan  6 15:22:29 2008
@@ -216,18 +216,13 @@
     }
 
     protected void indexQualifiers(
-            PersistentDescriptor descriptor,
+            final PersistentDescriptor descriptor,
             EntityInheritanceTree inheritanceTree) {
 
         Expression qualifier;
 
         if (inheritanceTree != null) {
-
             qualifier = inheritanceTree.qualifierForEntityAndSubclasses();
-
-            for (EntityInheritanceTree child : inheritanceTree.getChildren()) {
-                indexQualifiers(descriptor, child);
-            }
         }
         else {
             qualifier = descriptor.getEntity().getDeclaredQualifier();
@@ -253,6 +248,7 @@
             });
 
             descriptor.setDiscriminatorColumns(attributes);
+            descriptor.setEntityQualifier(qualifier);
         }
     }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLInheritanceTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLInheritanceTest.java?rev=609468&r1=609467&r2=609468&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLInheritanceTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataContextEJBQLInheritanceTest.java
Sun Jan  6 15:22:29 2008
@@ -70,7 +70,7 @@
         EJBQLQuery subclass = new EJBQLQuery("select e from Employee e ORDER BY e.name");
 
         List subclassResult = context.performQuery(subclass);
-         assertEquals(4, subclassResult.size());
+        assertEquals(4, subclassResult.size());
 
         assertEquals(Employee.class.getName(), subclassResult.get(0).getClass().getName());
         assertEquals(Employee.class.getName(), subclassResult.get(1).getClass().getName());

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=609468&r1=609467&r2=609468&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
Sun Jan  6 15:22:29 2008
@@ -21,6 +21,8 @@
 
 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.ObjEntity;
 import org.apache.cayenne.reflect.Accessor;
@@ -51,10 +53,14 @@
         return null;
     }
 
+    public Expression getEntityQualifier() {
+        return null;
+    }
+
     public Iterator<Property> getIdProperties() {
         return null;
     }
-    
+
     public Iterator<DbAttribute> getDiscriminatorColumns() {
         return null;
     }
@@ -62,7 +68,7 @@
     public Iterator<ArcProperty> getMapArcProperties() {
         return null;
     }
-    
+
     public ClassDescriptor getSubclassDescriptor(Class<?> objectClass) {
         return this;
     }



Mime
View raw message