People and Pets V2
People and Pets V2 adds a "quote" field to both sample entity classes PetData and PeopleData. The application's database file is also used by version 1, so if will need to be updated if version 1 has run previously. The update occurs automatically the first time version 2 starts.
Jpalite people-and-pets-example Java project version 2 application is launched from PeopleAndPetsMain in package au.com.cybersearch2.pp.v2. Associated resources are in "src/main/resources/v2" project folder.
Persistence Unit Configuration
The persistence units of version 2 differ from those of version 1 in three ways
- The "databaseVersion" setting is updated to "2"
- A new ""upgradeFilename" setting is added
- A new "openHelperClass" setting is added
The upgrade file adds the quote column and updates the database version to 2. The open helper adds 2 records after the database is created and add quotes to the existing records when updated to version 2.
Run Version 2
Run PeopleAndPetsMain as a Java application, and you will see console output starting with info and warning level log messages from database set up operations and then a play back of an application activity recorder. The application performs various actions involving records of both persistence units to simulate typical record create, read and delete operations. Note that new database records include a quote. For example
[1] = Buffy: id=2: "All that glisters is not gold"
Test class PP_UpdateTest runs the Version 1 application, and then runs Version 2 twice, once to automatically upgrade the database to Version 2, the second time to test the upgrade persisted successfully. You will see on the console that the version 1 records are updated to include a quote when the database update to version 2 occurs.