use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class DiffProcessor method arcDeleted.
@Override
public void arcDeleted(Object nodeId, Object targetNodeId, Object arcId) {
ObjectId id = (ObjectId) nodeId;
String relationshipName = arcId.toString();
ObjEntity entity = entityResolver.getObjEntity(id.getEntityName());
ObjRelationship relationship = entity.getRelationship(relationshipName);
MutableObjectChange c = changeSet.getOrCreate(id, ObjectChangeType.UPDATE);
ObjectId tid = (ObjectId) targetNodeId;
if (relationship.isToMany()) {
c.toManyRelationshipDisconnected(relationshipName, tid);
} else {
c.toOneRelationshipDisconnected(relationshipName, tid);
}
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class CommitLogFilter_AllIT method testPostCommit_Insert.
@Test
public void testPostCommit_Insert() throws SQLException {
final Auditable1 a1 = context.newObject(Auditable1.class);
a1.setCharProperty1("yy");
final ObjectId preCommitId = a1.getObjectId();
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
assertSame(context, invocation.getArguments()[0]);
ChangeMap changes = (ChangeMap) invocation.getArguments()[1];
assertNotNull(changes);
assertEquals(2, changes.getChanges().size());
assertEquals(1, changes.getUniqueChanges().size());
ObjectChange c = changes.getUniqueChanges().iterator().next();
assertNotNull(c);
assertEquals(ObjectChangeType.INSERT, c.getType());
assertEquals(1, c.getAttributeChanges().size());
assertEquals("yy", c.getAttributeChanges().get(Auditable1.CHAR_PROPERTY1.getName()).getNewValue());
assertNotEquals(preCommitId, a1.getObjectId());
assertEquals(preCommitId, c.getPreCommitId());
assertEquals(a1.getObjectId(), c.getPostCommitId());
return null;
}
}).when(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
context.commitChanges();
verify(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class CommitLogFilter_AllIT method testPostCommit_UpdateToOne.
@Test
public void testPostCommit_UpdateToOne() throws SQLException {
auditable1.insert(1, "xx");
auditable1.insert(2, "yy");
auditableChild1.insert(1, 1, "cc1");
auditableChild1.insert(2, 2, "cc2");
auditableChild1.insert(3, null, "cc3");
final AuditableChild1 ac1 = SelectById.query(AuditableChild1.class, 1).selectOne(context);
final AuditableChild1 ac2 = SelectById.query(AuditableChild1.class, 2).selectOne(context);
final AuditableChild1 ac3 = SelectById.query(AuditableChild1.class, 3).selectOne(context);
final Auditable1 a1 = SelectById.query(Auditable1.class, 1).selectOne(context);
final Auditable1 a2 = SelectById.query(Auditable1.class, 2).selectOne(context);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
assertSame(context, invocation.getArguments()[0]);
ChangeMap changes = (ChangeMap) invocation.getArguments()[1];
assertNotNull(changes);
assertEquals(4, changes.getUniqueChanges().size());
ObjectChange ac1c = changes.getChanges().get(new ObjectId("AuditableChild1", AuditableChild1.ID_PK_COLUMN, 1));
assertNotNull(ac1c);
assertEquals(ObjectChangeType.UPDATE, ac1c.getType());
ToOneRelationshipChange ac1c1 = ac1c.getToOneRelationshipChanges().get(AuditableChild1.PARENT.getName());
assertEquals(a1.getObjectId(), ac1c1.getOldValue());
assertEquals(null, ac1c1.getNewValue());
ObjectChange ac2c = changes.getChanges().get(new ObjectId("AuditableChild1", AuditableChild1.ID_PK_COLUMN, 2));
assertNotNull(ac2c);
assertEquals(ObjectChangeType.UPDATE, ac2c.getType());
ToOneRelationshipChange ac2c1 = ac2c.getToOneRelationshipChanges().get(AuditableChild1.PARENT.getName());
assertEquals(a2.getObjectId(), ac2c1.getOldValue());
assertEquals(a1.getObjectId(), ac2c1.getNewValue());
ObjectChange ac3c = changes.getChanges().get(new ObjectId("AuditableChild1", AuditableChild1.ID_PK_COLUMN, 3));
assertNotNull(ac3c);
assertEquals(ObjectChangeType.UPDATE, ac3c.getType());
ToOneRelationshipChange ac3c1 = ac3c.getToOneRelationshipChanges().get(AuditableChild1.PARENT.getName());
assertEquals(null, ac3c1.getOldValue());
assertEquals(a1.getObjectId(), ac3c1.getNewValue());
return null;
}
}).when(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
a1.removeFromChildren1(ac1);
a1.addToChildren1(ac2);
a1.addToChildren1(ac3);
context.commitChanges();
verify(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class CommitLogFilter_AllIT method testPostCommit_Update.
@Test
public void testPostCommit_Update() throws SQLException {
auditable1.insert(1, "xx");
final Auditable1 a1 = SelectById.query(Auditable1.class, 1).selectOne(context);
a1.setCharProperty1("yy");
final ObjectId preCommitId = a1.getObjectId();
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
assertSame(context, invocation.getArguments()[0]);
ChangeMap changes = (ChangeMap) invocation.getArguments()[1];
assertNotNull(changes);
assertEquals(1, changes.getUniqueChanges().size());
ObjectChange c = changes.getChanges().get(new ObjectId("Auditable1", Auditable1.ID_PK_COLUMN, 1));
assertNotNull(c);
assertEquals(ObjectChangeType.UPDATE, c.getType());
assertEquals(1, c.getAttributeChanges().size());
AttributeChange pc = c.getAttributeChanges().get(Auditable1.CHAR_PROPERTY1.getName());
assertNotNull(pc);
assertEquals("xx", pc.getOldValue());
assertEquals("yy", pc.getNewValue());
assertEquals(preCommitId, a1.getObjectId());
assertEquals(preCommitId, c.getPreCommitId());
assertEquals(preCommitId, c.getPostCommitId());
return null;
}
}).when(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
context.commitChanges();
verify(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
}
use of org.apache.cayenne.ObjectId in project cayenne by apache.
the class CommitLogFilter_All_FlattenedIT method testPostCommit_UpdateToMany.
@Test
public void testPostCommit_UpdateToMany() throws SQLException {
e3.insert(1);
e4.insert(11);
e4.insert(12);
e34.insert(1, 11);
final E3 e3 = SelectById.query(E3.class, 1).selectOne(context);
final E4 e4_1 = SelectById.query(E4.class, 11).selectOne(context);
final E4 e4_2 = SelectById.query(E4.class, 12).selectOne(context);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
assertSame(context, invocation.getArguments()[0]);
ChangeMap changes = (ChangeMap) invocation.getArguments()[1];
assertNotNull(changes);
assertEquals(3, changes.getUniqueChanges().size());
ObjectChange e3c = changes.getChanges().get(new ObjectId("E3", E3.ID_PK_COLUMN, 1));
assertNotNull(e3c);
assertEquals(ObjectChangeType.UPDATE, e3c.getType());
assertEquals(0, e3c.getAttributeChanges().size());
assertEquals(1, e3c.getToManyRelationshipChanges().size());
ToManyRelationshipChange e3c1 = e3c.getToManyRelationshipChanges().get(E3.E4S.getName());
assertNotNull(e3c1);
assertEquals(1, e3c1.getAdded().size());
assertTrue(e3c1.getAdded().contains(e4_2.getObjectId()));
assertEquals(1, e3c1.getRemoved().size());
assertTrue(e3c1.getRemoved().contains(e4_1.getObjectId()));
ObjectChange e41c = changes.getChanges().get(new ObjectId("E4", E4.ID_PK_COLUMN, 11));
assertNotNull(e41c);
assertEquals(ObjectChangeType.UPDATE, e41c.getType());
assertEquals(0, e41c.getAttributeChanges().size());
assertEquals(1, e41c.getToManyRelationshipChanges().size());
ToManyRelationshipChange e41c1 = e41c.getToManyRelationshipChanges().get(E4.E3S.getName());
assertNotNull(e41c);
assertEquals(0, e41c1.getAdded().size());
assertEquals(1, e41c1.getRemoved().size());
assertTrue(e41c1.getRemoved().contains(e3.getObjectId()));
ObjectChange e42c = changes.getChanges().get(new ObjectId("E4", E4.ID_PK_COLUMN, 12));
assertNotNull(e42c);
assertEquals(ObjectChangeType.UPDATE, e42c.getType());
assertEquals(0, e42c.getAttributeChanges().size());
assertEquals(1, e42c.getToManyRelationshipChanges().size());
ToManyRelationshipChange e42c1 = e42c.getToManyRelationshipChanges().get(E4.E3S.getName());
assertNotNull(e42c);
assertEquals(0, e42c1.getRemoved().size());
assertEquals(1, e42c1.getAdded().size());
assertTrue(e42c1.getAdded().contains(e3.getObjectId()));
return null;
}
}).when(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
e3.removeFromE4s(e4_1);
e3.addToE4s(e4_2);
context.commitChanges();
verify(mockListener).onPostCommit(any(ObjectContext.class), any(ChangeMap.class));
}
Aggregations