Search in sources :

Example 1 with RelLockingTestEntity

use of org.apache.cayenne.testdo.locking.RelLockingTestEntity in project cayenne by apache.

the class OptimisticLockingIT method testFailLockingOnToOne.

@Test
public void testFailLockingOnToOne() throws Exception {
    createLockingOnToOneDataSet();
    List<RelLockingTestEntity> allObjects = new SelectQuery<>(RelLockingTestEntity.class).select(context);
    assertEquals(1, allObjects.size());
    RelLockingTestEntity object = allObjects.get(0);
    // change name and save... no optimistic lock failure expected
    object.setName("first update");
    context.commitChanges();
    // change relationship and save... no optimistic lock failure expected
    SimpleLockingTestEntity object1 = context.newObject(SimpleLockingTestEntity.class);
    object.setToSimpleLockingTest(object1);
    context.commitChanges();
    // change row underneath, change description and save... optimistic lock failure
    // expected
    createRelLockUpdate();
    object.setName("third update");
    try {
        context.commitChanges();
        fail("Optimistic lock failure expected.");
    } catch (OptimisticLockException ex) {
    // optimistic lock failure expected...
    }
}
Also used : RelLockingTestEntity(org.apache.cayenne.testdo.locking.RelLockingTestEntity) SimpleLockingTestEntity(org.apache.cayenne.testdo.locking.SimpleLockingTestEntity) Test(org.junit.Test)

Aggregations

RelLockingTestEntity (org.apache.cayenne.testdo.locking.RelLockingTestEntity)1 SimpleLockingTestEntity (org.apache.cayenne.testdo.locking.SimpleLockingTestEntity)1 Test (org.junit.Test)1