/* Create Configuration and check for Migration */
Configuration config = createConfiguration(false);
int workspaceVersion = getWorkspaceFormatVersion();
MigrationResult migrationResult = new MigrationResult(false, false, false);
SubMonitor subMonitor = null;
try {
/* Log previously failing Online Backup */
try {
if (getOnlineBackupMarkerFile().exists()) {
Activator.safeLogInfo("Detected an Online Backup that did not complete"); //$NON-NLS-1$
safeDelete(getOnlineBackupMarkerFile());
}
} catch (Exception e) {
/* Ignore */
}
/* Log previously failing Reindexing */
try {
if (getReindexMarkerFile().exists()) {
Activator.safeLogInfo("Detected a Search Re-Indexing that did not complete"); //$NON-NLS-1$
safeDelete(getReindexMarkerFile());
}
} catch (Exception e) {
/* Ignore */
}
/* Perform Migration if necessary */
if (workspaceVersion != getCurrentFormatVersion()) {
progressMonitor.beginLongOperation(false);
subMonitor = SubMonitor.convert(progressMonitor, Messages.DBManager_RSSOWL_MIGRATION, 100);
//TODO Have a better way to allocate the ticks to the child. We need
//to be able to do it dynamically based on whether a reindex is required or not.
migrationResult = migrate(workspaceVersion, getCurrentFormatVersion(), subMonitor.newChild(70));
}
/* Perform Defrag if necessary */
if (!defragmentIfNecessary(progressMonitor, subMonitor)) {
/* Defragment */
if (migrationResult.isDefragmentDatabase())
defragment(progressMonitor, subMonitor);
/*
* We only run the time-based back-up if a defragment has not taken
* place because we always back-up during defragment.
*/
else
scheduledBackup(progressMonitor);
}
/* Open the DB */
startupStatus = createObjectContainer(config);
/* Notify Listeners that DB is opened */
if (startupStatus.isOK())
fireDatabaseEvent(new DatabaseEvent(fObjectContainer, fLock), true);
/* Re-Index Search Index if necessary */
boolean shouldReindex = shouldReindex(migrationResult, startupStatus);
if (subMonitor == null && shouldReindex) {
progressMonitor.beginLongOperation(false);
subMonitor = SubMonitor.convert(progressMonitor, Messages.DBManager_PROGRESS_WAIT, 20);
}
IModelSearch modelSearch = InternalOwl.getDefault().getPersistenceService().getModelSearch();
if (!progressMonitor.isCanceled() && (shouldReindex || migrationResult.isOptimizeIndex())) {
modelSearch.startup();
if (shouldReindex && !progressMonitor.isCanceled()) {
Activator.safeLogInfo("Start: Search Re-Indexing"); //$NON-NLS-1$
File marker = getReindexMarkerFile();
try {
/* Create Marker that Reindexing is Performed */
if (!marker.exists())
safeCreate(marker);
/* Reindex Search Index */
modelSearch.reindexAll(subMonitor != null ? subMonitor.newChild(20) : new NullProgressMonitor());
} finally {
safeDelete(marker);
}
if (progressMonitor.isCanceled())