cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r454066 - /incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/AshwoodEntitySorter.java
Date Sun, 08 Oct 2006 02:20:40 GMT
Author: aadamchik
Date: Sat Oct  7 19:20:40 2006
New Revision: 454066

URL: http://svn.apache.org/viewvc?view=rev&rev=454066
Log:
CAY-680 - switching to ObjectContext

Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/AshwoodEntitySorter.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/AshwoodEntitySorter.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/AshwoodEntitySorter.java?view=diff&rev=454066&r1=454065&r2=454066
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/AshwoodEntitySorter.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/map/AshwoodEntitySorter.java
Sat Oct  7 19:20:40 2006
@@ -29,11 +29,13 @@
 import java.util.Map;
 
 import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.cayenne.DataObject;
+import org.apache.cayenne.DataObjectUtils;
 import org.apache.cayenne.DataRow;
+import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.ObjectId;
-import org.apache.cayenne.PersistenceState;
-import org.apache.cayenne.access.DataContext;
+import org.apache.cayenne.Persistent;
+import org.apache.cayenne.property.ClassDescriptor;
+import org.apache.cayenne.query.ObjectIdQuery;
 import org.apache.commons.collections.comparators.ReverseComparator;
 import org.objectstyle.ashwood.dbutil.DbUtils;
 import org.objectstyle.ashwood.dbutil.ForeignKey;
@@ -161,6 +163,15 @@
         }
 
         int size = objects.size();
+        if (size == 0) {
+            return;
+        }
+
+        EntityResolver resolver = ((Persistent) objects.get(0))
+                .getObjectContext()
+                .getEntityResolver();
+        ClassDescriptor descriptor = resolver.getClassDescriptor(objEntity.getName());
+
         List reflexiveRels = (List) reflexiveDbEntities.get(dbEntity);
         String[] reflexiveRelNames = new String[reflexiveRels.size()];
         for (int i = 0; i < reflexiveRelNames.length; i++) {
@@ -175,7 +186,7 @@
         Digraph objectDependencyGraph = new MapDigraph(MapDigraph.HASHMAP_FACTORY);
         Object[] masters = new Object[reflexiveRelNames.length];
         for (int i = 0; i < size; i++) {
-            DataObject current = (DataObject) objects.get(i);
+            Persistent current = (Persistent) objects.get(i);
             objectDependencyGraph.addVertex(current);
             int actualMasterCount = 0;
             for (int k = 0; k < reflexiveRelNames.length; k++) {
@@ -185,8 +196,8 @@
                     continue;
                 }
 
-                masters[k] = (reflexiveRelName != null) ? current
-                        .readProperty(reflexiveRelName) : null;
+                masters[k] = (reflexiveRelName != null) ? descriptor.getProperty(
+                        reflexiveRelName).readProperty(current) : null;
 
                 if (masters[k] == null) {
                     masters[k] = findReflexiveMaster(current, (ObjRelationship) objEntity
@@ -207,7 +218,7 @@
                     continue;
                 }
 
-                DataObject masterCandidate = (DataObject) objects.get(j);
+                Object masterCandidate = objects.get(j);
                 for (int k = 0; k < masters.length; k++) {
                     if (masterCandidate.equals(masters[k])) {
                         objectDependencyGraph.putArc(
@@ -224,7 +235,7 @@
                 objectDependencyGraph);
 
         while (sorter.hasNext()) {
-            DataObject o = (DataObject) sorter.next();
+            Object o = sorter.next();
             if (o == null)
                 throw new CayenneRuntimeException("Sorting objects for "
                         + objEntity.getClassName()
@@ -283,27 +294,23 @@
         }
     }
 
-    protected DataObject findReflexiveMaster(
-            DataObject object,
+    protected Object findReflexiveMaster(
+            Persistent object,
             ObjRelationship toOneRel,
             String targetEntityName) {
 
         DbRelationship finalRel = (DbRelationship) toOneRel.getDbRelationships().get(0);
-        DataRow snapshot = null;
-        DataContext context = object.getDataContext();
+        ObjectContext context = object.getObjectContext();
 
-        // IMPORTANT: don't try to get snapshots for new objects, this will result in
-        // exception
-        if (object.getPersistenceState() != PersistenceState.NEW) {
-            snapshot = context.getObjectStore().getSnapshot(object.getObjectId());
-        }
-
-        if (snapshot == null) {
-            snapshot = context.currentSnapshot(object);
-        }
+        // find snapshot
+        ObjectIdQuery query = new ObjectIdQuery(
+                object.getObjectId(),
+                true,
+                ObjectIdQuery.CACHE);
+        DataRow snapshot = (DataRow) DataObjectUtils.objectForQuery(context, query);
 
         ObjectId id = snapshot.createTargetObjectId(targetEntityName, finalRel);
-        return (id != null) ? (DataObject) context.localObject(id, null) : null;
+        return (id != null) ? context.localObject(id, null) : null;
     }
 
     protected Comparator getDbEntityComparator(boolean dependantFirst) {



Mime
View raw message