Search in sources :

Example 46 with ObjRelationship

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;
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjRelationship(org.apache.cayenne.map.ObjRelationship)

Example 47 with ObjRelationship

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);
    }
}
Also used : ObjRelationship(org.apache.cayenne.map.ObjRelationship) DeleteRuleFlatA(org.apache.cayenne.testdo.relationships_delete_rules.DeleteRuleFlatA) DeleteRuleFlatB(org.apache.cayenne.testdo.relationships_delete_rules.DeleteRuleFlatB) Test(org.junit.Test)

Example 48 with ObjRelationship

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);
    }
}
Also used : ObjRelationship(org.apache.cayenne.map.ObjRelationship) DeleteRuleFlatA(org.apache.cayenne.testdo.relationships_delete_rules.DeleteRuleFlatA) DeleteRuleFlatB(org.apache.cayenne.testdo.relationships_delete_rules.DeleteRuleFlatB) Test(org.junit.Test)

Example 49 with ObjRelationship

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);
}
Also used : FlattenedTest3(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3) ObjRelationship(org.apache.cayenne.map.ObjRelationship) ObjectId(org.apache.cayenne.ObjectId) Test(org.junit.Test)

Example 50 with ObjRelationship

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));
}
Also used : FlattenedTest3(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest3) ObjRelationship(org.apache.cayenne.map.ObjRelationship) FlattenedTest1(org.apache.cayenne.testdo.relationships_flattened.FlattenedTest1) ObjectId(org.apache.cayenne.ObjectId) Test(org.junit.Test)

Aggregations

ObjRelationship (org.apache.cayenne.map.ObjRelationship)84 ObjEntity (org.apache.cayenne.map.ObjEntity)48 ObjAttribute (org.apache.cayenne.map.ObjAttribute)27 DbRelationship (org.apache.cayenne.map.DbRelationship)26 Test (org.junit.Test)24 DbEntity (org.apache.cayenne.map.DbEntity)18 DbAttribute (org.apache.cayenne.map.DbAttribute)15 DbJoin (org.apache.cayenne.map.DbJoin)14 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)12 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)12 ObjectId (org.apache.cayenne.ObjectId)10 ToManyProperty (org.apache.cayenne.reflect.ToManyProperty)9 ToOneProperty (org.apache.cayenne.reflect.ToOneProperty)9 ArrayList (java.util.ArrayList)8 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)8 PropertyVisitor (org.apache.cayenne.reflect.PropertyVisitor)8 List (java.util.List)7 EJBQLException (org.apache.cayenne.ejbql.EJBQLException)7 DataMap (org.apache.cayenne.map.DataMap)7 HashMap (java.util.HashMap)6