Search in sources :

Example 16 with SimpleLockingTestEntity

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

the class OptimisticLockingIT method testFailSimpleLockingOnDelete.

@Test
public void testFailSimpleLockingOnDelete() throws Exception {
    createSimpleLockingDataSet();
    List<SimpleLockingTestEntity> allObjects = new SelectQuery<>(SimpleLockingTestEntity.class).select(context);
    assertEquals(1, allObjects.size());
    SimpleLockingTestEntity object = allObjects.get(0);
    // change description and save... no optimistic lock failure expected
    object.setDescription("second update");
    context.commitChanges();
    // change row underneath, delete and save... optimistic lock failure expected
    createSimpleLockUpdate();
    context.deleteObjects(object);
    try {
        context.commitChanges();
        fail("Optimistic lock failure expected.");
    } catch (OptimisticLockException ex) {
    // optimistic lock failure expected...
    }
}
Also used : SimpleLockingTestEntity(org.apache.cayenne.testdo.locking.SimpleLockingTestEntity) Test(org.junit.Test)

Example 17 with SimpleLockingTestEntity

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

the class OptimisticLockingIT method testSuccessSimpleLockingOnUpdatePrecededByForgetSnapshot.

@Test
public void testSuccessSimpleLockingOnUpdatePrecededByForgetSnapshot() throws Exception {
    createSimpleLockingDataSet();
    List<SimpleLockingTestEntity> allObjects = new SelectQuery<>(SimpleLockingTestEntity.class).select(context);
    assertEquals(1, allObjects.size());
    SimpleLockingTestEntity object = allObjects.get(0);
    // change description and save... no optimistic lock failure expected
    object.setDescription("first update");
    context.commitChanges();
    context.getObjectStore().getDataRowCache().forgetSnapshot(object.getObjectId());
    object.setDescription("second update");
    context.commitChanges();
}
Also used : SimpleLockingTestEntity(org.apache.cayenne.testdo.locking.SimpleLockingTestEntity) Test(org.junit.Test)

Example 18 with SimpleLockingTestEntity

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

the class OptimisticLockingIT method testSuccessSimpleLockingOnUpdatePrecededByInvalidate.

@Test
public void testSuccessSimpleLockingOnUpdatePrecededByInvalidate() throws Exception {
    createSimpleLockingDataSet();
    List<SimpleLockingTestEntity> allObjects = new SelectQuery<>(SimpleLockingTestEntity.class).select(context);
    assertEquals(1, allObjects.size());
    SimpleLockingTestEntity object = allObjects.get(0);
    // change description and save... no optimistic lock failure expected
    object.setDescription("first update");
    context.commitChanges();
    context.invalidateObjects(object);
    object.setDescription("second update");
    context.commitChanges();
}
Also used : SimpleLockingTestEntity(org.apache.cayenne.testdo.locking.SimpleLockingTestEntity) Test(org.junit.Test)

Aggregations

SimpleLockingTestEntity (org.apache.cayenne.testdo.locking.SimpleLockingTestEntity)18 Test (org.junit.Test)18 Map (java.util.Map)2 Ordering (org.apache.cayenne.query.Ordering)1 SelectQuery (org.apache.cayenne.query.SelectQuery)1 RelLockingTestEntity (org.apache.cayenne.testdo.locking.RelLockingTestEntity)1