Search in sources :

Example 11 with SimpleLockingTestEntity

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

Example 12 with SimpleLockingTestEntity

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

Example 13 with SimpleLockingTestEntity

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

Example 14 with SimpleLockingTestEntity

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

Example 15 with SimpleLockingTestEntity

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...
    }
}
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