}
final String TBL = "ISTAT_DISPOSABLE_STATS";
String updateStatsSQL = "call syscs_util.syscs_update_statistics(" +
"'APP', ?, null)";
DisposableIndexStatistics dis = new DisposableIndexStatistics(
getOldVersion(), getConnection(), TBL);
switch (getPhase()) {
// create with old version
case PH_CREATE:
{
dis.createAndPopulateTables();
// The expected number of statistics entries depends on the
// version of Derby used to create the database. Some older
// versions of Derby contained a bug and lacked optimizations,
// causing the number of statistics entries to increase.
// Just after creation and before any update statistics expect
// all stats to exist.
dis.assertStatsCount(false, false);
break;
}
// boot with new version and soft-upgrade
case PH_SOFT_UPGRADE:
{
PreparedStatement ps = prepareStatement(updateStatsSQL);
String[] tables = dis.getTableNames();
// Update statistics on all relevant tables.
for (int i=0; i < tables.length; i++) {
ps.setString(1, tables[i]);
ps.executeUpdate();
}
// After soft upgrade and update statistics expect the
// orphaned index entry to be deleted, but the "unneeded
// disposable entries" are only deleted after hard upgrade.
dis.assertStatsCount(true, false);
break;
}
// soft-downgrade: boot with old version after soft-upgrade
case PH_POST_SOFT_UPGRADE:
{
// expect no change in entries on downgrade, should be same
// as they were in soft upgrade.
dis.assertStatsCount(true, false);
break;
}
// boot with new version and hard-upgrade
case PH_HARD_UPGRADE:
{
// expect no change in entries on upgrade before update
// statistics.
dis.assertStatsCount(true, false);
PreparedStatement ps = prepareStatement(updateStatsSQL);
String[] tables = dis.getTableNames();
for (int i=0; i < tables.length; i++) {
ps.setString(1, tables[i]);
ps.executeUpdate();
}
// Confirm that we disposed of the statistics that were added
// due to a bug or simply not needed by Derby.
try {
dis.assertStatsCount(true, true);
} finally {
for (int i=0; i < tables.length; i++) {
dropTable(tables[i]);
}
}