use of org.apache.cayenne.map.ObjRelationship in project cayenne by apache.
the class DeleteRulesIT method unsetReverse.
private ObjRelationship unsetReverse() {
ObjEntity entity = context.getEntityResolver().getObjEntity(DeleteRuleFlatA.class);
ObjRelationship relationship = entity.getRelationship(DeleteRuleFlatA.FLAT_B.getName());
ObjRelationship reverse = relationship.getReverseRelationship();
if (reverse != null) {
reverse.getSourceEntity().removeRelationship(reverse.getName());
context.getEntityResolver().getClassDescriptorMap().removeDescriptor("DeleteRuleFlatA");
context.getEntityResolver().getClassDescriptorMap().removeDescriptor("DeleteRuleFlatB");
}
return reverse;
}
use of org.apache.cayenne.map.ObjRelationship in project cayenne by apache.
the class DeleteRulesIT method testNoActionFlattenedNoReverse.
@Test
public void testNoActionFlattenedNoReverse() {
// temporarily set delete rule to NOACTION...
int oldRule = changeDeleteRule(DeleteRule.NO_ACTION);
ObjRelationship reverse = unsetReverse();
try {
DeleteRuleFlatA a = context.newObject(DeleteRuleFlatA.class);
DeleteRuleFlatB b = context.newObject(DeleteRuleFlatB.class);
a.addToFlatB(b);
context.commitChanges();
// must go on without exceptions...
context.deleteObjects(a);
// assert that join is deleted
assertJoinDeleted(a, b);
assertEquals(PersistenceState.DELETED, a.getPersistenceState());
assertEquals(PersistenceState.COMMITTED, b.getPersistenceState());
context.commitChanges();
} finally {
changeDeleteRule(oldRule);
restoreReverse(reverse);
}
}
use of org.apache.cayenne.map.ObjRelationship in project cayenne by apache.
the class DeleteRulesIT method testCascadeFlattenedNoReverse.
@Test
public void testCascadeFlattenedNoReverse() {
// temporarily set delete rule to CASCADE...
int oldRule = changeDeleteRule(DeleteRule.CASCADE);
ObjRelationship reverse = unsetReverse();
try {
DeleteRuleFlatA a = context.newObject(DeleteRuleFlatA.class);
DeleteRuleFlatB b = context.newObject(DeleteRuleFlatB.class);
a.addToFlatB(b);
context.commitChanges();
// must go on without exceptions...
context.deleteObjects(a);
// assert that join is deleted
assertJoinDeleted(a, b);
context.commitChanges();
assertEquals(PersistenceState.TRANSIENT, a.getPersistenceState());
assertEquals(PersistenceState.TRANSIENT, b.getPersistenceState());
} finally {
changeDeleteRule(oldRule);
restoreReverse(reverse);
}
}
use of org.apache.cayenne.map.ObjRelationship in project cayenne by apache.
the class FlattenedArcKeyIT method testAttributes.
@Test
public void testAttributes() {
ObjectId src = new ObjectId("X");
ObjectId target = new ObjectId("Y");
ObjRelationship r1 = entityResolver.getObjEntity(FlattenedTest3.class).getRelationship(FlattenedTest3.TO_FT1.getName());
FlattenedArcKey update = new FlattenedArcKey(src, target, r1);
assertSame(src, update.id1.getSourceId());
assertSame(target, update.id2.getSourceId());
assertSame(r1, update.relationship);
}
use of org.apache.cayenne.map.ObjRelationship in project cayenne by apache.
the class FlattenedArcKeyIT method testEquals.
@Test
public void testEquals() {
ObjectId src = new ObjectId("X");
ObjectId target = new ObjectId("Y");
ObjRelationship r1 = entityResolver.getObjEntity(FlattenedTest3.class).getRelationship(FlattenedTest3.TO_FT1.getName());
FlattenedArcKey update = new FlattenedArcKey(src, target, r1);
FlattenedArcKey update1 = new FlattenedArcKey(target, src, r1.getReverseRelationship());
ObjRelationship r3 = entityResolver.getObjEntity(FlattenedTest1.class).getRelationship(FlattenedTest1.FT3OVER_COMPLEX.getName());
FlattenedArcKey update2 = new FlattenedArcKey(target, src, r3);
assertTrue(update.equals(update1));
assertFalse(update.equals(update2));
}
Aggregations