Package ejava.examples.txhotel.jpa
Class OptimisticLockingTest
- java.lang.Object
-
- junit.framework.Assert
-
- junit.framework.TestCase
-
- ejava.examples.txhotel.jpa.DAOTestBase
-
- ejava.examples.txhotel.jpa.OptimisticLockingTest
-
- All Implemented Interfaces:
junit.framework.Test
public class OptimisticLockingTest extends DAOTestBase
This class provides a demonstration of Optimistic Locking as implemented by javax.peristence. Both Person and Reservation have a version field; only Reservation.version is known to the provider as an official version field. You'll note below that the provider stops us from updating an object in the database with a detached object that contains a version different from what is in the database.
-
-
Field Summary
-
Fields inherited from class ejava.examples.txhotel.jpa.DAOTestBase
em, log, reservationDAO
-
-
Constructor Summary
Constructors Constructor Description OptimisticLockingTest()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
testChangeNoVersion()
Person has a version field, but it is not registered with the provider.void
testChangeWithVersion()
Reservation's version field is registered with the provider.-
Methods inherited from class ejava.examples.txhotel.jpa.DAOTestBase
cleanup, populate, setUp, tearDown
-
Methods inherited from class junit.framework.TestCase
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, runTest, setName, toString
-
-
-
-
Method Detail
-
testChangeNoVersion
public void testChangeNoVersion()
Person has a version field, but it is not registered with the provider. Last one to make a change always wins.
-
testChangeWithVersion
public void testChangeWithVersion()
Reservation's version field is registered with the provider. Only detached objects with the matching version number can make an update. All others will fail.
-
-