Search in sources :

Example 1 with DeleteRuleFlatA

use of org.apache.cayenne.testdo.relationships_delete_rules.DeleteRuleFlatA in project cayenne by apache.

the class DeleteRulesIT method testCascadeFlattened.

@Test
public void testCascadeFlattened() {
    // temporarily set delete rule to CASCADE...
    int oldRule = changeDeleteRule(DeleteRule.CASCADE);
    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);
    }
}
Also used : DeleteRuleFlatA(org.apache.cayenne.testdo.relationships_delete_rules.DeleteRuleFlatA) DeleteRuleFlatB(org.apache.cayenne.testdo.relationships_delete_rules.DeleteRuleFlatB) Test(org.junit.Test)

Example 2 with DeleteRuleFlatA

use of org.apache.cayenne.testdo.relationships_delete_rules.DeleteRuleFlatA 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);
    }
}
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 3 with DeleteRuleFlatA

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

Example 4 with DeleteRuleFlatA

use of org.apache.cayenne.testdo.relationships_delete_rules.DeleteRuleFlatA in project cayenne by apache.

the class DeleteRulesIT method testNullifyFlattened.

@Test
public void testNullifyFlattened() {
    // temporarily set delete rule to NULLIFY...
    int oldRule = changeDeleteRule(DeleteRule.NULLIFY);
    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.MODIFIED, b.getPersistenceState());
        assertFalse(b.getUntitledRel().contains(a));
        context.commitChanges();
    } finally {
        changeDeleteRule(oldRule);
    }
}
Also used : DeleteRuleFlatA(org.apache.cayenne.testdo.relationships_delete_rules.DeleteRuleFlatA) DeleteRuleFlatB(org.apache.cayenne.testdo.relationships_delete_rules.DeleteRuleFlatB) Test(org.junit.Test)

Example 5 with DeleteRuleFlatA

use of org.apache.cayenne.testdo.relationships_delete_rules.DeleteRuleFlatA 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)

Aggregations

DeleteRuleFlatA (org.apache.cayenne.testdo.relationships_delete_rules.DeleteRuleFlatA)8 DeleteRuleFlatB (org.apache.cayenne.testdo.relationships_delete_rules.DeleteRuleFlatB)8 Test (org.junit.Test)8 ObjRelationship (org.apache.cayenne.map.ObjRelationship)4 DeleteDenyException (org.apache.cayenne.DeleteDenyException)2