use of org.apache.cayenne.testdo.locking.SimpleLockingTestEntity 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...
}
}
use of org.apache.cayenne.testdo.locking.SimpleLockingTestEntity in project cayenne by apache.
the class OptimisticLockingIT method testSuccessSimpleLockingNullablePrimitiveColumn.
@Test
public void testSuccessSimpleLockingNullablePrimitiveColumn() throws Exception {
createSimpleLockingDataSet();
SimpleLockingTestEntity object = ObjectSelect.query(SimpleLockingTestEntity.class).selectOne(context);
// we should have NULL value in primitive column
assertEquals(0, object.getIntColumnNull());
assertNull(object.readPropertyDirectly("intColumnNull"));
// change object and save... no optimistic lock failure expected
object.setDescription("first update");
object.setIntColumnNotnull(2);
context.commitChanges();
// update values once more
object.setDescription("second update");
object.setIntColumnNull(3);
context.commitChanges();
}
use of org.apache.cayenne.testdo.locking.SimpleLockingTestEntity in project cayenne by apache.
the class OptimisticLockingIT method testSuccessSimpleLockingOnDeletePrecededByInvalidate.
@Test
public void testSuccessSimpleLockingOnDeletePrecededByInvalidate() 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);
context.deleteObjects(object);
context.commitChanges();
}
use of org.apache.cayenne.testdo.locking.SimpleLockingTestEntity in project cayenne by apache.
the class OptimisticLockingIT method testSuccessSimpleLockingOnDelete.
@Test
public void testSuccessSimpleLockingOnDelete() 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.commitChanges();
}
use of org.apache.cayenne.testdo.locking.SimpleLockingTestEntity in project cayenne by apache.
the class OptimisticLockingIT method testSuccessSimpleLockingOnUpdate.
@Test
public void testSuccessSimpleLockingOnUpdate() 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.commitChanges();
}
Aggregations