You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2026/09/12 14:11:11 UTC

(cayenne) branch master updated: CAY-3017 ObjectContext should not be a DataChannel

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

asf-gitbox-commits pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cayenne.git


The following commit(s) were added to refs/heads/master by this push:
     new 8b5bfc48c CAY-3017 ObjectContext should not be a DataChannel
8b5bfc48c is described below

commit 8b5bfc48ceb304b11192343ddb5d32d42fe03555
Author: Andrus Adamchik <an...@objectstyle.com>
AuthorDate: Sat Sep 12 10:08:53 2026 -0400

    CAY-3017 ObjectContext should not be a DataChannel
    
        smarter channel adapter
---
 .../org/apache/cayenne/access/DataContext.java     | 20 --------------------
 .../apache/cayenne/access/DataContextChannel.java  | 22 ++++++++++++++++++++--
 2 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/cayenne/src/main/java/org/apache/cayenne/access/DataContext.java b/cayenne/src/main/java/org/apache/cayenne/access/DataContext.java
index e4fd11d7f..ddf3a163b 100644
--- a/cayenne/src/main/java/org/apache/cayenne/access/DataContext.java
+++ b/cayenne/src/main/java/org/apache/cayenne/access/DataContext.java
@@ -36,7 +36,6 @@ import org.apache.cayenne.cache.QueryCache;
 import org.apache.cayenne.event.EventManager;
 import org.apache.cayenne.exp.ValueInjector;
 import org.apache.cayenne.graph.ArcId;
-import org.apache.cayenne.graph.ChildDiffLoader;
 import org.apache.cayenne.graph.CompoundDiff;
 import org.apache.cayenne.graph.GraphDiff;
 import org.apache.cayenne.graph.GraphEvent;
@@ -879,25 +878,6 @@ public class DataContext implements ObjectContext {
         flushToParent(true);
     }
 
-    protected GraphDiff onContextFlush(ObjectContext originatingContext, GraphDiff changes, boolean cascade) {
-
-        boolean childContext = this != originatingContext && changes != null;
-
-        try {
-            if (childContext) {
-                getObjectStore().childContextSyncStarted();
-                changes.apply(new ChildDiffLoader(this));
-                fireDataChannelChanged(originatingContext, changes);
-            }
-
-            return (cascade) ? flushToParent(true) : new CompoundDiff();
-        } finally {
-            if (childContext) {
-                getObjectStore().childContextSyncStopped();
-            }
-        }
-    }
-
     /**
      * Synchronizes with the parent channel, performing a flush or a commit.
      *
diff --git a/cayenne/src/main/java/org/apache/cayenne/access/DataContextChannel.java b/cayenne/src/main/java/org/apache/cayenne/access/DataContextChannel.java
index 5f8c7abb6..001ea3074 100644
--- a/cayenne/src/main/java/org/apache/cayenne/access/DataContextChannel.java
+++ b/cayenne/src/main/java/org/apache/cayenne/access/DataContextChannel.java
@@ -26,6 +26,7 @@ import org.apache.cayenne.ObjectId;
 import org.apache.cayenne.Persistent;
 import org.apache.cayenne.QueryResponse;
 import org.apache.cayenne.event.EventManager;
+import org.apache.cayenne.graph.ChildDiffLoader;
 import org.apache.cayenne.graph.CompoundDiff;
 import org.apache.cayenne.graph.GraphDiff;
 import org.apache.cayenne.map.EntityResolver;
@@ -109,12 +110,29 @@ public record DataContextChannel(DataContext context) implements DataChannel {
                 context.rollbackChanges();
                 yield new CompoundDiff();
             }
-            case DataChannel.FLUSH_NOCASCADE_SYNC -> context.onContextFlush(childContext, changes, false);
-            case DataChannel.FLUSH_CASCADE_SYNC -> context.onContextFlush(childContext, changes, true);
+            case DataChannel.FLUSH_NOCASCADE_SYNC -> flushChildChanges(childContext, changes, false);
+            case DataChannel.FLUSH_CASCADE_SYNC -> flushChildChanges(childContext, changes, true);
             default -> throw new CayenneRuntimeException("Unrecognized SyncMessage type: %d", syncType);
         };
     }
 
+    /**
+     * Applies child context changes to the parent context objects, optionally cascading the flush further up the
+     * channel chain.
+     */
+    private GraphDiff flushChildChanges(ObjectContext childContext, GraphDiff changes, boolean cascade) {
+        ObjectStore objectStore = context.getObjectStore();
+
+        objectStore.childContextSyncStarted();
+        try {
+            changes.apply(new ChildDiffLoader(context));
+            context.fireDataChannelChanged(childContext, changes);
+            return cascade ? context.flushToParent(true) : new CompoundDiff();
+        } finally {
+            objectStore.childContextSyncStopped();
+        }
+    }
+
     private void checkChildContext(ObjectContext childContext) {
         if (childContext == null) {
             throw new IllegalArgumentException("Originating context must be a child of " + context + ", not null");