use of org.apache.cayenne.testdo.locking.SimpleLockingTestEntity in project cayenne by apache.
the class OptimisticLockingIT method testFailRetrieveDeletedRow.
@Test
public void testFailRetrieveDeletedRow() throws Exception {
createSimpleLockingDataSet();
List<SimpleLockingTestEntity> allObjects = new SelectQuery<>(SimpleLockingTestEntity.class).select(context);
assertEquals(1, allObjects.size());
SimpleLockingTestEntity object = allObjects.get(0);
object.setDescription("first update");
// delete row underneath, change description and save... optimistic lock failure
// expected
createSimpleLockDelete();
try {
context.commitChanges();
fail("Optimistic lock failure expected.");
} catch (OptimisticLockException ex) {
Map<?, ?> freshFailedRow = ex.getFreshSnapshot(context);
assertNull("" + freshFailedRow, freshFailedRow);
}
}
use of org.apache.cayenne.testdo.locking.SimpleLockingTestEntity in project cayenne by apache.
the class OptimisticLockingIT method testSuccessSimpleLockingOnDeleteFollowedByInvalidate.
@Test
public void testSuccessSimpleLockingOnDeleteFollowedByInvalidate() 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.deleteObjects(object);
context.invalidateObjects(object);
context.commitChanges();
}
use of org.apache.cayenne.testdo.locking.SimpleLockingTestEntity in project cayenne by apache.
the class OptimisticLockingIT method testFailRetrieveRow.
@Test
public void testFailRetrieveRow() throws Exception {
createSimpleLockingDataSet();
List<SimpleLockingTestEntity> allObjects = new SelectQuery<>(SimpleLockingTestEntity.class).select(context);
assertEquals(1, allObjects.size());
SimpleLockingTestEntity object = allObjects.get(0);
object.setDescription("first update");
// change row underneath, change description and save... optimistic lock failure
// expected
createSimpleLockUpdate();
try {
context.commitChanges();
fail("Optimistic lock failure expected.");
} catch (OptimisticLockException ex) {
Map<?, ?> freshFailedRow = ex.getFreshSnapshot(context);
assertNotNull(freshFailedRow);
assertEquals("LockTest1Updated", freshFailedRow.get("NAME"));
}
}
use of org.apache.cayenne.testdo.locking.SimpleLockingTestEntity in project cayenne by apache.
the class OptimisticLockingIT method testFailLockingOnNull.
@Test
public void testFailLockingOnNull() throws Exception {
createLockingOnNullDataSet();
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();
// change row underneath, change description and save... optimistic lock failure
// expected
createSimpleLockUpdate();
object.setDescription("second update");
try {
context.commitChanges();
fail("Optimistic lock failure expected.");
} catch (OptimisticLockException ex) {
// optimistic lock failure expected...
assertEquals(object.getObjectId(), ex.getFailedObjectId());
}
}
use of org.apache.cayenne.testdo.locking.SimpleLockingTestEntity in project cayenne by apache.
the class OptimisticLockingIT method testSuccessSimpleLockingOnDeletePrecededByForgetSnapshot.
@Test
public void testSuccessSimpleLockingOnDeletePrecededByForgetSnapshot() 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());
context.deleteObjects(object);
context.commitChanges();
}
Aggregations