Search in sources :

Example 6 with SimpleLockingTestEntity

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

Example 7 with SimpleLockingTestEntity

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

Example 8 with SimpleLockingTestEntity

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

Example 9 with SimpleLockingTestEntity

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

Example 10 with SimpleLockingTestEntity

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