cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r721817 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/ejbql/parser/ main/java/org/apache/cayenne/map/ main/java/org/apache/cayenne/reflect/ test/java/org/apache/cayenne/reflect/
Date Sun, 30 Nov 2008 14:15:37 GMT
Author: aadamchik
Date: Sun Nov 30 06:15:36 2008
New Revision: 721817

URL: http://svn.apache.org/viewvc?rev=721817&view=rev
Log:
CAY-1136 "Compiled" EntityResult ; Switch SelectQuery processing to use EntityResult

compiled EntityResult (untested, subclasses not included in the descriptor)

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/Compiler.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.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/reflect/MockClassDescriptor.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/Compiler.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/Compiler.java?rev=721817&r1=721816&r2=721817&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/Compiler.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ejbql/parser/Compiler.java
Sun Nov 30 06:15:36 2008
@@ -187,8 +187,6 @@
             }
         };
 
-        // EJBQL queries are polymorphic by definition - there is no distinction between
-        // inheritance/no-inheritance fetch
         descriptor.visitAllProperties(visitor);
 
         // append id columns ... (some may have been appended already via relationships)

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java?rev=721817&r1=721816&r2=721817&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjEntity.java
Sun Nov 30 06:15:36 2008
@@ -47,7 +47,6 @@
 /**
  * ObjEntity is a mapping descriptor for a DataObject Java class. It contains the
  * information about the Java class itself, as well as its mapping to the DbEntity layer.
- * 
  */
 public class ObjEntity extends Entity implements ObjEntityListener {
 
@@ -862,11 +861,14 @@
      * @since 3.0
      */
     public Collection<String> getPrimaryKeyNames() {
-        if (getDbEntity() == null) {
-            throw new CayenneRuntimeException("No DbEntity for ObjEntity: " + getName());
+        DbEntity dbEntity = getDbEntity();
+
+        // abstract entities may have no DbEntity mapping
+        if (dbEntity == null) {
+            return Collections.emptyList();
         }
 
-        Collection<DbAttribute> pkAttributes = getDbEntity().getPrimaryKeys();
+        Collection<DbAttribute> pkAttributes = dbEntity.getPrimaryKeys();
         Collection<String> names = new ArrayList<String>(pkAttributes.size());
 
         for (DbAttribute pk : pkAttributes) {

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=721817&r1=721816&r2=721817&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 Nov 30 06:15:36 2008
@@ -26,6 +26,7 @@
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.query.EntityResult;
 
 /**
  * A runtime descriptor of an persistent class.
@@ -52,6 +53,14 @@
     Collection<DbEntity> getRootDbEntities();
 
     /**
+     * Returns the EntityResult that describes the mapping of the ResultSet when entity
+     * data is fetched.
+     * 
+     * @since 3.0
+     */
+    EntityResult getEntityResult();
+
+    /**
      * Returns a class mapped by this descriptor.
      */
     Class<?> getObjectClass();
@@ -151,7 +160,7 @@
 
     /**
      * Passes the visitor to the properties "visit" method for all properties declared in
-     * this descriptor and all its subdescriptors. Properties that are overridden in
+     * this descriptor and all its super-decsriptors. Properties that are overridden in
      * subdescriptors will include overridden information. Walkthrough is terminated in
      * case one of the properties returns false. Returns true if all visited properties
      * returned true, false - if one property returned false.

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=721817&r1=721816&r2=721817&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 Nov 30 06:15:36 2008
@@ -25,6 +25,7 @@
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.query.EntityResult;
 
 /**
  * A ClassDescriptor wrapper that compiles decorated descriptor lazily on first access.
@@ -82,6 +83,11 @@
         return descriptor.getRootDbEntities();
     }
 
+    public EntityResult getEntityResult() {
+        checkDescriptorInitialized();
+        return descriptor.getEntityResult();
+    }
+
     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=721817&r1=721816&r2=721817&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 Nov 30 06:15:36 2008
@@ -33,6 +33,7 @@
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
+import org.apache.cayenne.query.EntityResult;
 import org.apache.commons.collections.IteratorUtils;
 
 /**
@@ -57,6 +58,7 @@
 
     protected ObjEntity entity;
     protected Collection<DbEntity> rootDbEntities;
+    protected EntityResult entityResult;
 
     // combines declared and super properties
     protected Collection<Property> idProperties;
@@ -173,12 +175,17 @@
         return entity;
     }
 
-    /**
-     * @since 3.0
-     */
     public Collection<DbEntity> getRootDbEntities() {
         return rootDbEntities;
     }
+    
+    public EntityResult getEntityResult() {
+        return entityResult;
+    }
+    
+    public void setEntityResult(EntityResult entityResult) {
+        this.entityResult = entityResult;
+    }
 
     public boolean isFault(Object object) {
         if (superclassDescriptor != null) {

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=721817&r1=721816&r2=721817&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 Nov 30 06:15:36 2008
@@ -19,6 +19,7 @@
 package org.apache.cayenne.reflect;
 
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Set;
 
 import org.apache.cayenne.CayenneRuntimeException;
@@ -27,12 +28,15 @@
 import org.apache.cayenne.map.Attribute;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.DbJoin;
+import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.EmbeddedAttribute;
 import org.apache.cayenne.map.EntityInheritanceTree;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
 import org.apache.cayenne.map.Relationship;
+import org.apache.cayenne.query.EntityResult;
 
 /**
  * A convenience superclass for {@link ClassDescriptorFactory} implementors.
@@ -130,6 +134,7 @@
         indexRootDbEntities(descriptor, inheritanceTree);
 
         indexSuperclassProperties(descriptor);
+        indexEntityResult(descriptor);
 
         return descriptor;
     }
@@ -313,6 +318,70 @@
         }
     }
 
+    protected void indexEntityResult(PersistentDescriptor descriptor) {
+
+        if (descriptor.getRootDbEntities().isEmpty()) {
+            // client descriptor?
+            return;
+        }
+
+        final EntityResult entityResult = new EntityResult(descriptor.getObjectClass());
+        final Set<String> visited = new HashSet<String>();
+
+        PropertyVisitor visitor = new PropertyVisitor() {
+
+            public boolean visitAttribute(AttributeProperty property) {
+                ObjAttribute oa = property.getAttribute();
+                if (visited.add(oa.getDbAttributePath())) {
+                    entityResult.addObjectField(
+                            oa.getEntity().getName(),
+                            oa.getName(),
+                            oa.getDbAttributePath());
+                }
+                return true;
+            }
+
+            public boolean visitToMany(ToManyProperty property) {
+                return true;
+            }
+
+            public boolean visitToOne(ToOneProperty property) {
+                ObjRelationship rel = property.getRelationship();
+                DbRelationship dbRel = rel.getDbRelationships().get(0);
+
+                for (DbJoin join : dbRel.getJoins()) {
+                    DbAttribute src = join.getSource();
+                    if (src.isForeignKey() && visited.add(src.getName())) {
+                        entityResult.addDbField(src.getName(), src.getName());
+                    }
+                }
+
+                return true;
+            }
+        };
+
+        descriptor.visitProperties(visitor);
+
+        // append id columns ... (some may have been appended already via relationships)
+        for (String pkName : descriptor.getEntity().getPrimaryKeyNames()) {
+            if (visited.add(pkName)) {
+                entityResult.addDbField(pkName, pkName);
+            }
+        }
+
+        // append inheritance discriminator columns...
+        Iterator<DbAttribute> discriminatorColumns = descriptor.getDiscriminatorColumns();
+        while (discriminatorColumns.hasNext()) {
+            DbAttribute column = discriminatorColumns.next();
+
+            if (visited.add(column.getName())) {
+                entityResult.addDbField(column.getName(), column.getName());
+            }
+        }
+
+        descriptor.setEntityResult(entityResult);
+    }
+
     /**
      * Creates an accessor for the property.
      */

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=721817&r1=721816&r2=721817&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 Nov 30 06:15:36 2008
@@ -27,6 +27,7 @@
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.query.EntityResult;
 
 public class MockClassDescriptor implements ClassDescriptor {
 
@@ -38,6 +39,10 @@
         return null;
     }
     
+    public EntityResult getEntityResult() {
+        return null;
+    }
+    
     /**
      * @since 3.0
      */



Mime
View raw message