use of org.apache.cayenne.testdo.locking.SimpleLockingTestEntity in project cayenne by apache.
the class OptimisticLockingIT method testSuccessSimpleLockingOnUpdateFollowedByForgetSnapshot.
@Test
public void testSuccessSimpleLockingOnUpdateFollowedByForgetSnapshot() 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();
object.setDescription("second update");
context.getObjectStore().getDataRowCache().forgetSnapshot(object.getObjectId());
context.commitChanges();
}
use of org.apache.cayenne.testdo.locking.SimpleLockingTestEntity in project cayenne by apache.
the class OptimisticLockingIT method testSuccessSimpleLockingOnUpdateFollowedByInvalidate.
@Test
public void testSuccessSimpleLockingOnUpdateFollowedByInvalidate() 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();
object.setDescription("second update");
context.invalidateObjects(object);
context.commitChanges();
}
use of org.apache.cayenne.testdo.locking.SimpleLockingTestEntity in project cayenne by apache.
the class OptimisticLockingIT method testSuccessLockingOnMixed.
@Test
public void testSuccessLockingOnMixed() throws Exception {
createLockingOnMixedDataSet();
SelectQuery<SimpleLockingTestEntity> query = new SelectQuery<>(SimpleLockingTestEntity.class);
query.addOrdering(new Ordering("db:LOCKING_TEST_ID", SortOrder.ASCENDING));
List<?> allObjects = context.performQuery(query);
assertEquals(3, allObjects.size());
SimpleLockingTestEntity object1 = (SimpleLockingTestEntity) allObjects.get(0);
SimpleLockingTestEntity object2 = (SimpleLockingTestEntity) allObjects.get(1);
SimpleLockingTestEntity object3 = (SimpleLockingTestEntity) allObjects.get(2);
// change description and save... no optimistic lock failure expected...
object1.setDescription("first update for object1");
object2.setDescription("first update for object2");
object3.setName("object3 - new name");
context.commitChanges();
// TODO: it would be nice to pick inside DataContext to see that 3 batches where
// generated...
// this requires refactoring of ContextCommit.
}
use of org.apache.cayenne.testdo.locking.SimpleLockingTestEntity in project cayenne by apache.
the class OptimisticLockingIT method testSuccessSimpleLockingOnDeleteFollowedByForgetSnapshot.
@Test
public void testSuccessSimpleLockingOnDeleteFollowedByForgetSnapshot() 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.getObjectStore().getDataRowCache().forgetSnapshot(object.getObjectId());
context.commitChanges();
}
use of org.apache.cayenne.testdo.locking.SimpleLockingTestEntity in project cayenne by apache.
the class OptimisticLockingIT method testFailSimpleLocking.
@Test
public void testFailSimpleLocking() 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();
// 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...
}
}
Aggregations