use of org.apache.cayenne.map.ObjRelationship in project cayenne by apache.
the class DeleteRulesIT method testNullifyFlattenedNoReverse.
@Test
public void testNullifyFlattenedNoReverse() {
// temporarily set delete rule to NULLIFY...
int oldRule = changeDeleteRule(DeleteRule.NULLIFY);
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 testDenyFlattenedNoReverse.
@Test
public void testDenyFlattenedNoReverse() {
// temporarily set delete rule to DENY...
int oldRule = changeDeleteRule(DeleteRule.DENY);
ObjRelationship reverse = unsetReverse();
try {
DeleteRuleFlatA a = context.newObject(DeleteRuleFlatA.class);
DeleteRuleFlatB b = context.newObject(DeleteRuleFlatB.class);
a.addToFlatB(b);
context.commitChanges();
try {
context.deleteObjects(a);
fail("Must have thrown a deny exception..");
} catch (DeleteDenyException ex) {
// expected... but check further
assertJoinNotDeleted(a, b);
}
} finally {
changeDeleteRule(oldRule);
restoreReverse(reverse);
}
}
use of org.apache.cayenne.map.ObjRelationship in project cayenne by apache.
the class FlattenedArcKeyIT method testHashCode.
@Test
public void testHashCode() {
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);
int h = update.hashCode();
int h1 = update1.hashCode();
int h2 = update2.hashCode();
assertTrue(h == h1);
assertTrue(h == update.hashCode());
assertFalse(h == h2);
}
use of org.apache.cayenne.map.ObjRelationship in project cayenne by apache.
the class NestedDataContextWriteIT method testCommitChangesToParentFlattened.
@Test
public void testCommitChangesToParentFlattened() throws Exception {
final DataContext context = createDataContext();
final ObjectContext childContext = runtime.newContext(context);
final Artist childO1 = childContext.newObject(Artist.class);
childO1.setArtistName("Master");
final ArtGroup childO2 = childContext.newObject(ArtGroup.class);
childO2.setName("Detail1");
childO2.addToArtistArray(childO1);
ObjEntity ent = childContext.getEntityResolver().getObjEntity("ArtGroup");
Collection<ObjRelationship> rels = ent.getDeclaredRelationships();
for (ObjRelationship rel : rels) {
System.out.println(rel.getName());
}
assertEquals(1, childO1.getGroupArray().size());
assertEquals(1, childO2.getArtistArray().size());
queryInterceptor.runWithQueriesBlocked(new UnitTestClosure() {
public void execute() {
childContext.commitChangesToParent();
assertEquals(PersistenceState.COMMITTED, childO1.getPersistenceState());
assertEquals(PersistenceState.COMMITTED, childO2.getPersistenceState());
Artist parentO1 = (Artist) context.getGraphManager().getNode(childO1.getObjectId());
assertNotNull(parentO1);
assertEquals(PersistenceState.NEW, parentO1.getPersistenceState());
ArtGroup parentO2 = (ArtGroup) context.getGraphManager().getNode(childO2.getObjectId());
assertNotNull(parentO2);
assertEquals(PersistenceState.NEW, parentO2.getPersistenceState());
assertEquals(1, parentO1.getGroupArray().size());
assertEquals(1, parentO2.getArtistArray().size());
assertTrue(parentO2.getArtistArray().contains(parentO1));
assertTrue(parentO1.getGroupArray().contains(parentO2));
}
});
}
use of org.apache.cayenne.map.ObjRelationship in project cayenne by apache.
the class DeleteObjectIT method testDeleteObjectsRelationshipCollection.
@Test
public void testDeleteObjectsRelationshipCollection() throws Exception {
createObjectsRelationshipCollectionDataSet();
Artist artist = Cayenne.objectForPK(context, Artist.class, 1);
List<Painting> paintings = artist.getPaintingArray();
assertEquals(3, paintings.size());
// create a clone to be able to inspect paintings after deletion
List<Painting> paintingsClone = new ArrayList<Painting>(paintings);
for (Painting object : paintingsClone) {
assertEquals(PersistenceState.COMMITTED, object.getPersistenceState());
}
context.deleteObjects(paintings);
// as Painting -> Artist has Nullify rule, relationship list has to be
// cleaned up,
// and no exceptions thrown on concurrent modification...
ObjRelationship r = context.getEntityResolver().getObjEntity(Painting.class).getRelationship("toArtist");
assertEquals(DeleteRule.NULLIFY, r.getDeleteRule());
assertEquals(0, paintings.size());
for (Painting object : paintingsClone) {
assertEquals(PersistenceState.DELETED, object.getPersistenceState());
}
}
Aggregations