return DBManager.createConfiguration(false);
}
};
Migration migration = new Migrations().getMigration(workspaceFormat, currentFormat);
if (migration == null) {
throw new PersistenceException("It was not possible to migrate your data to the current version of RSSOwl. Migrations are supported between final versions and between consecutive milestones. In other words, 2.0M7 to 2.0M8 and 2.0 to 2.1 are supported but 2.0M6 to 2.0M8 is not supported. In the latter case, you would need to launch 2.0M7 and then 2.0M8 to be able to use that version. Migration was attempted from originFormat: " + workspaceFormat + " to destinationFormat: " + currentFormat); //$NON-NLS-1$ //$NON-NLS-2$
}
final File dbFile = new File(getDBFilePath());
final String backupFileSuffix = ".mig."; //$NON-NLS-1$
/*
* Copy the db file to a permanent back-up where the file name includes the
* workspaceFormat number. This will only be deleted after another
* migration.
*/
final BackupService backupService = new BackupService(dbFile, backupFileSuffix + workspaceFormat, 1);
backupService.setLayoutStrategy(new BackupService.BackupLayoutStrategy() {
public List<File> findBackupFiles() {
List<File> backupFiles = new ArrayList<File>(3);
for (int i = workspaceFormat; i >= 0; --i) {
File file = new File(dbFile.getAbsoluteFile() + backupFileSuffix + i);
if (file.exists())
backupFiles.add(file);
}
return backupFiles;
}
public void rotateBackups(List<File> backupFiles) {
throw new UnsupportedOperationException("No rotation supported because maxBackupCount is 1"); //$NON-NLS-1$
}
});
backupService.backup(true, new NullProgressMonitor());
/* Create a copy of the db file to use for the migration */
File migDbFile = backupService.getTempBackupFile();
DBHelper.copyFileNIO(dbFile, migDbFile);
/* Migrate the copy */
MigrationResult migrationResult = migration.migrate(configFactory, migDbFile.getAbsolutePath(), progressMonitor);
File dbFormatFile = getDBFormatFile();
File migFormatFile = new File(dbFormatFile.getAbsolutePath() + ".mig.temp"); //$NON-NLS-1$
try {
if (!migFormatFile.exists()) {
migFormatFile.createNewFile();
}
if (!dbFormatFile.exists()) {
dbFormatFile.createNewFile();
}
} catch (IOException ioe) {
throw new PersistenceException("Failed to migrate data", ioe); //$NON-NLS-1$
}
setFormatVersion(migFormatFile);
DBHelper.rename(migFormatFile, dbFormatFile);