This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/master by this push:
     new 07584e14c3 ISIS-3126: [JDO] just some polishing/comments
07584e14c3 is described below

commit 07584e14c367e0455a523e05e60472539bd601b7
Author: andi-huber <[email protected]>
AuthorDate: Fri Aug 19 21:42:25 2022 +0200

    ISIS-3126: [JDO] just some polishing/comments
---
 .../datanucleus/changetracking/JdoLifecycleListener.java    | 12 +++---------
 .../jdo/datanucleus/entities/DnObjectProviderForIsis.java   | 13 ++++++++++++-
 2 files changed, 15 insertions(+), 10 deletions(-)

diff --git 
a/persistence/jdo/datanucleus/src/main/java/org/apache/isis/persistence/jdo/datanucleus/changetracking/JdoLifecycleListener.java
 
b/persistence/jdo/datanucleus/src/main/java/org/apache/isis/persistence/jdo/datanucleus/changetracking/JdoLifecycleListener.java
index 3d009adafd..ca2b86c4ab 100644
--- 
a/persistence/jdo/datanucleus/src/main/java/org/apache/isis/persistence/jdo/datanucleus/changetracking/JdoLifecycleListener.java
+++ 
b/persistence/jdo/datanucleus/src/main/java/org/apache/isis/persistence/jdo/datanucleus/changetracking/JdoLifecycleListener.java
@@ -140,18 +140,12 @@ DetachLifecycleListener, DirtyLifecycleListener, 
LoadLifecycleListener, StoreLif
         final Persistable pojo = _Utils.persistableFor(event);
         final Runnable doPreDirty = ()->doPreDirty(pojo);
 
-
-
+        // [ISIS-3126] pre-dirty nested loop prevention,
+        // assuming we can cast the DN StateManager to the custom one as 
provided by the framework
         _Casts.castTo(DnObjectProviderForIsis.class, pojo.dnGetStateManager())
         .ifPresentOrElse(stateManager->
                 
stateManager.acquirePreDirtyPropagationLock(pojo.dnGetObjectId())
-                .ifPresent(lock->{
-                    try {
-                        doPreDirty.run();
-                    } finally {
-                        lock.release();
-                    }
-                }),
+                .ifPresent(lock->lock.releaseAfter(doPreDirty)),
                 doPreDirty);
     }
 
diff --git 
a/persistence/jdo/datanucleus/src/main/java/org/apache/isis/persistence/jdo/datanucleus/entities/DnObjectProviderForIsis.java
 
b/persistence/jdo/datanucleus/src/main/java/org/apache/isis/persistence/jdo/datanucleus/entities/DnObjectProviderForIsis.java
index f52c017ef4..1abbcb9c8f 100644
--- 
a/persistence/jdo/datanucleus/src/main/java/org/apache/isis/persistence/jdo/datanucleus/entities/DnObjectProviderForIsis.java
+++ 
b/persistence/jdo/datanucleus/src/main/java/org/apache/isis/persistence/jdo/datanucleus/entities/DnObjectProviderForIsis.java
@@ -156,11 +156,18 @@ extends ReferentialStateManagerImpl {
         }
     }
 
-    // -- PRE-DIRTY NESTED LOOP PREVENTION
+    // -- [ISIS-3126] PRE-DIRTY NESTED LOOP PREVENTION
 
     @FunctionalInterface
     public static interface PreDirtyPropagationLock {
         void release();
+        default void releaseAfter(final Runnable runnable) {
+            try {
+                runnable.run();
+            } finally {
+                release();
+            }
+        }
     }
 
     // assuming we don't require thread-safety here,
@@ -172,6 +179,10 @@ extends ReferentialStateManagerImpl {
         return ()->preDirtyPropagationLocks.remove(id);
     }
 
+    /**
+     * Optionally provides a {@link PreDirtyPropagationLock} for pre-dirty 
event propagation,
+     * based on whether there is NOT already an pre-dirty event in progress 
for the same OID.
+     */
     public Optional<PreDirtyPropagationLock> 
acquirePreDirtyPropagationLock(final Object id) {
 
         // this algorithm is not thread-safe

Reply via email to