cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject [20/48] Installing Maven Failsafe Plugin
Date Sun, 02 Nov 2014 07:10:08 GMT
http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/NumericTypesTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/NumericTypesTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/NumericTypesTest.java
deleted file mode 100644
index 0a3a531..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/NumericTypesTest.java
+++ /dev/null
@@ -1,295 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.access;
-
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.List;
-
-import org.apache.cayenne.ObjectId;
-import org.apache.cayenne.configuration.server.ServerRuntime;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.exp.Expression;
-import org.apache.cayenne.exp.ExpressionFactory;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.test.jdbc.TableHelper;
-import org.apache.cayenne.testdo.testmap.BigDecimalEntity;
-import org.apache.cayenne.testdo.testmap.BigIntegerEntity;
-import org.apache.cayenne.testdo.testmap.BitTestEntity;
-import org.apache.cayenne.testdo.testmap.BooleanTestEntity;
-import org.apache.cayenne.testdo.testmap.DecimalPKTest1;
-import org.apache.cayenne.testdo.testmap.DecimalPKTestEntity;
-import org.apache.cayenne.testdo.testmap.LongEntity;
-import org.apache.cayenne.testdo.testmap.SmallintTestEntity;
-import org.apache.cayenne.testdo.testmap.TinyintTestEntity;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-/**
- */
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class NumericTypesTest extends ServerCase {
-
-    @Inject
-    protected DataContext context;
-
-    @Inject
-    protected DataContext context1;
-
-    @Inject
-    protected ServerRuntime runtime;
-
-    @Inject
-    protected DBHelper dbHelper;
-
-    protected TableHelper tSmallintTest;
-    protected TableHelper tTinyintTest;
-
-    @Override
-    protected void setUpAfterInjection() throws Exception {
-        dbHelper.deleteAll("BOOLEAN_TEST");
-        dbHelper.deleteAll("SMALLINT_TEST");
-        dbHelper.deleteAll("TINYINT_TEST");
-        dbHelper.deleteAll("DECIMAL_PK_TST");
-
-        tSmallintTest = new TableHelper(dbHelper, "SMALLINT_TEST");
-        tSmallintTest.setColumns("ID", "SMALLINT_COL");
-
-        tTinyintTest = new TableHelper(dbHelper, "TINYINT_TEST");
-        tTinyintTest.setColumns("ID", "TINYINT_COL");
-    }
-
-    protected void createShortDataSet() throws Exception {
-        tSmallintTest.insert(1, 9999);
-        tSmallintTest.insert(2, 3333);
-    }
-
-    protected void createTinyintDataSet() throws Exception {
-        tTinyintTest.insert(1, 81);
-        tTinyintTest.insert(2, 50);
-    }
-
-    public void testLong() throws Exception {
-
-        LongEntity test = context.newObject(LongEntity.class);
-
-        Long i = new Long(Integer.MAX_VALUE + 10l);
-        test.setLongField(i);
-        context.commitChanges();
-
-        SelectQuery q = new SelectQuery(LongEntity.class);
-        LongEntity testRead = (LongEntity) context.performQuery(q).get(0);
-        assertNotNull(testRead.getLongField());
-        assertEquals(i, testRead.getLongField());
-
-        test.setLongField(null);
-        context.commitChanges();
-    }
-
-    public void testBigInteger() throws Exception {
-
-        BigIntegerEntity test = context.newObject(BigIntegerEntity.class);
-
-        BigInteger i = new BigInteger("1234567890");
-        test.setBigIntegerField(i);
-        context.commitChanges();
-
-        SelectQuery q = new SelectQuery(BigIntegerEntity.class);
-        BigIntegerEntity testRead = (BigIntegerEntity) context.performQuery(q).get(0);
-        assertNotNull(testRead.getBigIntegerField());
-        assertEquals(i, testRead.getBigIntegerField());
-
-        test.setBigIntegerField(null);
-        context.commitChanges();
-    }
-
-    public void testBigDecimal() throws Exception {
-
-        BigDecimalEntity test = context.newObject(BigDecimalEntity.class);
-
-        BigDecimal i = new BigDecimal("1234567890.44");
-        test.setBigDecimalField(i);
-        context.commitChanges();
-
-        SelectQuery q = new SelectQuery(BigDecimalEntity.class);
-        BigDecimalEntity testRead = (BigDecimalEntity) context.performQuery(q).get(0);
-        assertNotNull(testRead.getBigDecimalField());
-        assertEquals(i, testRead.getBigDecimalField());
-
-        test.setBigDecimalField(null);
-        context.commitChanges();
-    }
-
-    public void testShortInQualifier() throws Exception {
-        createShortDataSet();
-
-        // test
-        Expression qual = ExpressionFactory.matchExp("smallintCol", new Short("9999"));
-        List<?> objects = context.performQuery(new SelectQuery(
-                SmallintTestEntity.class,
-                qual));
-        assertEquals(1, objects.size());
-
-        SmallintTestEntity object = (SmallintTestEntity) objects.get(0);
-        assertEquals(new Short("9999"), object.getSmallintCol());
-    }
-
-    public void testShortInInsert() throws Exception {
-        SmallintTestEntity object = (SmallintTestEntity) (context)
-                .newObject("SmallintTestEntity");
-        object.setSmallintCol(new Short("1"));
-        context.commitChanges();
-    }
-
-    public void testTinyintInQualifier() throws Exception {
-        createTinyintDataSet();
-
-        // test
-        Expression qual = ExpressionFactory.matchExp("tinyintCol", new Byte((byte) 81));
-        List<?> objects = context.performQuery(new SelectQuery(
-                TinyintTestEntity.class,
-                qual));
-        assertEquals(1, objects.size());
-
-        TinyintTestEntity object = (TinyintTestEntity) objects.get(0);
-        assertEquals(new Byte((byte) 81), object.getTinyintCol());
-    }
-
-    public void testTinyintInInsert() throws Exception {
-        TinyintTestEntity object = (TinyintTestEntity) (context)
-                .newObject("TinyintTestEntity");
-        object.setTinyintCol(new Byte((byte) 1));
-        context.commitChanges();
-    }
-
-    public void testBooleanBit() throws Exception {
-
-        BitTestEntity trueObject = (BitTestEntity) context.newObject("BitTestEntity");
-        trueObject.setBitColumn(Boolean.TRUE);
-        BitTestEntity falseObject = (BitTestEntity) context.newObject("BitTestEntity");
-        falseObject.setBitColumn(Boolean.FALSE);
-        context.commitChanges();
-        context.invalidateObjects(trueObject, falseObject);
-
-        // fetch true...
-        Expression trueQ = ExpressionFactory.matchExp("bitColumn", Boolean.TRUE);
-        List<?> trueResult = context1.performQuery(new SelectQuery(
-                BitTestEntity.class,
-                trueQ));
-        assertEquals(1, trueResult.size());
-
-        BitTestEntity trueRefetched = (BitTestEntity) trueResult.get(0);
-        assertEquals(Boolean.TRUE, trueRefetched.getBitColumn());
-
-        // CAY-320. Simplifying the use of booleans to allow identity comparison.
-        assertNotSame(trueRefetched, trueObject);
-        assertSame(Boolean.TRUE, trueRefetched.getBitColumn());
-
-        // fetch false
-        Expression falseQ = ExpressionFactory.matchExp("bitColumn", Boolean.FALSE);
-        List<?> falseResult = context1.performQuery(new SelectQuery(
-                BitTestEntity.class,
-                falseQ));
-        assertEquals(1, falseResult.size());
-
-        BitTestEntity falseRefetched = (BitTestEntity) falseResult.get(0);
-        assertEquals(Boolean.FALSE, falseRefetched.getBitColumn());
-
-        // CAY-320. Simplifying the use of booleans to allow identity comparison.
-        assertNotSame(falseRefetched, falseObject);
-        assertSame(Boolean.FALSE, falseRefetched.getBitColumn());
-    }
-
-    public void testBooleanBoolean() throws Exception {
-
-        // populate (testing insert as well)
-        BooleanTestEntity trueObject = (BooleanTestEntity) context
-                .newObject("BooleanTestEntity");
-        trueObject.setBooleanColumn(Boolean.TRUE);
-        BooleanTestEntity falseObject = (BooleanTestEntity) context
-                .newObject("BooleanTestEntity");
-        falseObject.setBooleanColumn(Boolean.FALSE);
-        context.commitChanges();
-
-        context.invalidateObjects(trueObject, falseObject);
-
-        // fetch true...
-        Expression trueQ = ExpressionFactory.matchExp("booleanColumn", Boolean.TRUE);
-        List<?> trueResult = context1.performQuery(new SelectQuery(
-                BooleanTestEntity.class,
-                trueQ));
-        assertEquals(1, trueResult.size());
-
-        BooleanTestEntity trueRefetched = (BooleanTestEntity) trueResult.get(0);
-        assertEquals(Boolean.TRUE, trueRefetched.getBooleanColumn());
-
-        // CAY-320. Simplifying the use of booleans to allow identity comparison.
-        assertNotSame(trueRefetched, trueObject);
-        assertSame(Boolean.TRUE, trueRefetched.getBooleanColumn());
-
-        // fetch false
-        Expression falseQ = ExpressionFactory.matchExp("booleanColumn", Boolean.FALSE);
-        List<?> falseResult = context1.performQuery(new SelectQuery(
-                BooleanTestEntity.class,
-                falseQ));
-        assertEquals(1, falseResult.size());
-
-        BooleanTestEntity falseRefetched = (BooleanTestEntity) falseResult.get(0);
-        assertEquals(Boolean.FALSE, falseRefetched.getBooleanColumn());
-
-        // CAY-320. Simplifying the use of booleans to allow identity comparison.
-        assertNotSame(falseRefetched, falseObject);
-        assertSame(Boolean.FALSE, falseRefetched.getBooleanColumn());
-    }
-
-    public void testDecimalPK() throws Exception {
-
-        // populate (testing insert as well)
-        DecimalPKTestEntity object = context.newObject(DecimalPKTestEntity.class);
-
-        object.setName("o1");
-        object.setDecimalPK(new BigDecimal("1.25"));
-        context.commitChanges();
-
-        ObjectId syntheticId = new ObjectId(
-                "DecimalPKTestEntity",
-                "DECIMAL_PK",
-                new BigDecimal("1.25"));
-        assertSame(object, context.getGraphManager().getNode(syntheticId));
-
-        context.deleteObjects(object);
-        context.commitChanges();
-    }
-
-    public void testDecimalPK1() throws Exception {
-
-        // populate (testing insert as well)
-        DecimalPKTest1 object = context.newObject(DecimalPKTest1.class);
-
-        object.setName("o2");
-        object.setDecimalPK(new Double(1.25));
-        context.commitChanges();
-
-        ObjectId syntheticId = new ObjectId("DecimalPKTest1", "DECIMAL_PK", new Double(
-                1.25));
-        assertSame(object, context.getGraphManager().getNode(syntheticId));
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreDiffRetainingIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreDiffRetainingIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreDiffRetainingIT.java
new file mode 100644
index 0000000..f8b11d7
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreDiffRetainingIT.java
@@ -0,0 +1,107 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.access;
+
+import org.apache.cayenne.Cayenne;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.testdo.testmap.Painting;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.sql.Types;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class ObjectStoreDiffRetainingIT extends ServerCase {
+
+    @Inject
+    protected DataContext context;
+
+    @Inject
+    protected DBHelper dbHelper;
+
+    protected TableHelper tArtist;
+    protected TableHelper tPainting;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("PAINTING_INFO");
+        dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST_EXHIBIT");
+        dbHelper.deleteAll("ARTIST_GROUP");
+        dbHelper.deleteAll("ARTIST");
+
+        tArtist = new TableHelper(dbHelper, "ARTIST");
+        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME", "DATE_OF_BIRTH")
+                .setColumnTypes(Types.BIGINT, Types.CHAR, Types.DATE);
+
+        tPainting = new TableHelper(dbHelper, "PAINTING");
+        tPainting.setColumns(
+                "ARTIST_ID",
+                "ESTIMATED_PRICE",
+                "GALLERY_ID",
+                "PAINTING_ID",
+                "PAINTING_TITLE").setColumnTypes(
+                 Types.BIGINT,
+                 Types.DECIMAL,
+                 Types.INTEGER,
+                 Types.INTEGER,
+                 Types.VARCHAR);
+    }
+
+    protected void createMixedDataSet() throws Exception {
+        tArtist.insert(2000, "artist with one painting", null);
+        tPainting.insert(2000, null, null, 3000, "p1");
+    }
+
+    public void testSnapshotRetainedOnPropertyModification() throws Exception {
+        createMixedDataSet();
+
+        Artist a = Cayenne.objectForPK(context, Artist.class, 2000);
+        ObjectStore objectStore = context.getObjectStore();
+
+        assertNull(objectStore.getChangesByObjectId().get(a.getObjectId()));
+
+        a.setArtistName("some other name");
+        assertNotNull(objectStore.getChangesByObjectId().get(a.getObjectId()));
+    }
+
+    public void testSnapshotRetainedOnRelAndPropertyModification() throws Exception {
+        createMixedDataSet();
+
+        Artist a = Cayenne.objectForPK(context, Artist.class, 2000);
+        ObjectStore objectStore = context.getObjectStore();
+
+        assertNull(objectStore.getChangesByObjectId().get(a.getObjectId()));
+
+        // we are trying to reproduce the bug CAY-213 - relationship modification puts
+        // object in a modified state, so later when object is really modified, its
+        // snapshot is not retained... in testing this I am leaving some flexibility for
+        // the framework to retain a snapshot when it deems appropriate...
+
+        a.addToPaintingArray(context.newObject(Painting.class));
+        a.setArtistName("some other name");
+        assertNotNull("Snapshot wasn't retained - CAY-213", objectStore
+                .getChangesByObjectId()
+                .get(a.getObjectId()));
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreDiffRetainingTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreDiffRetainingTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreDiffRetainingTest.java
deleted file mode 100644
index cdd4f5d..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreDiffRetainingTest.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.access;
-
-import java.sql.Types;
-
-import org.apache.cayenne.Cayenne;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.test.jdbc.TableHelper;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.testdo.testmap.Painting;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class ObjectStoreDiffRetainingTest extends ServerCase {
-
-    @Inject
-    protected DataContext context;
-
-    @Inject
-    protected DBHelper dbHelper;
-
-    protected TableHelper tArtist;
-    protected TableHelper tPainting;
-
-    @Override
-    protected void setUpAfterInjection() throws Exception {
-        dbHelper.deleteAll("PAINTING_INFO");
-        dbHelper.deleteAll("PAINTING");
-        dbHelper.deleteAll("ARTIST_EXHIBIT");
-        dbHelper.deleteAll("ARTIST_GROUP");
-        dbHelper.deleteAll("ARTIST");
-
-        tArtist = new TableHelper(dbHelper, "ARTIST");
-        tArtist.setColumns("ARTIST_ID", "ARTIST_NAME", "DATE_OF_BIRTH")
-                .setColumnTypes(Types.BIGINT, Types.CHAR, Types.DATE);
-
-        tPainting = new TableHelper(dbHelper, "PAINTING");
-        tPainting.setColumns(
-                "ARTIST_ID",
-                "ESTIMATED_PRICE",
-                "GALLERY_ID",
-                "PAINTING_ID",
-                "PAINTING_TITLE").setColumnTypes(
-                 Types.BIGINT,
-                 Types.DECIMAL,
-                 Types.INTEGER,
-                 Types.INTEGER,
-                 Types.VARCHAR);
-    }
-
-    protected void createMixedDataSet() throws Exception {
-        tArtist.insert(2000, "artist with one painting", null);
-        tPainting.insert(2000, null, null, 3000, "p1");
-    }
-
-    public void testSnapshotRetainedOnPropertyModification() throws Exception {
-        createMixedDataSet();
-
-        Artist a = Cayenne.objectForPK(context, Artist.class, 2000);
-        ObjectStore objectStore = context.getObjectStore();
-
-        assertNull(objectStore.getChangesByObjectId().get(a.getObjectId()));
-
-        a.setArtistName("some other name");
-        assertNotNull(objectStore.getChangesByObjectId().get(a.getObjectId()));
-    }
-
-    public void testSnapshotRetainedOnRelAndPropertyModification() throws Exception {
-        createMixedDataSet();
-
-        Artist a = Cayenne.objectForPK(context, Artist.class, 2000);
-        ObjectStore objectStore = context.getObjectStore();
-
-        assertNull(objectStore.getChangesByObjectId().get(a.getObjectId()));
-
-        // we are trying to reproduce the bug CAY-213 - relationship modification puts
-        // object in a modified state, so later when object is really modified, its
-        // snapshot is not retained... in testing this I am leaving some flexibility for
-        // the framework to retain a snapshot when it deems appropriate...
-
-        a.addToPaintingArray(context.newObject(Painting.class));
-        a.setArtistName("some other name");
-        assertNotNull("Snapshot wasn't retained - CAY-213", objectStore
-                .getChangesByObjectId()
-                .get(a.getObjectId()));
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreGCIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreGCIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreGCIT.java
new file mode 100644
index 0000000..86e8ede
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreGCIT.java
@@ -0,0 +1,130 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.access;
+
+import org.apache.cayenne.Cayenne;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.query.SQLTemplate;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.parallel.ParallelTestContainer;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class ObjectStoreGCIT extends ServerCase {
+
+    @Inject
+    private DataContext context;
+
+    @Inject
+    private DBHelper dbHelper;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("PAINTING_INFO");
+        dbHelper.deleteAll("PAINTING");
+        dbHelper.deleteAll("ARTIST_EXHIBIT");
+        dbHelper.deleteAll("ARTIST_GROUP");
+        dbHelper.deleteAll("ARTIST");
+    }
+
+    public void testReleaseUnreferenced() throws Exception {
+        context.performGenericQuery(new SQLTemplate(
+                Artist.class,
+                "insert into ARTIST (ARTIST_ID, ARTIST_NAME) values (1, 'aa')"));
+
+        assertEquals(0, context.getObjectStore().registeredObjectsCount());
+        context.performQuery(new SelectQuery(Artist.class));
+        assertEquals(1, context.getObjectStore().registeredObjectsCount());
+
+        // allow for slow GC
+        new ParallelTestContainer() {
+
+            @Override
+            protected void assertResult() throws Exception {
+                System.gc();
+                assertEquals(0, context.getObjectStore().registeredObjectsCount());
+            }
+        }.runTest(2000);
+    }
+
+    public void testRetainUnreferencedNew() throws Exception {
+        assertEquals(0, context.getObjectStore().registeredObjectsCount());
+        Artist a = context.newObject(Artist.class);
+        a.setArtistName("X");
+        a = null;
+        assertEquals(1, context.getObjectStore().registeredObjectsCount());
+
+        // allow for slow GC
+        new ParallelTestContainer() {
+
+            @Override
+            protected void assertResult() throws Exception {
+                System.gc();
+                assertEquals(1, context.getObjectStore().registeredObjectsCount());
+            }
+        }.runTest(2000);
+
+        assertEquals(1, context.getObjectStore().registeredObjectsCount());
+        context.commitChanges();
+        new ParallelTestContainer() {
+
+            @Override
+            protected void assertResult() throws Exception {
+                System.gc();
+                assertEquals(0, context.getObjectStore().registeredObjectsCount());
+            }
+        }.runTest(2000);
+
+    }
+
+    public void testRetainUnreferencedModified() throws Exception {
+        context.performGenericQuery(new SQLTemplate(
+                Artist.class,
+                "insert into ARTIST (ARTIST_ID, ARTIST_NAME) values (1, 'aa')"));
+
+        assertEquals(0, context.getObjectStore().registeredObjectsCount());
+        Artist a = Cayenne.objectForPK(context, Artist.class, 1);
+        a.setArtistName("Y");
+        a = null;
+        assertEquals(1, context.getObjectStore().registeredObjectsCount());
+
+        new ParallelTestContainer() {
+
+            @Override
+            protected void assertResult() throws Exception {
+                System.gc();
+                assertEquals(1, context.getObjectStore().registeredObjectsCount());
+            }
+        }.runTest(2000);
+
+        context.commitChanges();
+        new ParallelTestContainer() {
+
+            @Override
+            protected void assertResult() throws Exception {
+                System.gc();
+                assertEquals(0, context.getObjectStore().registeredObjectsCount());
+            }
+        }.runTest(2000);
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreGCTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreGCTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreGCTest.java
deleted file mode 100644
index fe6bce0..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreGCTest.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-package org.apache.cayenne.access;
-
-import org.apache.cayenne.Cayenne;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.query.SQLTemplate;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.test.parallel.ParallelTestContainer;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class ObjectStoreGCTest extends ServerCase {
-
-    @Inject
-    private DataContext context;
-
-    @Inject
-    private DBHelper dbHelper;
-
-    @Override
-    protected void setUpAfterInjection() throws Exception {
-        dbHelper.deleteAll("PAINTING_INFO");
-        dbHelper.deleteAll("PAINTING");
-        dbHelper.deleteAll("ARTIST_EXHIBIT");
-        dbHelper.deleteAll("ARTIST_GROUP");
-        dbHelper.deleteAll("ARTIST");
-    }
-
-    public void testReleaseUnreferenced() throws Exception {
-        context.performGenericQuery(new SQLTemplate(
-                Artist.class,
-                "insert into ARTIST (ARTIST_ID, ARTIST_NAME) values (1, 'aa')"));
-
-        assertEquals(0, context.getObjectStore().registeredObjectsCount());
-        context.performQuery(new SelectQuery(Artist.class));
-        assertEquals(1, context.getObjectStore().registeredObjectsCount());
-
-        // allow for slow GC
-        new ParallelTestContainer() {
-
-            @Override
-            protected void assertResult() throws Exception {
-                System.gc();
-                assertEquals(0, context.getObjectStore().registeredObjectsCount());
-            }
-        }.runTest(2000);
-    }
-
-    public void testRetainUnreferencedNew() throws Exception {
-        assertEquals(0, context.getObjectStore().registeredObjectsCount());
-        Artist a = context.newObject(Artist.class);
-        a.setArtistName("X");
-        a = null;
-        assertEquals(1, context.getObjectStore().registeredObjectsCount());
-
-        // allow for slow GC
-        new ParallelTestContainer() {
-
-            @Override
-            protected void assertResult() throws Exception {
-                System.gc();
-                assertEquals(1, context.getObjectStore().registeredObjectsCount());
-            }
-        }.runTest(2000);
-
-        assertEquals(1, context.getObjectStore().registeredObjectsCount());
-        context.commitChanges();
-        new ParallelTestContainer() {
-
-            @Override
-            protected void assertResult() throws Exception {
-                System.gc();
-                assertEquals(0, context.getObjectStore().registeredObjectsCount());
-            }
-        }.runTest(2000);
-
-    }
-
-    public void testRetainUnreferencedModified() throws Exception {
-        context.performGenericQuery(new SQLTemplate(
-                Artist.class,
-                "insert into ARTIST (ARTIST_ID, ARTIST_NAME) values (1, 'aa')"));
-
-        assertEquals(0, context.getObjectStore().registeredObjectsCount());
-        Artist a = Cayenne.objectForPK(context, Artist.class, 1);
-        a.setArtistName("Y");
-        a = null;
-        assertEquals(1, context.getObjectStore().registeredObjectsCount());
-
-        new ParallelTestContainer() {
-
-            @Override
-            protected void assertResult() throws Exception {
-                System.gc();
-                assertEquals(1, context.getObjectStore().registeredObjectsCount());
-            }
-        }.runTest(2000);
-
-        context.commitChanges();
-        new ParallelTestContainer() {
-
-            @Override
-            protected void assertResult() throws Exception {
-                System.gc();
-                assertEquals(0, context.getObjectStore().registeredObjectsCount());
-            }
-        }.runTest(2000);
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreIT.java
new file mode 100644
index 0000000..8e24d38
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreIT.java
@@ -0,0 +1,133 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.access;
+
+import org.apache.cayenne.Cayenne;
+import org.apache.cayenne.DataObject;
+import org.apache.cayenne.DataRow;
+import org.apache.cayenne.MockDataObject;
+import org.apache.cayenne.ObjectId;
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.testdo.testmap.Artist;
+import org.apache.cayenne.testdo.testmap.Gallery;
+import org.apache.cayenne.testdo.testmap.Painting;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+import java.util.Collections;
+import java.util.Date;
+
+@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
+public class ObjectStoreIT extends ServerCase {
+
+    @Inject
+    private DataContext context;
+
+    public void testRegisteredObjectsCount() throws Exception {
+
+        assertEquals(0, context.getObjectStore().registeredObjectsCount());
+
+        DataObject o1 = new MockDataObject();
+        o1.setObjectId(new ObjectId("T", "key1", "v1"));
+        context.getObjectStore().registerNode(o1.getObjectId(), o1);
+        assertEquals(1, context.getObjectStore().registeredObjectsCount());
+
+        // test object with same id
+        DataObject o2 = new MockDataObject();
+        o2.setObjectId(new ObjectId("T", "key1", "v1"));
+        context.getObjectStore().registerNode(o2.getObjectId(), o2);
+        assertEquals(1, context.getObjectStore().registeredObjectsCount());
+
+        // test new object
+        DataObject o3 = new MockDataObject();
+        o3.setObjectId(new ObjectId("T", "key3", "v3"));
+        context.getObjectStore().registerNode(o3.getObjectId(), o3);
+        assertEquals(2, context.getObjectStore().registeredObjectsCount());
+    }
+
+    public void testObjectsUnregistered() throws Exception {
+
+        DataRow row = new DataRow(10);
+        row.put("ARTIST_ID", new Integer(1));
+        row.put("ARTIST_NAME", "ArtistXYZ");
+        row.put("DATE_OF_BIRTH", new Date());
+        DataObject object = context.objectFromDataRow(Artist.class, row);
+        ObjectId oid = object.getObjectId();
+
+        // insert object into the ObjectStore
+        context.getObjectStore().registerNode(oid, object);
+        assertSame(object, context.getObjectStore().getNode(oid));
+        assertNotNull(context.getObjectStore().getCachedSnapshot(oid));
+
+        context.getObjectStore().objectsUnregistered(Collections.singletonList(object));
+
+        assertNull(object.getObjectId());
+        assertNull(context.getObjectStore().getNode(oid));
+
+        // in the future this may not be the case
+        assertNull(context.getObjectStore().getCachedSnapshot(oid));
+    }
+
+    public void testUnregisterThenRegister() throws Exception {
+
+        // Create a gallery.
+        Gallery g = context.newObject(Gallery.class);
+        g.setGalleryName("Test Gallery");
+
+        // Create an artist in the same context.
+        Artist a = context.newObject(Artist.class);
+        a.setArtistName("Test Artist");
+
+        // Create a painting in the same context.
+        Painting p = context.newObject(Painting.class);
+        p.setPaintingTitle("Test Painting");
+
+        // Set the painting's gallery.
+        p.setToGallery(g);
+        assertEquals(g, p.getToGallery());
+
+        // Unregister the painting from the context.
+        context.unregisterObjects(Collections.singletonList(p));
+
+        // Make sure that even though the painting has been removed from the context's
+        // object graph that the reference to the gallery is the same.
+        assertEquals(g, p.getToGallery());
+
+        // Now, set the relationship between "p" & "a." Since "p" is not registered with a
+        // context, but "a" is, "p" should be auto-registered with the context of "a."
+        p.setToArtist(a);
+
+        // Now commit the gallery, artist, & painting.
+        context.commitChanges();
+
+        // Check one last time that the painting's gallery is set to what we expect.
+        assertEquals(g, p.getToGallery());
+
+        // Now, retrieve the same painting from the DB. Note that the gallery relationship
+        // is null even though according to our painting, that should not be the case; a
+        // NULL
+        // value has been recorded to the DB for the painting's gallery_id field.
+        //
+        // The full object graph is not being re-registered during auto-registration
+        // with the context.
+        Painting newP = (Painting) Cayenne.objectForPK(context, p.getObjectId());
+        assertNotNull(newP.getToGallery());
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreTest.java
deleted file mode 100644
index f270ff4..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/ObjectStoreTest.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.access;
-
-import java.util.Collections;
-import java.util.Date;
-
-import org.apache.cayenne.Cayenne;
-import org.apache.cayenne.DataObject;
-import org.apache.cayenne.DataRow;
-import org.apache.cayenne.MockDataObject;
-import org.apache.cayenne.ObjectId;
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.testdo.testmap.Artist;
-import org.apache.cayenne.testdo.testmap.Gallery;
-import org.apache.cayenne.testdo.testmap.Painting;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.TESTMAP_PROJECT)
-public class ObjectStoreTest extends ServerCase {
-
-    @Inject
-    private DataContext context;
-
-    public void testRegisteredObjectsCount() throws Exception {
-
-        assertEquals(0, context.getObjectStore().registeredObjectsCount());
-
-        DataObject o1 = new MockDataObject();
-        o1.setObjectId(new ObjectId("T", "key1", "v1"));
-        context.getObjectStore().registerNode(o1.getObjectId(), o1);
-        assertEquals(1, context.getObjectStore().registeredObjectsCount());
-
-        // test object with same id
-        DataObject o2 = new MockDataObject();
-        o2.setObjectId(new ObjectId("T", "key1", "v1"));
-        context.getObjectStore().registerNode(o2.getObjectId(), o2);
-        assertEquals(1, context.getObjectStore().registeredObjectsCount());
-
-        // test new object
-        DataObject o3 = new MockDataObject();
-        o3.setObjectId(new ObjectId("T", "key3", "v3"));
-        context.getObjectStore().registerNode(o3.getObjectId(), o3);
-        assertEquals(2, context.getObjectStore().registeredObjectsCount());
-    }
-
-    public void testObjectsUnregistered() throws Exception {
-
-        DataRow row = new DataRow(10);
-        row.put("ARTIST_ID", new Integer(1));
-        row.put("ARTIST_NAME", "ArtistXYZ");
-        row.put("DATE_OF_BIRTH", new Date());
-        DataObject object = context.objectFromDataRow(Artist.class, row);
-        ObjectId oid = object.getObjectId();
-
-        // insert object into the ObjectStore
-        context.getObjectStore().registerNode(oid, object);
-        assertSame(object, context.getObjectStore().getNode(oid));
-        assertNotNull(context.getObjectStore().getCachedSnapshot(oid));
-
-        context.getObjectStore().objectsUnregistered(Collections.singletonList(object));
-
-        assertNull(object.getObjectId());
-        assertNull(context.getObjectStore().getNode(oid));
-
-        // in the future this may not be the case
-        assertNull(context.getObjectStore().getCachedSnapshot(oid));
-    }
-
-    public void testUnregisterThenRegister() throws Exception {
-
-        // Create a gallery.
-        Gallery g = context.newObject(Gallery.class);
-        g.setGalleryName("Test Gallery");
-
-        // Create an artist in the same context.
-        Artist a = context.newObject(Artist.class);
-        a.setArtistName("Test Artist");
-
-        // Create a painting in the same context.
-        Painting p = context.newObject(Painting.class);
-        p.setPaintingTitle("Test Painting");
-
-        // Set the painting's gallery.
-        p.setToGallery(g);
-        assertEquals(g, p.getToGallery());
-
-        // Unregister the painting from the context.
-        context.unregisterObjects(Collections.singletonList(p));
-
-        // Make sure that even though the painting has been removed from the context's
-        // object graph that the reference to the gallery is the same.
-        assertEquals(g, p.getToGallery());
-
-        // Now, set the relationship between "p" & "a." Since "p" is not registered with a
-        // context, but "a" is, "p" should be auto-registered with the context of "a."
-        p.setToArtist(a);
-
-        // Now commit the gallery, artist, & painting.
-        context.commitChanges();
-
-        // Check one last time that the painting's gallery is set to what we expect.
-        assertEquals(g, p.getToGallery());
-
-        // Now, retrieve the same painting from the DB. Note that the gallery relationship
-        // is null even though according to our painting, that should not be the case; a
-        // NULL
-        // value has been recorded to the DB for the painting's gallery_id field.
-        //
-        // The full object graph is not being re-registered during auto-registration
-        // with the context.
-        Painting newP = (Painting) Cayenne.objectForPK(context, p.getObjectId());
-        assertNotNull(newP.getToGallery());
-    }
-}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/OptimisticLockingIT.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/OptimisticLockingIT.java b/cayenne-server/src/test/java/org/apache/cayenne/access/OptimisticLockingIT.java
new file mode 100644
index 0000000..b345f2a
--- /dev/null
+++ b/cayenne-server/src/test/java/org/apache/cayenne/access/OptimisticLockingIT.java
@@ -0,0 +1,498 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+
+package org.apache.cayenne.access;
+
+import java.sql.Types;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cayenne.di.Inject;
+import org.apache.cayenne.query.Ordering;
+import org.apache.cayenne.query.SelectQuery;
+import org.apache.cayenne.query.SortOrder;
+import org.apache.cayenne.test.jdbc.DBHelper;
+import org.apache.cayenne.test.jdbc.TableHelper;
+import org.apache.cayenne.testdo.locking.RelLockingTestEntity;
+import org.apache.cayenne.testdo.locking.SimpleLockingTestEntity;
+import org.apache.cayenne.unit.di.server.ServerCase;
+import org.apache.cayenne.unit.di.server.UseServerRuntime;
+
+@UseServerRuntime(ServerCase.LOCKING_PROJECT)
+public class OptimisticLockingIT extends ServerCase {
+
+    @Inject
+    protected DataContext context;
+
+    @Inject
+    protected DBHelper dbHelper;
+
+    protected TableHelper tSimpleLockingTest;
+    protected TableHelper tRelLockingTest;
+    protected TableHelper tLockingHelper;
+
+    @Override
+    protected void setUpAfterInjection() throws Exception {
+        dbHelper.deleteAll("LOCKING_HELPER");
+        dbHelper.deleteAll("REL_LOCKING_TEST");
+        dbHelper.deleteAll("SIMPLE_LOCKING_TEST");
+
+        tSimpleLockingTest = new TableHelper(dbHelper, "SIMPLE_LOCKING_TEST");
+        tSimpleLockingTest.setColumns("LOCKING_TEST_ID", "NAME", "DESCRIPTION")
+                .setColumnTypes(Types.INTEGER, Types.VARCHAR, Types.VARCHAR);
+
+        tRelLockingTest = new TableHelper(dbHelper, "REL_LOCKING_TEST");
+        tRelLockingTest.setColumns(
+                "REL_LOCKING_TEST_ID",
+                "SIMPLE_LOCKING_TEST_ID",
+                "NAME");
+
+        tLockingHelper = new TableHelper(dbHelper, "LOCKING_HELPER");
+        tLockingHelper.setColumns("LOCKING_HELPER_ID", "REL_LOCKING_TEST_ID", "NAME");
+    }
+
+    protected void createSimpleLockingDataSet() throws Exception {
+        tLockingHelper.delete().execute();
+        tRelLockingTest.delete().execute();
+        tSimpleLockingTest.delete().execute();
+        tSimpleLockingTest.insert(1, "LockTest1", null);
+    }
+
+    protected void createLockingOnNullDataSet() throws Exception {
+        tLockingHelper.delete().execute();
+        tRelLockingTest.delete().execute();
+        tSimpleLockingTest.delete().execute();
+        tSimpleLockingTest.insert(1, null, null);
+    }
+
+    protected void createLockingOnMixedDataSet() throws Exception {
+        tLockingHelper.delete().execute();
+        tRelLockingTest.delete().execute();
+        tSimpleLockingTest.delete().execute();
+        tSimpleLockingTest.insert(1, null, null);
+        tSimpleLockingTest.insert(2, "LockTest2", null);
+        tSimpleLockingTest.insert(3, "LockTest3", "Another Lock Test");
+    }
+
+    protected void createLockingOnToOneDataSet() throws Exception {
+        tLockingHelper.delete().execute();
+        tRelLockingTest.delete().execute();
+        tSimpleLockingTest.delete().execute();
+        tSimpleLockingTest.insert(1, "LockTest1", null);
+        tRelLockingTest.insert(5, 1, "Rel Test 1");
+        tLockingHelper.insert(1, 5, "Locking Helper 1");
+    }
+
+    protected void createSimpleLockUpdate() throws Exception {
+        assertEquals(1, tSimpleLockingTest
+                .update()
+                .set("NAME", "LockTest1Updated")
+                .where("LOCKING_TEST_ID", 1)
+                .execute());
+    }
+
+    protected void createRelLockUpdate() throws Exception {
+        tRelLockingTest.update().set("SIMPLE_LOCKING_TEST_ID", 1).where(
+                "REL_LOCKING_TEST_ID",
+                5).execute();
+    }
+
+    protected void createSimpleLockDelete() throws Exception {
+        tSimpleLockingTest.delete().execute();
+    }
+
+    public void testSuccessSimpleLockingOnDelete() throws Exception {
+        createSimpleLockingDataSet();
+
+        List<?> allObjects = context.performQuery(new SelectQuery(
+                SimpleLockingTestEntity.class));
+        assertEquals(1, allObjects.size());
+
+        SimpleLockingTestEntity object = (SimpleLockingTestEntity) allObjects.get(0);
+
+        // change description and save... no optimistic lock failure expected
+        object.setDescription("first update");
+        context.commitChanges();
+
+        context.deleteObjects(object);
+        context.commitChanges();
+    }
+
+    public void testSuccessSimpleLockingOnDeleteFollowedByInvalidate() throws Exception {
+        createSimpleLockingDataSet();
+
+        List<?> allObjects = context.performQuery(new SelectQuery(
+                SimpleLockingTestEntity.class));
+        assertEquals(1, allObjects.size());
+
+        SimpleLockingTestEntity object = (SimpleLockingTestEntity) 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();
+    }
+
+    public void testSuccessSimpleLockingOnDeleteFollowedByForgetSnapshot()
+            throws Exception {
+        createSimpleLockingDataSet();
+
+        List<?> allObjects = context.performQuery(new SelectQuery(
+                SimpleLockingTestEntity.class));
+        assertEquals(1, allObjects.size());
+
+        SimpleLockingTestEntity object = (SimpleLockingTestEntity) 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();
+    }
+
+    public void testSuccessSimpleLockingOnDeletePrecededByInvalidate() throws Exception {
+        createSimpleLockingDataSet();
+
+        List<?> allObjects = context.performQuery(new SelectQuery(
+                SimpleLockingTestEntity.class));
+        assertEquals(1, allObjects.size());
+
+        SimpleLockingTestEntity object = (SimpleLockingTestEntity) 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();
+    }
+
+    public void testSuccessSimpleLockingOnDeletePrecededByForgetSnapshot()
+            throws Exception {
+        createSimpleLockingDataSet();
+
+        List<?> allObjects = context.performQuery(new SelectQuery(
+                SimpleLockingTestEntity.class));
+        assertEquals(1, allObjects.size());
+
+        SimpleLockingTestEntity object = (SimpleLockingTestEntity) 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();
+    }
+
+    public void testFailSimpleLockingOnDelete() throws Exception {
+        createSimpleLockingDataSet();
+
+        List<?> allObjects = context.performQuery(new SelectQuery(
+                SimpleLockingTestEntity.class));
+        assertEquals(1, allObjects.size());
+
+        SimpleLockingTestEntity object = (SimpleLockingTestEntity) allObjects.get(0);
+
+        // change description and save... no optimistic lock failure expected
+        object.setDescription("second update");
+        context.commitChanges();
+
+        // change row underneath, delete and save... optimistic lock failure expected
+        createSimpleLockUpdate();
+
+        context.deleteObjects(object);
+
+        try {
+            context.commitChanges();
+            fail("Optimistic lock failure expected.");
+        }
+        catch (OptimisticLockException ex) {
+            // optimistic lock failure expected...
+        }
+    }
+
+    public void testSuccessSimpleLockingOnUpdate() throws Exception {
+        createSimpleLockingDataSet();
+
+        List<?> allObjects = context.performQuery(new SelectQuery(
+                SimpleLockingTestEntity.class));
+        assertEquals(1, allObjects.size());
+
+        SimpleLockingTestEntity object = (SimpleLockingTestEntity) allObjects.get(0);
+
+        // change description and save... no optimistic lock failure expected
+        object.setDescription("first update");
+        context.commitChanges();
+
+        object.setDescription("second update");
+
+        context.commitChanges();
+    }
+
+    public void testSuccessSimpleLockingOnUpdateFollowedByInvalidate() throws Exception {
+        createSimpleLockingDataSet();
+
+        List<?> allObjects = context.performQuery(new SelectQuery(
+                SimpleLockingTestEntity.class));
+        assertEquals(1, allObjects.size());
+
+        SimpleLockingTestEntity object = (SimpleLockingTestEntity) 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();
+    }
+
+    public void testSuccessSimpleLockingOnUpdatePrecededByInvalidate() throws Exception {
+        createSimpleLockingDataSet();
+
+        List<?> allObjects = context.performQuery(new SelectQuery(
+                SimpleLockingTestEntity.class));
+        assertEquals(1, allObjects.size());
+
+        SimpleLockingTestEntity object = (SimpleLockingTestEntity) allObjects.get(0);
+
+        // change description and save... no optimistic lock failure expected
+        object.setDescription("first update");
+        context.commitChanges();
+
+        context.invalidateObjects(object);
+        object.setDescription("second update");
+
+        context.commitChanges();
+    }
+
+    public void testSuccessSimpleLockingOnUpdateFollowedByForgetSnapshot()
+            throws Exception {
+        createSimpleLockingDataSet();
+
+        List<?> allObjects = context.performQuery(new SelectQuery(
+                SimpleLockingTestEntity.class));
+        assertEquals(1, allObjects.size());
+
+        SimpleLockingTestEntity object = (SimpleLockingTestEntity) 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();
+    }
+
+    public void testSuccessSimpleLockingOnUpdatePrecededByForgetSnapshot()
+            throws Exception {
+        createSimpleLockingDataSet();
+
+        List<?> allObjects = context.performQuery(new SelectQuery(
+                SimpleLockingTestEntity.class));
+        assertEquals(1, allObjects.size());
+
+        SimpleLockingTestEntity object = (SimpleLockingTestEntity) allObjects.get(0);
+
+        // change description and save... no optimistic lock failure expected
+        object.setDescription("first update");
+        context.commitChanges();
+
+        context.getObjectStore().getDataRowCache().forgetSnapshot(object.getObjectId());
+        object.setDescription("second update");
+
+        context.commitChanges();
+    }
+
+    public void testFailSimpleLocking() throws Exception {
+        createSimpleLockingDataSet();
+
+        List<?> allObjects = context.performQuery(new SelectQuery(
+                SimpleLockingTestEntity.class));
+        assertEquals(1, allObjects.size());
+
+        SimpleLockingTestEntity object = (SimpleLockingTestEntity) 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...
+        }
+    }
+
+    public void testFailLockingOnNull() throws Exception {
+        createLockingOnNullDataSet();
+
+        List<?> allObjects = context.performQuery(new SelectQuery(
+                SimpleLockingTestEntity.class));
+        assertEquals(1, allObjects.size());
+
+        SimpleLockingTestEntity object = (SimpleLockingTestEntity) 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());
+        }
+    }
+
+    public void testSuccessLockingOnMixed() throws Exception {
+        createLockingOnMixedDataSet();
+
+        SelectQuery 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.
+    }
+
+    public void testFailLockingOnToOne() throws Exception {
+        createLockingOnToOneDataSet();
+
+        List<?> allObjects = context.performQuery(new SelectQuery(
+                RelLockingTestEntity.class));
+        assertEquals(1, allObjects.size());
+
+        RelLockingTestEntity object = (RelLockingTestEntity) 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...
+        }
+    }
+
+    public void testFailRetrieveRow() throws Exception {
+        createSimpleLockingDataSet();
+
+        List<?> allObjects = context.performQuery(new SelectQuery(
+                SimpleLockingTestEntity.class));
+        assertEquals(1, allObjects.size());
+
+        SimpleLockingTestEntity object = (SimpleLockingTestEntity) 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"));
+        }
+    }
+
+    public void testFailRetrieveDeletedRow() throws Exception {
+        createSimpleLockingDataSet();
+
+        List<?> allObjects = context.performQuery(new SelectQuery(
+                SimpleLockingTestEntity.class));
+        assertEquals(1, allObjects.size());
+
+        SimpleLockingTestEntity object = (SimpleLockingTestEntity) 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);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e42c376c/cayenne-server/src/test/java/org/apache/cayenne/access/OptimisticLockingTest.java
----------------------------------------------------------------------
diff --git a/cayenne-server/src/test/java/org/apache/cayenne/access/OptimisticLockingTest.java b/cayenne-server/src/test/java/org/apache/cayenne/access/OptimisticLockingTest.java
deleted file mode 100644
index eff2363..0000000
--- a/cayenne-server/src/test/java/org/apache/cayenne/access/OptimisticLockingTest.java
+++ /dev/null
@@ -1,498 +0,0 @@
-/*****************************************************************
- *   Licensed to the Apache Software Foundation (ASF) under one
- *  or more contributor license agreements.  See the NOTICE file
- *  distributed with this work for additional information
- *  regarding copyright ownership.  The ASF licenses this file
- *  to you under the Apache License, Version 2.0 (the
- *  "License"); you may not use this file except in compliance
- *  with the License.  You may obtain a copy of the License at
- *
- *    http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing,
- *  software distributed under the License is distributed on an
- *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- *  KIND, either express or implied.  See the License for the
- *  specific language governing permissions and limitations
- *  under the License.
- ****************************************************************/
-
-package org.apache.cayenne.access;
-
-import java.sql.Types;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.cayenne.di.Inject;
-import org.apache.cayenne.query.Ordering;
-import org.apache.cayenne.query.SelectQuery;
-import org.apache.cayenne.query.SortOrder;
-import org.apache.cayenne.test.jdbc.DBHelper;
-import org.apache.cayenne.test.jdbc.TableHelper;
-import org.apache.cayenne.testdo.locking.RelLockingTestEntity;
-import org.apache.cayenne.testdo.locking.SimpleLockingTestEntity;
-import org.apache.cayenne.unit.di.server.ServerCase;
-import org.apache.cayenne.unit.di.server.UseServerRuntime;
-
-@UseServerRuntime(ServerCase.LOCKING_PROJECT)
-public class OptimisticLockingTest extends ServerCase {
-
-    @Inject
-    protected DataContext context;
-
-    @Inject
-    protected DBHelper dbHelper;
-
-    protected TableHelper tSimpleLockingTest;
-    protected TableHelper tRelLockingTest;
-    protected TableHelper tLockingHelper;
-
-    @Override
-    protected void setUpAfterInjection() throws Exception {
-        dbHelper.deleteAll("LOCKING_HELPER");
-        dbHelper.deleteAll("REL_LOCKING_TEST");
-        dbHelper.deleteAll("SIMPLE_LOCKING_TEST");
-
-        tSimpleLockingTest = new TableHelper(dbHelper, "SIMPLE_LOCKING_TEST");
-        tSimpleLockingTest.setColumns("LOCKING_TEST_ID", "NAME", "DESCRIPTION")
-                .setColumnTypes(Types.INTEGER, Types.VARCHAR, Types.VARCHAR);
-
-        tRelLockingTest = new TableHelper(dbHelper, "REL_LOCKING_TEST");
-        tRelLockingTest.setColumns(
-                "REL_LOCKING_TEST_ID",
-                "SIMPLE_LOCKING_TEST_ID",
-                "NAME");
-
-        tLockingHelper = new TableHelper(dbHelper, "LOCKING_HELPER");
-        tLockingHelper.setColumns("LOCKING_HELPER_ID", "REL_LOCKING_TEST_ID", "NAME");
-    }
-
-    protected void createSimpleLockingDataSet() throws Exception {
-        tLockingHelper.delete().execute();
-        tRelLockingTest.delete().execute();
-        tSimpleLockingTest.delete().execute();
-        tSimpleLockingTest.insert(1, "LockTest1", null);
-    }
-
-    protected void createLockingOnNullDataSet() throws Exception {
-        tLockingHelper.delete().execute();
-        tRelLockingTest.delete().execute();
-        tSimpleLockingTest.delete().execute();
-        tSimpleLockingTest.insert(1, null, null);
-    }
-
-    protected void createLockingOnMixedDataSet() throws Exception {
-        tLockingHelper.delete().execute();
-        tRelLockingTest.delete().execute();
-        tSimpleLockingTest.delete().execute();
-        tSimpleLockingTest.insert(1, null, null);
-        tSimpleLockingTest.insert(2, "LockTest2", null);
-        tSimpleLockingTest.insert(3, "LockTest3", "Another Lock Test");
-    }
-
-    protected void createLockingOnToOneDataSet() throws Exception {
-        tLockingHelper.delete().execute();
-        tRelLockingTest.delete().execute();
-        tSimpleLockingTest.delete().execute();
-        tSimpleLockingTest.insert(1, "LockTest1", null);
-        tRelLockingTest.insert(5, 1, "Rel Test 1");
-        tLockingHelper.insert(1, 5, "Locking Helper 1");
-    }
-
-    protected void createSimpleLockUpdate() throws Exception {
-        assertEquals(1, tSimpleLockingTest
-                .update()
-                .set("NAME", "LockTest1Updated")
-                .where("LOCKING_TEST_ID", 1)
-                .execute());
-    }
-
-    protected void createRelLockUpdate() throws Exception {
-        tRelLockingTest.update().set("SIMPLE_LOCKING_TEST_ID", 1).where(
-                "REL_LOCKING_TEST_ID",
-                5).execute();
-    }
-
-    protected void createSimpleLockDelete() throws Exception {
-        tSimpleLockingTest.delete().execute();
-    }
-
-    public void testSuccessSimpleLockingOnDelete() throws Exception {
-        createSimpleLockingDataSet();
-
-        List<?> allObjects = context.performQuery(new SelectQuery(
-                SimpleLockingTestEntity.class));
-        assertEquals(1, allObjects.size());
-
-        SimpleLockingTestEntity object = (SimpleLockingTestEntity) allObjects.get(0);
-
-        // change description and save... no optimistic lock failure expected
-        object.setDescription("first update");
-        context.commitChanges();
-
-        context.deleteObjects(object);
-        context.commitChanges();
-    }
-
-    public void testSuccessSimpleLockingOnDeleteFollowedByInvalidate() throws Exception {
-        createSimpleLockingDataSet();
-
-        List<?> allObjects = context.performQuery(new SelectQuery(
-                SimpleLockingTestEntity.class));
-        assertEquals(1, allObjects.size());
-
-        SimpleLockingTestEntity object = (SimpleLockingTestEntity) 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();
-    }
-
-    public void testSuccessSimpleLockingOnDeleteFollowedByForgetSnapshot()
-            throws Exception {
-        createSimpleLockingDataSet();
-
-        List<?> allObjects = context.performQuery(new SelectQuery(
-                SimpleLockingTestEntity.class));
-        assertEquals(1, allObjects.size());
-
-        SimpleLockingTestEntity object = (SimpleLockingTestEntity) 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();
-    }
-
-    public void testSuccessSimpleLockingOnDeletePrecededByInvalidate() throws Exception {
-        createSimpleLockingDataSet();
-
-        List<?> allObjects = context.performQuery(new SelectQuery(
-                SimpleLockingTestEntity.class));
-        assertEquals(1, allObjects.size());
-
-        SimpleLockingTestEntity object = (SimpleLockingTestEntity) 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();
-    }
-
-    public void testSuccessSimpleLockingOnDeletePrecededByForgetSnapshot()
-            throws Exception {
-        createSimpleLockingDataSet();
-
-        List<?> allObjects = context.performQuery(new SelectQuery(
-                SimpleLockingTestEntity.class));
-        assertEquals(1, allObjects.size());
-
-        SimpleLockingTestEntity object = (SimpleLockingTestEntity) 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();
-    }
-
-    public void testFailSimpleLockingOnDelete() throws Exception {
-        createSimpleLockingDataSet();
-
-        List<?> allObjects = context.performQuery(new SelectQuery(
-                SimpleLockingTestEntity.class));
-        assertEquals(1, allObjects.size());
-
-        SimpleLockingTestEntity object = (SimpleLockingTestEntity) allObjects.get(0);
-
-        // change description and save... no optimistic lock failure expected
-        object.setDescription("second update");
-        context.commitChanges();
-
-        // change row underneath, delete and save... optimistic lock failure expected
-        createSimpleLockUpdate();
-
-        context.deleteObjects(object);
-
-        try {
-            context.commitChanges();
-            fail("Optimistic lock failure expected.");
-        }
-        catch (OptimisticLockException ex) {
-            // optimistic lock failure expected...
-        }
-    }
-
-    public void testSuccessSimpleLockingOnUpdate() throws Exception {
-        createSimpleLockingDataSet();
-
-        List<?> allObjects = context.performQuery(new SelectQuery(
-                SimpleLockingTestEntity.class));
-        assertEquals(1, allObjects.size());
-
-        SimpleLockingTestEntity object = (SimpleLockingTestEntity) allObjects.get(0);
-
-        // change description and save... no optimistic lock failure expected
-        object.setDescription("first update");
-        context.commitChanges();
-
-        object.setDescription("second update");
-
-        context.commitChanges();
-    }
-
-    public void testSuccessSimpleLockingOnUpdateFollowedByInvalidate() throws Exception {
-        createSimpleLockingDataSet();
-
-        List<?> allObjects = context.performQuery(new SelectQuery(
-                SimpleLockingTestEntity.class));
-        assertEquals(1, allObjects.size());
-
-        SimpleLockingTestEntity object = (SimpleLockingTestEntity) 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();
-    }
-
-    public void testSuccessSimpleLockingOnUpdatePrecededByInvalidate() throws Exception {
-        createSimpleLockingDataSet();
-
-        List<?> allObjects = context.performQuery(new SelectQuery(
-                SimpleLockingTestEntity.class));
-        assertEquals(1, allObjects.size());
-
-        SimpleLockingTestEntity object = (SimpleLockingTestEntity) allObjects.get(0);
-
-        // change description and save... no optimistic lock failure expected
-        object.setDescription("first update");
-        context.commitChanges();
-
-        context.invalidateObjects(object);
-        object.setDescription("second update");
-
-        context.commitChanges();
-    }
-
-    public void testSuccessSimpleLockingOnUpdateFollowedByForgetSnapshot()
-            throws Exception {
-        createSimpleLockingDataSet();
-
-        List<?> allObjects = context.performQuery(new SelectQuery(
-                SimpleLockingTestEntity.class));
-        assertEquals(1, allObjects.size());
-
-        SimpleLockingTestEntity object = (SimpleLockingTestEntity) 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();
-    }
-
-    public void testSuccessSimpleLockingOnUpdatePrecededByForgetSnapshot()
-            throws Exception {
-        createSimpleLockingDataSet();
-
-        List<?> allObjects = context.performQuery(new SelectQuery(
-                SimpleLockingTestEntity.class));
-        assertEquals(1, allObjects.size());
-
-        SimpleLockingTestEntity object = (SimpleLockingTestEntity) allObjects.get(0);
-
-        // change description and save... no optimistic lock failure expected
-        object.setDescription("first update");
-        context.commitChanges();
-
-        context.getObjectStore().getDataRowCache().forgetSnapshot(object.getObjectId());
-        object.setDescription("second update");
-
-        context.commitChanges();
-    }
-
-    public void testFailSimpleLocking() throws Exception {
-        createSimpleLockingDataSet();
-
-        List<?> allObjects = context.performQuery(new SelectQuery(
-                SimpleLockingTestEntity.class));
-        assertEquals(1, allObjects.size());
-
-        SimpleLockingTestEntity object = (SimpleLockingTestEntity) 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...
-        }
-    }
-
-    public void testFailLockingOnNull() throws Exception {
-        createLockingOnNullDataSet();
-
-        List<?> allObjects = context.performQuery(new SelectQuery(
-                SimpleLockingTestEntity.class));
-        assertEquals(1, allObjects.size());
-
-        SimpleLockingTestEntity object = (SimpleLockingTestEntity) 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());
-        }
-    }
-
-    public void testSuccessLockingOnMixed() throws Exception {
-        createLockingOnMixedDataSet();
-
-        SelectQuery 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.
-    }
-
-    public void testFailLockingOnToOne() throws Exception {
-        createLockingOnToOneDataSet();
-
-        List<?> allObjects = context.performQuery(new SelectQuery(
-                RelLockingTestEntity.class));
-        assertEquals(1, allObjects.size());
-
-        RelLockingTestEntity object = (RelLockingTestEntity) 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...
-        }
-    }
-
-    public void testFailRetrieveRow() throws Exception {
-        createSimpleLockingDataSet();
-
-        List<?> allObjects = context.performQuery(new SelectQuery(
-                SimpleLockingTestEntity.class));
-        assertEquals(1, allObjects.size());
-
-        SimpleLockingTestEntity object = (SimpleLockingTestEntity) 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"));
-        }
-    }
-
-    public void testFailRetrieveDeletedRow() throws Exception {
-        createSimpleLockingDataSet();
-
-        List<?> allObjects = context.performQuery(new SelectQuery(
-                SimpleLockingTestEntity.class));
-        assertEquals(1, allObjects.size());
-
-        SimpleLockingTestEntity object = (SimpleLockingTestEntity) 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);
-        }
-    }
-}


Mime
View raw message