2057
2061
// MessageDialog.openInformation(null, "", systemInfo.freespaceSize()
2058
2062
// + ", " + systemInfo.totalSize() + "; "
2059
2063
// + systemInfo.freespaceEntryCount());
2061
if (force || needsDefragmentation()) {
2062
Meta meta1 = getMeta(false);
2063
boolean hasBackups = meta1 == null
2064
|| meta1.getBackupLocation() != null
2065
&& meta1.getBackupLocation().length() > 0;
2071
Messages.DbManager_Catalog_maintenance,
2072
Messages.DbManager_The_cat_seems_to_be_fragmented,
2074
final String backupPath = fileName + ".defrag"; //$NON-NLS-1$
2075
ProgressMonitorDialog dialog = new ProgressMonitorDialog(
2078
dialog.run(true, false, new IRunnableWithProgress() {
2080
public void run(IProgressMonitor monitor)
2081
throws InvocationTargetException,
2082
InterruptedException {
2084
monitor.beginTask(NLS.bind(
2085
Messages.DbManager_Defragmenting_,
2086
fileName), IProgressMonitor.UNKNOWN);
2088
monitor.subTask(Messages.DbManager_backing_up_cat);
2089
performBackup(0L, -1L, true);
2093
monitor.subTask(Messages.DbManager_defragmenting_cat);
2095
DefragmentConfig config = new DefragmentConfig(
2096
fileName, backupPath);
2097
config.objectCommitFrequency(1000);
2098
config.forceBackupDelete(true);
2099
boolean fileNeedsUpgrade = config
2100
.fileNeedsUpgrade();
2101
EmbeddedConfiguration ef = createDatabaseConfiguration(
2102
fileNeedsUpgrade, fileName);
2103
config.db4oConfig(ef);
2105
Defragment.defrag(config);
2106
} catch (Exception e) {
2107
File target = new File(fileName);
2109
new File(backupPath).renameTo(target);
2110
throw new InvocationTargetException(e);
2112
if (fileNeedsUpgrade) {
2113
monitor.subTask(Messages.DbManager_updating_database_version);
2115
.openFile(ef, fileName);
2066
if (force || needsDefragmentation()) {
2067
Meta meta1 = getMeta(false);
2068
boolean hasBackups = meta1 == null
2069
|| meta1.getBackupLocation() != null
2070
&& meta1.getBackupLocation().length() > 0;
2076
Messages.DbManager_Catalog_maintenance,
2077
Messages.DbManager_The_cat_seems_to_be_fragmented,
2079
final String backupPath = fileName + ".defrag"; //$NON-NLS-1$
2080
ProgressMonitorDialog dialog = new ProgressMonitorDialog(
2083
dialog.run(true, false,
2084
new IRunnableWithProgress() {
2086
public void run(IProgressMonitor monitor)
2087
throws InvocationTargetException,
2088
InterruptedException {
2122
Messages.DbManager_database_converted_to_version_n,
2127
db = createDatabase(fileName);
2092
Messages.DbManager_Defragmenting_,
2094
IProgressMonitor.UNKNOWN);
2096
monitor.subTask(Messages.DbManager_backing_up_cat);
2097
performBackup(0L, -1L, true);
2101
monitor.subTask(Messages.DbManager_defragmenting_cat);
2103
DefragmentConfig config = new DefragmentConfig(
2104
fileName, backupPath);
2105
config.objectCommitFrequency(1000);
2106
config.forceBackupDelete(true);
2107
boolean fileNeedsUpgrade = config
2108
.fileNeedsUpgrade();
2109
EmbeddedConfiguration ef = createDatabaseConfiguration(
2112
config.db4oConfig(ef);
2114
Defragment.defrag(config);
2115
} catch (Exception e) {
2116
File target = new File(
2119
new File(backupPath)
2121
throw new InvocationTargetException(
2124
if (fileNeedsUpgrade) {
2125
monitor.subTask(Messages.DbManager_updating_database_version);
2126
db = Db4oEmbedded.openFile(
2134
Messages.DbManager_database_converted_to_version_n,
2139
db = createDatabase(fileName);
2143
} catch (InvocationTargetException e1) {
2144
factory.getErrorHandler().showError(
2145
Messages.DbManager_Defrag_error,
2146
NLS.bind(Messages.DbManager_Defrag_failed,
2147
e1.getCause()), this);
2148
} catch (InterruptedException e1) {
2149
// should never happen
2151
File backup = new File(backupPath);
2152
if (!file.exists()) {
2153
if (backup.exists())
2154
backup.renameTo(file);
2158
Messages.DbManager_defragmentation_failed,
2165
Messages.DbManager_defragmentation_successfiul);
2131
} catch (InvocationTargetException e1) {
2132
factory.getErrorHandler().showError(
2133
Messages.DbManager_Defrag_error,
2134
NLS.bind(Messages.DbManager_Defrag_failed,
2135
e1.getCause()), this);
2136
} catch (InterruptedException e1) {
2137
// should never happen
2139
File backup = new File(backupPath);
2140
if (!file.exists()) {
2141
if (backup.exists())
2142
backup.renameTo(file);
2143
DbActivator.getDefault().logError(
2144
Messages.DbManager_defragmentation_failed,
2151
Messages.DbManager_defragmentation_successfiul);
2170
} catch (Throwable e) {
2171
DbActivator.getDefault().logError(
2172
Messages.DbManager_error_checking_sanity, e);
2156
} catch (Throwable e) {
2157
DbActivator.getDefault().logError(
2158
Messages.DbManager_error_checking_sanity, e);
2162
2176
public boolean needsDefragmentation() {
2355
2371
monitor.worked(1);
2356
2372
if (db != null) {
2357
2373
while (!sorted.isEmpty()) {
2358
String[] todo = sorted
2359
.toArray(new String[sorted.size()]);
2360
for (String id : todo) {
2361
if (id.startsWith(IDbManager.IMPORTKEY)) {
2374
String id = sorted.poll();
2376
if (id.startsWith(IDbManager.IMPORTKEY))
2378
SmartCollectionImpl sm = obtainById(
2379
SmartCollectionImpl.class, id);
2380
if (sm == null || pruneSystemCollection(sm))
2382
Iterator<String> it = sorted.iterator();
2383
while (it.hasNext()) {
2384
String next = it.next();
2385
if (id.startsWith(next)) {
2363
2387
monitor.worked(1);
2366
SmartCollectionImpl sm = obtainById(
2367
SmartCollectionImpl.class, id);
2369
if (pruneSystemCollection(sm)) {
2373
Iterator<String> it = sorted.iterator();
2374
while (it.hasNext()) {
2375
String cand = it.next();
2376
if (id.startsWith(cand)) {
2384
} else if (sorted.remove(id))
2388
2391
importIds.remove(Constants.LAST_IMPORT_ID);