cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1234358 - in /cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access: DataContext.java DataDomainQueryAction.java DataRowUtils.java ObjectResolver.java
Date Sat, 21 Jan 2012 16:22:19 GMT
Author: aadamchik
Date: Sat Jan 21 16:22:18 2012
New Revision: 1234358

URL: http://svn.apache.org/viewvc?rev=1234358&view=rev
Log:
CAY-1616 Remove internal dependencies on deprecated ObjectContext.localObject

turns out all non-merge versions of the old localObject call are done on DataContext,
not on generic ObjectContext, and are scoped inside access package. So I just created
a package provate method for this case

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java
    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/access/DataRowUtils.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ObjectResolver.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java?rev=1234358&r1=1234357&r2=1234358&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataContext.java
Sat Jan 21 16:22:18 2012
@@ -1135,6 +1135,60 @@ public class DataContext extends BaseCon
     }
 
     /**
+     * An internal version of {@link #localObject(Object)} that operates on ObjectId
+     * instead of Persistent, and wouldn't attempt to look up an object in the parent
+     * channel.
+     * 
+     * @since 3.1
+     */
+    Persistent findOrCreateObject(ObjectId id) {
+
+        if (id == null) {
+            throw new IllegalArgumentException("Null ObjectId");
+        }
+
+        // have to synchronize almost the entire method to prevent multiple threads from
+        // messing up dataobjects per CAY-845. Originally only parts of "else" were
+        // synchronized, but we had to expand the lock scope to ensure consistent
+        // behavior.
+        synchronized (getGraphManager()) {
+            Persistent cachedObject = (Persistent) getGraphManager().getNode(id);
+
+            // return an existing object
+            if (cachedObject != null) {
+
+                int state = cachedObject.getPersistenceState();
+
+                // TODO: Andrus, 1/24/2006 implement smart merge for modified objects...
+                if (state != PersistenceState.MODIFIED
+                        && state != PersistenceState.DELETED) {
+
+                    ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(
+                            id.getEntityName());
+
+                    descriptor.injectValueHolders(cachedObject);
+                }
+
+                return cachedObject;
+            }
+
+            // create and register a hollow object
+            ClassDescriptor descriptor = getEntityResolver().getClassDescriptor(
+                    id.getEntityName());
+            Persistent localObject = (Persistent) descriptor.createObject();
+
+            localObject.setObjectContext(this);
+            localObject.setObjectId(id);
+
+            getGraphManager().registerNode(id, localObject);
+            localObject.setPersistenceState(PersistenceState.HOLLOW);
+
+            return localObject;
+        }
+
+    }
+
+    /**
      * Returns an object local to this DataContext and matching the ObjectId. If
      * <code>prototype</code> is not null, local object is refreshed with the
prototype
      * values.

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=1234358&r1=1234357&r2=1234358&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
Sat Jan 21 16:22:18 2012
@@ -203,8 +203,9 @@ class DataDomainQueryAction implements Q
             // we previously checked that "!isSourceIndependentFromTargetChange"
             DbRelationship dbRelationship = relationship.getDbRelationships().get(0);
 
-            ObjectId targetId = sourceRow.createTargetObjectId(relationship
-                    .getTargetEntityName(), dbRelationship);
+            ObjectId targetId = sourceRow.createTargetObjectId(
+                    relationship.getTargetEntityName(),
+                    dbRelationship);
 
             // null id means that FK is null...
             if (targetId == null) {
@@ -226,10 +227,9 @@ class DataDomainQueryAction implements Q
                             .getEntityResolver())) {
 
                 // prevent passing partial snapshots to ObjectResolver per CAY-724.
-                // Create
-                // a hollow object right here and skip object conversion downstream
+                // Create a hollow object right here and skip object conversion downstream
                 this.noObjectConversion = true;
-                Object object = context.localObject(targetId, null);
+                Object object = context.findOrCreateObject(targetId);
 
                 this.response = new GenericResponse(Collections.singletonList(object));
                 return DONE;
@@ -568,8 +568,10 @@ class DataDomainQueryAction implements Q
 
             // take a shortcut when no prefetches exist...
             if (prefetchTree == null) {
-                return new ObjectResolver(context, descriptor, metadata
-                        .isRefreshingObjects())
+                return new ObjectResolver(
+                        context,
+                        descriptor,
+                        metadata.isRefreshingObjects())
                         .synchronizedRootResultNodeFromDataRows(normalizedRows);
             }
             else {
@@ -678,8 +680,10 @@ class DataDomainQueryAction implements Q
             }
 
             if (prefetchTree == null) {
-                return new ObjectResolver(context, descriptor, metadata
-                        .isRefreshingObjects())
+                return new ObjectResolver(
+                        context,
+                        descriptor,
+                        metadata.isRefreshingObjects())
                         .synchronizedRootResultNodeFromDataRows(rowsColumn);
             }
             else {
@@ -705,7 +709,8 @@ class DataDomainQueryAction implements Q
 
             // no conversions needed for scalar positions; reuse Object[]'s to fill them
             // with resolved objects
-            List<PrefetchProcessorNode> segmentNodes = new ArrayList<PrefetchProcessorNode>(width);
+            List<PrefetchProcessorNode> segmentNodes = new ArrayList<PrefetchProcessorNode>(
+                    width);
             for (int i = 0; i < width; i++) {
 
                 if (rsMapping.get(i) instanceof EntityResultSegment) {
@@ -718,7 +723,7 @@ class DataDomainQueryAction implements Q
                             i);
 
                     segmentNodes.add(nextResult);
-                    
+
                     List<Persistent> objects = nextResult.getObjects();
 
                     for (int j = 0; j < rowsLen; j++) {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataRowUtils.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataRowUtils.java?rev=1234358&r1=1234357&r2=1234358&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataRowUtils.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataRowUtils.java
Sat Jan 21 16:22:18 2012
@@ -181,8 +181,9 @@ class DataRowUtils {
                         // must check before creating ObjectId because of partial
                         // snapshots
                         if (hasFK(dbRelationship, snapshot)) {
-                            ObjectId id = snapshot.createTargetObjectId(relationship
-                                    .getTargetEntityName(), dbRelationship);
+                            ObjectId id = snapshot.createTargetObjectId(
+                                    relationship.getTargetEntityName(),
+                                    dbRelationship);
 
                             if (diff == null
                                     || !diff.containsArcSnapshot(relationship.getName())
@@ -202,8 +203,10 @@ class DataRowUtils {
                                         property.invalidate(object);
                                     }
                                     else {
-                                        property.writeProperty(object, null, context
-                                                .localObject(id, null));
+                                        property.writeProperty(
+                                                object,
+                                                null,
+                                                context.findOrCreateObject(id));
                                     }
                                 }
                             }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ObjectResolver.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ObjectResolver.java?rev=1234358&r1=1234357&r2=1234358&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ObjectResolver.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/ObjectResolver.java
Sat Jan 21 16:22:18 2012
@@ -148,7 +148,7 @@ class ObjectResolver {
         }
 
         // this will create a HOLLOW object if it is not registered yet
-        Persistent object = context.localObject(anId, null);
+        Persistent object = context.findOrCreateObject(anId);
 
         // deal with object state
         int state = object.getPersistenceState();



Mime
View raw message