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/10/11 19:54:44 UTC
(cayenne) branch master updated: cleanup -ShallowMergeOperation should be private
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 0f4e36c3d cleanup -ShallowMergeOperation should be private
0f4e36c3d is described below
commit 0f4e36c3db416fd3e489b079ac64cc5d88fd90e3
Author: Andrus Adamchik <an...@objectstyle.com>
AuthorDate: Sun Oct 11 15:53:38 2026 -0400
cleanup -ShallowMergeOperation should be private
---
.../org/apache/cayenne/access/DataContext.java | 1 -
.../apache/cayenne/access/DataContextChannel.java | 1 -
.../{util => access}/ShallowMergeOperation.java | 4 +-
.../apache/cayenne/util/DeepMergeOperation.java | 153 ---------------------
.../{util => access}/ShallowMergeOperationIT.java | 3 +-
.../apache/cayenne/util/DeepMergeOperationIT.java | 88 ------------
.../util/DeepMergeOperationInheritanceIT.java | 121 ----------------
7 files changed, 3 insertions(+), 368 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 c74b2310c..f7148029d 100644
--- a/cayenne/src/main/java/org/apache/cayenne/access/DataContext.java
+++ b/cayenne/src/main/java/org/apache/cayenne/access/DataContext.java
@@ -53,7 +53,6 @@ import org.apache.cayenne.reflect.PropertyDescriptor;
import org.apache.cayenne.reflect.PropertyVisitor;
import org.apache.cayenne.reflect.ToManyProperty;
import org.apache.cayenne.reflect.ToOneProperty;
-import org.apache.cayenne.util.ShallowMergeOperation;
import org.apache.cayenne.util.Util;
import java.util.ArrayList;
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 95d83cde1..55fbc8ba1 100644
--- a/cayenne/src/main/java/org/apache/cayenne/access/DataContextChannel.java
+++ b/cayenne/src/main/java/org/apache/cayenne/access/DataContextChannel.java
@@ -35,7 +35,6 @@ import org.apache.cayenne.query.EntityResultSegment;
import org.apache.cayenne.query.Query;
import org.apache.cayenne.query.QueryMetadata;
import org.apache.cayenne.query.ResultSegment;
-import org.apache.cayenne.util.ShallowMergeOperation;
import java.util.ArrayList;
import java.util.Collection;
diff --git a/cayenne/src/main/java/org/apache/cayenne/util/ShallowMergeOperation.java b/cayenne/src/main/java/org/apache/cayenne/access/ShallowMergeOperation.java
similarity index 98%
rename from cayenne/src/main/java/org/apache/cayenne/util/ShallowMergeOperation.java
rename to cayenne/src/main/java/org/apache/cayenne/access/ShallowMergeOperation.java
index 609dd0729..d04d450c8 100644
--- a/cayenne/src/main/java/org/apache/cayenne/util/ShallowMergeOperation.java
+++ b/cayenne/src/main/java/org/apache/cayenne/access/ShallowMergeOperation.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
****************************************************************/
-package org.apache.cayenne.util;
+package org.apache.cayenne.access;
import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.ObjectId;
@@ -31,7 +31,7 @@ import org.apache.cayenne.reflect.ClassDescriptor;
*
* @since 3.1
*/
-public class ShallowMergeOperation {
+class ShallowMergeOperation {
private final ObjectContext context;
diff --git a/cayenne/src/main/java/org/apache/cayenne/util/DeepMergeOperation.java b/cayenne/src/main/java/org/apache/cayenne/util/DeepMergeOperation.java
deleted file mode 100644
index a61f9cd7f..000000000
--- a/cayenne/src/main/java/org/apache/cayenne/util/DeepMergeOperation.java
+++ /dev/null
@@ -1,153 +0,0 @@
-/*****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ****************************************************************/
-
-package org.apache.cayenne.util;
-
-import org.apache.cayenne.CayenneRuntimeException;
-import org.apache.cayenne.ObjectContext;
-import org.apache.cayenne.ObjectId;
-import org.apache.cayenne.Persistent;
-import org.apache.cayenne.map.EntityResolver;
-import org.apache.cayenne.reflect.AttributeProperty;
-import org.apache.cayenne.reflect.ClassDescriptor;
-import org.apache.cayenne.reflect.PropertyVisitor;
-import org.apache.cayenne.reflect.ToManyMapProperty;
-import org.apache.cayenne.reflect.ToManyProperty;
-import org.apache.cayenne.reflect.ToOneProperty;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Map.Entry;
-
-/**
- * An operation that merges changes from an object graph, whose objects are registered in
- * some ObjectContext, to peer objects in an ObjectConext that is a child of that context.
- * The merge terminates at hollow nodes in the parent context to avoid tripping over
- * unresolved relationships.
- *
- * @since 1.2
- * @deprecated unused
- */
-@Deprecated(since = "5.0", forRemoval = true)
-public class DeepMergeOperation {
-
- private final EntityResolver entityResolver;
- private final ShallowMergeOperation shallowMergeOperation;
-
- public DeepMergeOperation(ObjectContext context) {
- this.entityResolver = context.getEntityResolver();
- this.shallowMergeOperation = new ShallowMergeOperation(context);
- }
-
- public <T extends Persistent> T merge(T peerInParentContext) {
- ClassDescriptor descriptor = entityResolver
- .getClassDescriptor(peerInParentContext.getObjectId().getEntityName());
- return merge(peerInParentContext, descriptor, new HashMap<>());
- }
-
- private <T extends Persistent> T merge(
- final T peerInParentContext,
- ClassDescriptor descriptor,
- final Map<ObjectId, Persistent> seen) {
-
- ObjectId id = peerInParentContext.getObjectId();
-
- // sanity check
- if (id == null) {
- throw new CayenneRuntimeException("Server returned an object without an id: %s", peerInParentContext);
- }
-
- Persistent seenTarget = seen.get(id);
- if (seenTarget != null) {
- @SuppressWarnings("unchecked")
- T castTarget = (T) seenTarget;
- return castTarget;
- }
-
- final T target = shallowMergeOperation.merge(peerInParentContext);
- seen.put(id, target);
-
- descriptor = descriptor.getSubclassDescriptor(id.getEntityName());
- descriptor.visitProperties(new PropertyVisitor() {
-
- public boolean visitToOne(ToOneProperty property) {
-
- Object sourceValue = property.readPropertyDirectly(peerInParentContext);
- if (!property.isFaultValue(sourceValue)) {
- Persistent destinationSource = (Persistent) sourceValue;
- Object destinationTarget = destinationSource != null
- ? merge(destinationSource, property.getTargetDescriptor(), seen)
- : null;
- Object targetValue = property.readPropertyDirectly(target);
- Object oldTarget = property.isFaultValue(targetValue) ? null : targetValue;
- property.writePropertyDirectly(target, oldTarget, destinationTarget);
- }
-
- return true;
- }
-
- public boolean visitToMany(ToManyProperty property) {
- Object value = property.readPropertyDirectly(peerInParentContext);
- if (!property.isFaultValue(value)) {
- Object targetValue;
-
- if (property instanceof ToManyMapProperty) {
- Map<?, ?> map = (Map<?, ?>) value;
- Map<Object, Object> targetMap = new HashMap<>();
-
- for (Entry<?, ?> entry : map.entrySet()) {
- Object destinationSource = entry.getValue();
- Object destinationTarget = destinationSource != null
- ? merge((Persistent) destinationSource, property.getTargetDescriptor(), seen)
- : null;
-
- targetMap.put(entry.getKey(), destinationTarget);
- }
- targetValue = targetMap;
- }
- else {
- Collection<?> collection = (Collection<?>) value;
- Collection<Object> targetCollection = new ArrayList<>(collection.size());
-
- for (Object destinationSource : collection) {
- Object destinationTarget = destinationSource != null
- ? merge((Persistent) destinationSource, property.getTargetDescriptor(), seen)
- : null;
-
- targetCollection.add(destinationTarget);
- }
- targetValue = targetCollection;
- }
-
- property.writePropertyDirectly(target, null, targetValue);
- }
-
- return true;
- }
-
- public boolean visitAttribute(AttributeProperty property) {
- return true;
- }
- });
-
- return target;
- }
-}
diff --git a/cayenne/src/test/java/org/apache/cayenne/util/ShallowMergeOperationIT.java b/cayenne/src/test/java/org/apache/cayenne/access/ShallowMergeOperationIT.java
similarity index 98%
rename from cayenne/src/test/java/org/apache/cayenne/util/ShallowMergeOperationIT.java
rename to cayenne/src/test/java/org/apache/cayenne/access/ShallowMergeOperationIT.java
index 5e3c90b16..047a2e63d 100644
--- a/cayenne/src/test/java/org/apache/cayenne/util/ShallowMergeOperationIT.java
+++ b/cayenne/src/test/java/org/apache/cayenne/access/ShallowMergeOperationIT.java
@@ -16,14 +16,13 @@
* specific language governing permissions and limitations
* under the License.
****************************************************************/
-package org.apache.cayenne.util;
+package org.apache.cayenne.access;
import org.apache.cayenne.Cayenne;
import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.ObjectId;
import org.apache.cayenne.PersistenceState;
import org.apache.cayenne.Persistent;
-import org.apache.cayenne.access.DataContext;
import org.apache.cayenne.CayenneRuntime;
import org.apache.cayenne.test.jdbc.TableHelper;
import org.apache.cayenne.testdo.testmap.Artist;
diff --git a/cayenne/src/test/java/org/apache/cayenne/util/DeepMergeOperationIT.java b/cayenne/src/test/java/org/apache/cayenne/util/DeepMergeOperationIT.java
deleted file mode 100644
index 379f047cd..000000000
--- a/cayenne/src/test/java/org/apache/cayenne/util/DeepMergeOperationIT.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ****************************************************************/
-
-package org.apache.cayenne.util;
-
-import org.apache.cayenne.Cayenne;
-import org.apache.cayenne.PersistenceState;
-import org.apache.cayenne.access.DataContext;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.unit.CayenneProjects;
-import org.apache.cayenne.unit.CayenneTestsEnv;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.RegisterExtension;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertSame;
-
-@Deprecated
-public class DeepMergeOperationIT {
-
- @RegisterExtension
- static final CayenneTestsEnv env = CayenneTestsEnv.forProject(CayenneProjects.TESTMAP_PROJECT);
-
- private DataContext context;
- private DataContext context1;
-
- @BeforeEach
- public void setUp() {
- context = env.context();
- context1 = (DataContext) env.runtime().newContext();
- }
-
- @Test
- public void deepMergeNonExistent() {
-
- final Artist a = context.newObject(Artist.class);
- a.setArtistName("AAA");
- context.commitChanges();
-
- final DeepMergeOperation op = new DeepMergeOperation(context1);
-
- env.runWithQueriesBlocked(() -> {
- Artist a2 = op.merge(a);
- assertNotNull(a2);
- assertEquals(PersistenceState.COMMITTED, a2.getPersistenceState());
- assertEquals(a.getArtistName(), a2.getArtistName());
- });
- }
-
- @Test
- public void deepMergeModified() {
-
- final Artist a = context.newObject(Artist.class);
- a.setArtistName("AAA");
- context.commitChanges();
-
- final Artist a1 = (Artist) Cayenne.objectForPK(context1, a.getObjectId());
- a1.setArtistName("BBB");
- final DeepMergeOperation op = new DeepMergeOperation(context1);
-
- env.runWithQueriesBlocked(() -> {
- Artist a2 = op.merge(a);
- assertNotNull(a2);
- assertEquals(PersistenceState.MODIFIED, a2.getPersistenceState());
- assertSame(a1, a2);
- assertEquals("BBB", a2.getArtistName());
- });
- }
-
-}
diff --git a/cayenne/src/test/java/org/apache/cayenne/util/DeepMergeOperationInheritanceIT.java b/cayenne/src/test/java/org/apache/cayenne/util/DeepMergeOperationInheritanceIT.java
deleted file mode 100644
index 6a62c4ea6..000000000
--- a/cayenne/src/test/java/org/apache/cayenne/util/DeepMergeOperationInheritanceIT.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * https://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ****************************************************************/
-
-package org.apache.cayenne.util;
-
-import org.apache.cayenne.PersistenceState;
-import org.apache.cayenne.access.DataContext;
-import org.apache.cayenne.query.ObjectSelect;
-import org.apache.cayenne.testdo.inheritance_people.Department;
-import org.apache.cayenne.testdo.inheritance_people.Employee;
-import org.apache.cayenne.testdo.inheritance_people.Manager;
-import org.apache.cayenne.PeopleTestBase;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.*;
-
-@Deprecated
-public class DeepMergeOperationInheritanceIT extends PeopleTestBase {
-
- private DataContext context;
- private DataContext context1;
-
- @BeforeEach
- public void setUp() {
- context = env.context();
- context1 = (DataContext) env.runtime().newContext();
- }
-
- @Test
- public void deepMergeExistingSubclass() {
-
- final Department d1 = context.newObject(Department.class);
- d1.setName("D1");
-
- // need to do double commit as Ashwood sorter blows on Employees/Departments ordering...
- context.commitChanges();
-
- Employee e1 = context.newObject(Employee.class);
- e1.setName("E1");
- e1.setPersonType("EE");
- d1.addToEmployees(e1);
-
- Manager e2 = context.newObject(Manager.class);
- e2.setName("E2");
- e2.setPersonType("EM");
- d1.addToEmployees(e2);
-
- context.commitChanges();
-
- // need to make sure source relationship is resolved as a result of some Ashwood strangeness...
- d1.getEmployees().size();
-
- // resolve Employees
- ObjectSelect.query(Employee.class).select(context1);
-
- final DeepMergeOperation op = new DeepMergeOperation(context1);
-
- assertMergeResult(d1, op);
- }
-
- @Test
- public void deepMergeNonExistentSubclass() {
-
- final Department d1 = context.newObject(Department.class);
- d1.setName("D1");
-
- // need to do double commit as Ashwood sorter blows on Employees/Departments ordering...
- context.commitChanges();
-
- Employee e1 = context.newObject(Employee.class);
- e1.setName("E1");
- e1.setPersonType("EE");
- d1.addToEmployees(e1);
-
- Manager e2 = context.newObject(Manager.class);
- e2.setName("E2");
- e2.setPersonType("EM");
- d1.addToEmployees(e2);
-
- context.commitChanges();
-
- // need to make sure source relationship is resolved as a result of some Ashwood strangeness...
- d1.getEmployees().size();
- final DeepMergeOperation op = new DeepMergeOperation(context1);
-
- assertMergeResult(d1, op);
- }
-
- private void assertMergeResult(Department d1, DeepMergeOperation op) {
- env.runWithQueriesBlocked(() -> {
- Department d2 = op.merge(d1);
- assertNotNull(d2);
- assertEquals(PersistenceState.COMMITTED, d2.getPersistenceState());
-
- for (Employee ex : d2.getEmployees()) {
- if ("E2".equals(ex.getName())) {
- assertInstanceOf(Manager.class, ex);
- } else {
- assertFalse(ex instanceof Manager);
- }
- }
- });
- }
-}