cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From johnth...@apache.org
Subject svn commit: r1489619 - in /cayenne/main/trunk: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/ framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/
Date Tue, 04 Jun 2013 21:25:33 GMT
Author: johnthuss
Date: Tue Jun  4 21:25:21 2013
New Revision: 1489619

URL: http://svn.apache.org/r1489619
Log:
CAY-1832 Exception when modifying objects in postLoad callback

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/BaseContext.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainCallbacksTest.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=1489619&r1=1489618&r2=1489619&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 Tue Jun  4 21:25:21 2013
@@ -83,3 +83,5 @@ CAY-1804 Serialisation of long[] type wa
 CAY-1806 Error importing eomodel 
 CAY-1817 NPE during Validate Project 
 CAY-1827 EhCache region corresponding to a cache group loses its settings after 'removeGroup'
+CAY-1832 Exception when modifying objects in postLoad callback
+

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/BaseContext.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/BaseContext.java?rev=1489619&r1=1489618&r2=1489619&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/BaseContext.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/BaseContext.java
Tue Jun  4 21:25:21 2013
@@ -321,18 +321,18 @@ public abstract class BaseContext implem
                         "Error resolving fault, more than one row exists in the database
for ObjectId: " + oid);
             }
 
+            // 5/28/2013 - Commented out this block to allow for modifying objects in the
postLoad callback
             // sanity check...
-            if (object.getPersistenceState() != PersistenceState.COMMITTED) {
-
-                String state = PersistenceState.persistenceStateName(object.getPersistenceState());
-
-                // TODO: andrus 4/13/2006, modified and deleted states are
-                // possible due to
-                // a race condition, should we handle them here?
-
-                throw new FaultFailureException("Error resolving fault for ObjectId: " +
oid + " and state (" + state
-                        + "). Possible cause - matching row is missing from the database.");
-            }
+//            if (object.getPersistenceState() != PersistenceState.COMMITTED) {
+//
+//                String state = PersistenceState.persistenceStateName(object.getPersistenceState());
+//
+//                // TODO: andrus 4/13/2006, modified and deleted states are
+//                // possible due to
+//                // a race condition, should we handle them here?
+//                throw new FaultFailureException("Error resolving fault for ObjectId: "
+ oid + " and state (" + state
+//                        + "). Possible cause - matching row is missing from the database.");
+//            }
         }
 
         // resolve relationship fault

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainCallbacksTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainCallbacksTest.java?rev=1489619&r1=1489618&r2=1489619&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainCallbacksTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/DataDomainCallbacksTest.java
Tue Jun  4 21:25:21 2013
@@ -18,6 +18,8 @@
  ****************************************************************/
 package org.apache.cayenne.access;
 
+import java.util.List;
+
 import org.apache.cayenne.ObjectContext;
 import org.apache.cayenne.PersistenceState;
 import org.apache.cayenne.Persistent;
@@ -226,6 +228,47 @@ public class DataDomainCallbacksTest ext
         assertSame(a2, listener.getPublicCalledbackEntity());
     }
 
+    public void testPostLoad_ThatModifiesObject() {
+        LifecycleCallbackRegistry registry = resolver.getCallbackRegistry();
+
+        registry.addListener(LifecycleEvent.POST_LOAD, Artist.class, "postLoadCallback");
+        MockCallingBackListener listener = new MockCallingBackListener() {
+        	@Override
+        	public void publicCallback(Object entity) {
+        		super.publicCallback(entity);
+        		Artist a = (Artist)entity;
+        		a.setArtistName("Changed"); // modify object during postLoad callback
+        	}
+        };
+        registry.addListener(
+                LifecycleEvent.POST_LOAD,
+                Artist.class,
+                listener,
+                "publicCallback");
+
+        Artist a1 = context.newObject(Artist.class);
+        a1.setArtistName("XX");
+        Painting p1 = context.newObject(Painting.class);
+        p1.setToArtist(a1);
+        p1.setPaintingTitle("XXX");
+        context.commitChanges();
+
+        context.invalidateObjects(a1, p1);
+
+        SelectQuery q = new SelectQuery(Painting.class);
+        p1 = (Painting) context1.performQuery(q).get(0);
+
+        // this should be a hollow object, so no callback just yet
+        a1 = p1.getToArtist();
+        assertEquals(PersistenceState.HOLLOW, a1.getPersistenceState());
+        assertEquals(0, a1.getPostLoaded());
+        assertNull(listener.getPublicCalledbackEntity());
+
+        a1.getArtistName();
+        assertEquals(1, a1.getPostLoaded());
+        assertSame(a1, listener.getPublicCalledbackEntity());
+    }
+    
     public void testPreUpdate() {
 
         LifecycleCallbackRegistry registry = resolver.getCallbackRegistry();



Mime
View raw message