Skip to content

Commit

Permalink
CAY-2851 Replace Existing OneToOne From New Object
Browse files Browse the repository at this point in the history
  • Loading branch information
stariy95 committed Jun 12, 2024
1 parent 5979c92 commit 9c8ad5b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 9 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ CAY-2841 Multi column ColumnSelect with SHARED_CACHE fails after 1st select
CAY-2844 Joint prefetch doesn't use ObjEntity qualifier
CAY-2848 Vertical Inheritance: Updating one-to-many with inverse nullifies other columns
CAY-2850 Query using Clob comparison with empty String fails
CAY-2851 Replace Existing OneToOne From New Object
CAY-2853 Incorrect deletion of entities from flattened attributes

----------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,8 @@ public void testPostCommit_UpdateToOne() throws SQLException {
verify(mockListener).onPostCommit(any(ObjectContext.class), changeMap.capture());

assertNotNull(changeMap.getValue());
// TODO: this assertions would fail, once CAY-2851 is fixed
assertEquals(4, changeMap.getValue().getUniqueChanges().size());
assertEquals(5, changeMap.getValue().getUniqueChanges().size());

// TODO: commented out until CAY-2851 is fixed
/*
ObjectChange a1c = changeMap.getValue().getChanges().get(
ObjectId.of("Auditable1", Auditable1.ID_PK_COLUMN, 1));
assertNotNull(a1c);
Expand All @@ -263,7 +260,6 @@ public void testPostCommit_UpdateToOne() throws SQLException {
ToManyRelationshipChange a2c1 = a2c.getToManyRelationshipChanges().get(Auditable1.CHILDREN1.getName());
assertEquals(0, a2c1.getAdded().size());
assertEquals(1, a2c1.getRemoved().size());
*/

ObjectChange ac1c = changeMap.getValue().getChanges().get(
ObjectId.of("AuditableChild1", AuditableChild1.ID_PK_COLUMN, 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ protected void setReverseRelationship(String relName, DataObject val) {
.getRelationship(relName);
ObjRelationship revRel = rel.getReverseRelationship();
if (revRel != null) {
Object oldTarget = val.readProperty(revRel.getName());
if (oldTarget != this && oldTarget instanceof DataObject && val instanceof BaseDataObject) {
((BaseDataObject)val).unsetReverseRelationship(revRel.getName(), (DataObject) oldTarget);
}
if (revRel.isToMany()) {
val.addToManyTarget(revRel.getName(), this, false);
} else {
Expand Down
43 changes: 41 additions & 2 deletions cayenne-server/src/test/java/org/apache/cayenne/CDOOne2ManyIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.apache.cayenne.unit.di.server.ServerCase;
import org.apache.cayenne.unit.di.server.UseServerRuntime;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import java.util.Date;
Expand Down Expand Up @@ -296,7 +295,6 @@ public void testPropagatePK() {
context.commitChanges();
}

@Ignore("See CAY-2851 for details")
@Test
public void testReplace() {

Expand Down Expand Up @@ -340,4 +338,45 @@ public void testReplace() {
assertEquals(1, g3.getPaintingArray().size());
assertSame(p3, g3.getPaintingArray().get(0));
}

@Test
public void testReplaceToSame() {

Painting p1 = context.newObject(Painting.class);
p1.setPaintingTitle("xa");

Gallery g1 = context.newObject(Gallery.class);
g1.setGalleryName("yTW");

p1.setToGallery(g1);

context.commitChanges();
ObjectContext context2 = runtime.newContext();

// test database data
Painting p2 = ObjectSelect.query(Painting.class).selectOne(context2);
Gallery g21 = p2.getToGallery();
assertNotNull(g21);
assertEquals("yTW", g21.getGalleryName());
assertEquals(1, g21.getPaintingArray().size());
assertSame(p2, g21.getPaintingArray().get(0));

g21.addToPaintingArray(p2);

// test before save
assertEquals(2, g21.getPaintingArray().size());
assertSame(p2, g21.getPaintingArray().get(0));

// do save II
context2.commitChanges();

ObjectContext context3 = runtime.newContext();

Painting p3 = ObjectSelect.query(Painting.class).selectOne(context3);
Gallery g3 = p3.getToGallery();
assertNotNull(g3);
assertEquals("yTW", g3.getGalleryName());
assertEquals(1, g3.getPaintingArray().size());
assertSame(p3, g3.getPaintingArray().get(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.cayenne.testdo.testmap.PaintingInfo;
import org.apache.cayenne.unit.di.server.CayenneProjects;
import org.apache.cayenne.unit.di.server.UseServerRuntime;
import org.junit.Ignore;
import org.junit.Test;

import java.sql.Timestamp;
Expand Down Expand Up @@ -146,7 +145,6 @@ public void testReplace() throws Exception {

}

@Ignore("See CAY-2851 for details")
@Test
public void testReplaceOtherSide() throws Exception {
String altPaintingName = "alt painting";
Expand Down

0 comments on commit 9c8ad5b

Please sign in to comment.