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

danhaywood pushed a commit to branch CAUSEWAY-3799
in repository https://gitbox.apache.org/repos/asf/causeway.git


The following commit(s) were added to refs/heads/CAUSEWAY-3799 by this push:
     new 251302bcc0 CAUSEWAY-3799: moves the writing out of audit trail entries
251302bcc0 is described below

commit 251302bcc0018c6941d388f78aa8bbd3e182eacf
Author: Dan Haywood <[email protected]>
AuthorDate: Fri Jun 28 10:25:13 2024 +0100

    CAUSEWAY-3799: moves the writing out of audit trail entries
    
    to the beforeCommit rather than beforeCompletion callback
---
 .../changetracking/EntityChangeTrackerDefault.java | 30 +++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git 
a/persistence/commons/src/main/java/org/apache/causeway/persistence/commons/integration/changetracking/EntityChangeTrackerDefault.java
 
b/persistence/commons/src/main/java/org/apache/causeway/persistence/commons/integration/changetracking/EntityChangeTrackerDefault.java
index c022e1b08a..d14d54a7ff 100644
--- 
a/persistence/commons/src/main/java/org/apache/causeway/persistence/commons/integration/changetracking/EntityChangeTrackerDefault.java
+++ 
b/persistence/commons/src/main/java/org/apache/causeway/persistence/commons/integration/changetracking/EntityChangeTrackerDefault.java
@@ -270,6 +270,10 @@ implements
             log.debug("EntityChangeTrackerDefault.destroy xactn={} 
interactionId={} thread={}", transactionCounter.get(), interactionId, 
Thread.currentThread().getName());
         }
 
+        clearAndReset();
+    }
+
+    private void clearAndReset() {
         enlistedPropertyChangeRecordsById.clear();
         changes.clear();
 
@@ -281,7 +285,6 @@ implements
     }
 
 
-
     /**
      * @implNote sets a lock on the {@code enlistedPropertyChangeRecordsById} 
{@link Map}
      *      until given {@code runnable} completes<p>
@@ -325,10 +328,13 @@ implements
     }
 
     @Override
-    public void beforeCompletion() {
+    public void beforeCommit(boolean readOnly) {
         _Xray.publish(this, interactionProviderProvider);
 
-        log.debug("about to publish entity changes");
+        if(log.isDebugEnabled()) {
+            val interactionId = 
interactionProviderProvider.get().currentInteraction().map(Interaction::getInteractionId).orElse(null);
+            log.debug("EntityChangeTrackerDefault.beforeCommit(readOnly={}) 
xactn={} interactionId={} thread={}", readOnly, transactionCounter.get(), 
interactionId, Thread.currentThread().getName());
+        }
 
         // we memoize the property changes to (hopefully) avoid 
ConcurrentModificationExceptions with ourselves later
         memoizeChangesIfRequired();
@@ -337,6 +343,24 @@ implements
         entityChangesPublisher.publishChangingEntities(this);
     }
 
+    @Override
+    public void afterCompletion(int status) {
+
+        if(log.isDebugEnabled()) {
+            val interactionId = 
interactionProviderProvider.get().currentInteraction().map(Interaction::getInteractionId).orElse(null);
+            log.debug("EntityChangeTrackerDefault.afterCompletion(status={}) 
xactn={} interactionId={} thread={}", decodeStatus(status), 
transactionCounter.get(), interactionId, Thread.currentThread().getName());
+        }
+
+        clearAndReset();
+    }
+
+    private static String decodeStatus(int status) {
+        if (status == STATUS_COMMITTED) return "STATUS_COMMITTED";
+        if (status == STATUS_ROLLED_BACK) return "STATUS_ROLLED_BACK";
+        if (status == STATUS_UNKNOWN) return "STATUS_UNKNOWN";
+        return status + " [not recognised]";
+    }
+
     private void enableCommandPublishing() {
         val alreadySet = persistentChangesEncountered.getAndSet(true);
         if(!alreadySet) {

Reply via email to