openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From allee8...@apache.org
Subject svn commit: r708722 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestMessageListeners.java
Date Tue, 28 Oct 2008 23:31:10 GMT
Author: allee8285
Date: Tue Oct 28 16:31:09 2008
New Revision: 708722

URL: http://svn.apache.org/viewvc?rev=708722&view=rev
Log:
OPENJPA-754 - Add additional condition to determine if the pre/postUpdate callback should
be called.

Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
    openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestMessageListeners.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java?rev=708722&r1=708721&r2=708722&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
Tue Oct 28 16:31:09 2008
@@ -976,6 +976,8 @@
             boolean wasNew = isNew();
             boolean wasFlushed = isFlushed();
             boolean wasDeleted = isDeleted();
+            boolean needPostUpdate = !(wasNew && !wasFlushed)
+					&& (ImplHelper.getUpdateFields(this) != null);
 
             // all dirty fields were flushed
             _flush.or(_dirty);
@@ -1003,7 +1005,7 @@
                 fireLifecycleEvent(LifecycleEvent.AFTER_PERSIST_PERFORMED);
             else if (wasDeleted)
                 fireLifecycleEvent(LifecycleEvent.AFTER_DELETE_PERFORMED);
-            else 
+            else if (needPostUpdate)
                 // updates and new-flushed with changes
                 fireLifecycleEvent(LifecycleEvent.AFTER_UPDATE_PERFORMED);
         } else if (reason == BrokerImpl.FLUSH_ROLLBACK) {
@@ -2813,7 +2815,8 @@
             // BEFORE_PERSIST is handled during Broker.persist and Broker.attach
             if (isDeleted())
                 fireLifecycleEvent(LifecycleEvent.BEFORE_DELETE);
-            else if (!(isNew() && !isFlushed()))
+            else if (!(isNew() && !isFlushed())
+				&& (ImplHelper.getUpdateFields(this) != null))
                 fireLifecycleEvent(LifecycleEvent.BEFORE_UPDATE);
             _flags |= FLAG_PRE_FLUSHED;
         }

Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestMessageListeners.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestMessageListeners.java?rev=708722&r1=708721&r2=708722&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestMessageListeners.java
(original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/callbacks/TestMessageListeners.java
Tue Oct 28 16:31:09 2008
@@ -155,8 +155,16 @@
 
             em.getTransaction().commit();
 
-            // Complete the 2nd @postPersist and the @preUpdate caused by
-            // setters calls in @postPersist
+            // Complete the 2nd @postPersist
+            assertStatus(2, 2, 0, 0, 0, 0, 0);
+
+			// Make an update to trigger the pre/postUpdater callbacks
+            em.getTransaction().begin();
+            message = em.find(Message.class,message.getId());
+            message.setMessage("Update field and trigger pre/postUpdate");
+            em.getTransaction().commit();
+            
+            // Complete the 2nd @postPersist
             assertStatus(2, 2, 1, 1, 0, 0, 0);
 
         } finally {



Mime
View raw message