Android Hello Two Dbs v2
Version 2 project is in folder hello-two-dbs-v2 under parent example.

Note that are downgrade scripts in the v1 folder for changing the database version from 2 to 1.
The use of the word "upgrade" in the downgrade script name may be confusing, but it is expected that downgrading
will only be used in testing.
You can run through an upgrade on an actual device or emulator by installing and running AndroidHelloTwoDbs v1 followed by v2.
Hello Two Dbs Upgrade Script
Android Hello Two Dbs version two differs from version one by the addition of a new "quote" column to both the Simple and Complex Entity tables.
The main problem is that if database version 1 already exists, then it's schema will need to be upgraded before you can even begin to use ORMLite. Otherwise you will get errors
about a missing "quote" column. Here is an SQL statement which makes the required adjustment for the Simple database:
ALTER TABLE `Simple` ADD COLUMN `quote` VARCHAR DEFAULT ``;
Classy Data allows such an SQL script to run in an onUpgrade event. For convenience, there is a naming convention for upgrade script files, but a custom format is also possible.
The default format, using "{n}" parmaeters, is "{2}-upgrade-v{0}-v{1}.sql", where {0} is the old version number, {1} the new version number and {2} the Persistence Unit name.
eg. for PU "simple" upgrade from v1 to v2: "simple-upgrade-v1-v2.sql".
Hello Two Dbs OpenHelperCallbacks
Custom implementations of the OpenHelperCallbacks interface are provided to replace the empty quotes of each appended column with real quotes using JPA.
Here is an example from the SimpleOpenHelperCallbacks class of a task to set the quotes:
public void doTask(EntityManagerLite entityManager)
{
Query query = entityManager.createNamedQuery(ALL_SIMPLE_DATA);
List<SimpleData> list = (List<SimpleData>) query.getResultList();
for (SimpleData simple : list)
{
simple.setQuote(QuoteSource.getQuote());
entityManager.merge(simple);
}
}
A persistence unit configuration may contain an open-helper-callbacks-classname property for custom handling of onCreate and onUpgrade events.
Here is the simple v2 persistence unit configuration as an example:
<persistence-unit name="simple">
<class>au.com.cybersearch2.example.v2.SimpleData</class>
<property name="database-name" value="helloTwoDb1.db"/>
<property name="database-version" value="2"/>
<property name="open-helper-callbacks-classname" value="au.com.cybersearch2.example.v2.SimpleOpenHelperCallbacks"/>
</persistence-unit>