Class 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.
    • 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 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
    • Constructor Detail

      • OptimisticLockingTest

        public OptimisticLockingTest()
    • 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.