Search in sources :

Example 1 with SimpleLockingTestEntity

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...
    }
}
Also used : RelLockingTestEntity(org.apache.cayenne.testdo.locking.RelLockingTestEntity) SimpleLockingTestEntity(org.apache.cayenne.testdo.locking.SimpleLockingTestEntity) Test(org.junit.Test)

Example 2 with SimpleLockingTestEntity

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();
}
Also used : SimpleLockingTestEntity(org.apache.cayenne.testdo.locking.SimpleLockingTestEntity) Test(org.junit.Test)

Example 3 with SimpleLockingTestEntity

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();
}
Also used : SimpleLockingTestEntity(org.apache.cayenne.testdo.locking.SimpleLockingTestEntity) Test(org.junit.Test)

Example 4 with SimpleLockingTestEntity

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();
}
Also used : SimpleLockingTestEntity(org.apache.cayenne.testdo.locking.SimpleLockingTestEntity) Test(org.junit.Test)

Example 5 with SimpleLockingTestEntity

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();
}
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