cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r794677 - in /cayenne/main/trunk: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/
Date Thu, 16 Jul 2009 13:58:48 GMT
Author: aadamchik
Date: Thu Jul 16 13:58:48 2009
New Revision: 794677

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

Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    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/DbRelationship.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ObjRelationship.java

Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=794677&r1=794676&r2=794677&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Thu Jul 16 13:58:48 2009
@@ -14,6 +14,7 @@
 
 Changes/New Features Since M6:
 
+CAY-132 Intelligent lazy fault detection
 CAY-419 Collections aren't supported with in-memory filtering
 CAY-1116 Add generated PK support to SQLite
 CAY-1225 Controlling JDBC Driver setting "fetchSize" in a SelectQuery
@@ -21,6 +22,7 @@
 CAY-1236 Allow providing custom INSERT, UPDATE, DELETE query builders
 CAY-1241 Add method to ExpressionFactory to match against the primary key of an object or
list of objects
 
+
 Bug Fixes Since M6:
 
 CAY-1169 Weird behavior when adding entity via merging

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=794677&r1=794676&r2=794677&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
Thu Jul 16 13:58:48 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;
@@ -197,8 +196,7 @@
             }
 
             // we can assume that there is one and only one DbRelationship as
-            // we previously checked that
-            // "!isSourceIndependentFromTargetChange"
+            // we previously checked that "!isSourceIndependentFromTargetChange"
             DbRelationship dbRelationship = relationship.getDbRelationships().get(0);
 
             ObjectId targetId = sourceRow.createTargetObjectId(relationship
@@ -217,14 +215,9 @@
                 return DONE;
             }
 
-            ObjEntity targetEntity = (ObjEntity) relationship.getTargetEntity();
-
-            // do not create a target hollow object for qualified entities or entities
-            // involved in inheritance, as the target object may be null even for non-null
-            // FK.
-            if (context != null
-                    && !isQualifiedEntity(targetEntity)
-                    && domain.getEntityResolver().lookupInheritanceTree(targetEntity)
== null) {
+            // check whether a non-null FK is enough to assume non-null target, and if so,
+            // create a fault
+            if (context != null && !relationship.isOptional()) {
 
                 // prevent passing partial snapshots to ObjectResolver per CAY-724. Create
                 // a hollow object right here and skip object conversion downstream
@@ -557,23 +550,6 @@
         return false;
     }
 
-    /**
-     * Returns true if the entity or its super entities have a limiting qualifier.
-     */
-    private boolean isQualifiedEntity(ObjEntity entity) {
-        if (entity.getDeclaredQualifier() != null) {
-            return true;
-        }
-
-        entity = entity.getSuperEntity();
-
-        if (entity == null) {
-            return false;
-        }
-
-        return isQualifiedEntity(entity);
-    }
-
     abstract class ObjectConversionStrategy<T> {
 
         abstract void convert(List<T> mainRows);

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DbRelationship.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DbRelationship.java?rev=794677&r1=794676&r2=794677&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DbRelationship.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DbRelationship.java
Thu Jul 16 13:58:48 2009
@@ -227,11 +227,31 @@
      */
     public boolean isToPK() {
         for (DbJoin join : getJoins()) {
-            if (join.getTarget() == null) {
+            
+            DbAttribute target = join.getTarget();
+            if (target == null) {
+                return false;
+            }
+
+            if (target.isPrimaryKey()) {
+                return true;
+            }
+        }
+
+        return false;
+    }
+    
+    /**
+     * @since 3.0
+     */
+    public boolean isFromPK() {
+        for (DbJoin join : getJoins()) {
+            DbAttribute source = join.getSource();
+            if (source == null) {
                 return false;
             }
 
-            if (join.getTarget().isPrimaryKey()) {
+            if (source.isPrimaryKey()) {
                 return true;
             }
         }

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=794677&r1=794676&r2=794677&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
Thu Jul 16 13:58:48 2009
@@ -275,6 +275,59 @@
         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,
+     * but there are other more subtle cases, such as PK..PK, etc.
+     * 
+     * @since 3.0
+     */
+    public boolean isOptional() {
+        if (isToMany() || isFlattened()) {
+            return true;
+        }
+
+        // entities with qualifiers may result in filtering even existing target rows, so
+        // such relationships are optional
+        if (isQualifiedEntity((ObjEntity) getTargetEntity())) {
+            return true;
+        }
+
+        DbRelationship dbRelationship = getDbRelationships().get(0);
+
+        // to-one mandatory relationships are either from non-PK or to master pk
+        if (dbRelationship.isToPK()) {
+            if (!dbRelationship.isFromPK()) {
+                return false;
+            }
+
+            DbRelationship reverseRelationship = dbRelationship.getReverseRelationship();
+            if (reverseRelationship.isToDependentPK()) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+    
+    /**
+     * Returns true if the entity or its super entities have a limiting qualifier.
+     */
+    private boolean isQualifiedEntity(ObjEntity entity) {
+        if (entity.getDeclaredQualifier() != null) {
+            return true;
+        }
+
+        entity = entity.getSuperEntity();
+
+        if (entity == null) {
+            return false;
+        }
+
+        return isQualifiedEntity(entity);
+    }
+
 
     /**
      * Returns a boolean indicating whether modifying a target of such relationship in any



Mime
View raw message