cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r811834 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne: access/DataDomainQueryAction.java map/EntityResolver.java map/ObjRelationship.java
Date Sun, 06 Sep 2009 16:36:26 GMT
Author: aadamchik
Date: Sun Sep  6 16:36:25 2009
New Revision: 811834

URL: http://svn.apache.org/viewvc?rev=811834&view=rev
Log:
CAY-132 Intelligent lazy fault detection

refactoring

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java?rev=811834&r1=811833&r2=811834&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataDomainQueryAction.java
Sun Sep  6 16:36:25 2009
@@ -38,7 +38,6 @@
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.LifecycleEvent;
-import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
 import org.apache.cayenne.query.EntityResultSegment;
 import org.apache.cayenne.query.ObjectIdQuery;
@@ -218,22 +217,18 @@
 
             // check whether a non-null FK is enough to assume non-null target, and if so,
             // create a fault
-            if (context != null && !relationship.isOptional()) {
+            if (context != null
+                    && relationship.isSourceDefiningTargetPrecenseAndType(domain
+                            .getEntityResolver())) {
+
+                // prevent passing partial snapshots to ObjectResolver per CAY-724.
+                // Create
+                // a hollow object right here and skip object conversion downstream
+                this.noObjectConversion = true;
+                Object object = context.localObject(targetId, null);
 
-                // final check (how do we do it in relationship.isOptional()??) - is
-                // inheritance involved
-                ObjEntity targetEntity = (ObjEntity) relationship.getTargetEntity();
-                if (domain.getEntityResolver().lookupInheritanceTree(targetEntity) == null)
{
-
-                    // prevent passing partial snapshots to ObjectResolver per CAY-724.
-                    // Create
-                    // a hollow object right here and skip object conversion downstream
-                    this.noObjectConversion = true;
-                    Object object = context.localObject(targetId, null);
-
-                    this.response = new GenericResponse(Collections.singletonList(object));
-                    return DONE;
-                }
+                this.response = new GenericResponse(Collections.singletonList(object));
+                return DONE;
             }
         }
 

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java?rev=811834&r1=811833&r2=811834&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EntityResolver.java
Sun Sep  6 16:36:25 2009
@@ -89,9 +89,10 @@
     public EntityResolver() {
         init();
     }
-    
+
     /**
-     * Initialization of EntityResolver. Used in constructor and in Java deserialization
process
+     * Initialization of EntityResolver. Used in constructor and in Java deserialization
+     * process
      */
     private void init() {
         this.indexedByClass = true;
@@ -394,7 +395,7 @@
 
         return c;
     }
-    
+
     /**
      * @since 3.0
      */
@@ -403,7 +404,7 @@
         for (DataMap map : getDataMaps()) {
             c.addComposited(map.getResults());
         }
-        
+
         return c;
     }
 
@@ -456,7 +457,7 @@
 
         return result;
     }
-    
+
     /**
      * @since 3.0
      */
@@ -680,8 +681,19 @@
      * known subentities, null is returned.
      */
     public EntityInheritanceTree lookupInheritanceTree(ObjEntity entity) {
+        return lookupInheritanceTree(entity.getName());
+    }
+
+    /**
+     * Returns EntityInheritanceTree representing inheritance hierarchy that starts with
a
+     * given ObjEntity as root, and includes all its subentities. If ObjEntity has no
+     * known subentities, null is returned.
+     * 
+     * @since 3.0
+     */
+    public EntityInheritanceTree lookupInheritanceTree(String entityName) {
 
-        EntityInheritanceTree tree = entityInheritanceCache.get(entity.getName());
+        EntityInheritanceTree tree = entityInheritanceCache.get(entityName);
 
         if (tree == null) {
             // since we keep inheritance trees for all entities, null means
@@ -690,7 +702,7 @@
             // rebuild cache just in case some of the datamaps
             // have changed and now contain the required information
             constructCache();
-            tree = entityInheritanceCache.get(entity.getName());
+            tree = entityInheritanceCache.get(entityName);
         }
 
         // don't return "trivial" trees
@@ -911,10 +923,11 @@
     }
 
     /**
-     * Java default deserialization seems not to invoke constructor by default - 
-     * invoking it manually
+     * Java default deserialization seems not to invoke constructor by default - invoking
+     * it manually
      */
-    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
{
+    private void readObject(ObjectInputStream in) throws IOException,
+            ClassNotFoundException {
         init();
         in.defaultReadObject();
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java?rev=811834&r1=811833&r2=811834&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java
Sun Sep  6 16:36:25 2009
@@ -37,7 +37,6 @@
 /**
  * Describes an association between two Java classes mapped as source and target
  * ObjEntity. Maps to a path of DbRelationships.
- * 
  */
 public class ObjRelationship extends Relationship {
 
@@ -277,7 +276,7 @@
         this.readOnly = false;
         this.toMany = false;
     }
-    
+
     /**
      * Returns a boolean indicating whether the presence of a non-null source key(s) will
      * not guarantee a presence of a target record. PK..FK relationships are all optional,
@@ -312,7 +311,17 @@
 
         return true;
     }
-    
+
+    /**
+     * Returns true if the relationship is non-optional and target has no subclasses.
+     * 
+     * @since 3.0
+     */
+    public boolean isSourceDefiningTargetPrecenseAndType(EntityResolver entityResolver) {
+        return !isOptional()
+                && entityResolver.lookupInheritanceTree(getTargetEntityName()) ==
null;
+    }
+
     /**
      * Returns true if the entity or its super entities have a limiting qualifier.
      */
@@ -330,7 +339,6 @@
         return isQualifiedEntity(entity);
     }
 
-
     /**
      * Returns a boolean indicating whether modifying a target of such relationship in any
      * way will not change the underlying table row of the source.
@@ -725,8 +733,8 @@
      * Returns a property name of a target entity used to create a relationship map. Only
      * has effect if collectionType property is set to "java.util.Map".
      * 
-     * @return The attribute name used for the map key or <code>null</code> if
the
-     *         default (PK) is used as the map key.
+     * @return The attribute name used for the map key or <code>null</code> if
the default
+     *         (PK) is used as the map key.
      * @since 3.0
      */
     public String getMapKey() {



Mime
View raw message