return DBManager.this.createConfiguration();
}
};
Migration migration = new Migrations().getMigration(workspaceFormat, currentFormat);
if (migration == null) {
throw new PersistenceException("No migration found for originFormat: " + workspaceFormat + ", and destinationFormat: " + currentFormat);
}
/* Create a copy of the db file to use for the migration */
File dbFile = new File(getDBFilePath());
String migDbFileName = getDBFilePath() + ".mig";
File migDbFile = new File(migDbFileName);
copyFile(dbFile, migDbFile);
/* Migrate the copy */
boolean reindexRequired = migration.migrate(configFactory, migDbFileName, progressMonitor);
/*
* Copy the db file to a permanent back where the file name includes the
* workspaceFormat number.
*/
File backupDbFile = new File(getDBFilePath() + ".bak." + workspaceFormat);
copyFile(dbFile, backupDbFile);
File dbFormatFile = getDBFormatFile();
File migFormatFile = new File(dbFormatFile.getAbsolutePath() + ".mig");
try {
if (!migFormatFile.exists()) {
migFormatFile.createNewFile();
}
if (!dbFormatFile.exists()) {
dbFormatFile.createNewFile();
}
} catch (IOException ioe) {
throw new PersistenceException("Error creating database", ioe); //$NON-NLS-1$
}
setFormatVersion(migFormatFile);
/* If rename fails, fall-back to delete and rename */
if (!migFormatFile.renameTo(dbFormatFile)) {
dbFormatFile.delete();
if (!migFormatFile.renameTo(dbFormatFile)) {
throw new PersistenceException("Failed to migrate data.");
}
}
/* Finally, rename the actual db file */
/* If rename fails, fall-back to delete and rename */
if (!migDbFile.renameTo(dbFile)) {
dbFile.delete();
if (!migDbFile.renameTo(dbFile)) {
throw new PersistenceException("Failed to migrate data.");
}
}
return reindexRequired;
}