/// <exception cref="System.IO.IOException"></exception>
        internal static LocalObjectContainer FreshTargetFile(DefragmentConfig config)
        {
            config.Db4oConfig().Storage.Delete(config.OrigPath());
            IConfiguration clonedDb4oConfig = config.ClonedDb4oConfig();

            clonedDb4oConfig.ReadOnly(false);
            return((LocalObjectContainer)Db4oFactory.OpenFile(clonedDb4oConfig, config.OrigPath
                                                                  ()));
        }
Beispiel #2
0
        /// <exception cref="System.IO.IOException"></exception>
        private static void MoveToBackup(DefragmentConfig config)
        {
            IStorage origStorage = config.Db4oConfig().Storage;

            if (origStorage == config.BackupStorage())
            {
                origStorage.Rename(config.OrigPath(), config.BackupPath());
                return;
            }
            CopyBin(origStorage, config.BackupStorage(), config.OrigPath(), config.BackupPath
                        ());
            origStorage.Delete(config.OrigPath());
        }
Beispiel #3
0
        /// <summary>
        /// Renames the file at the configured original path to the configured backup
        /// path and then builds a defragmented version of the file in the original
        /// place.
        /// </summary>
        /// <remarks>
        /// Renames the file at the configured original path to the configured backup
        /// path and then builds a defragmented version of the file in the original
        /// place.
        /// </remarks>
        /// <param name="config">The configuration for this defragmentation run.</param>
        /// <param name="listener">
        /// A listener for status notifications during the defragmentation
        /// process.
        /// </param>
        /// <exception cref="System.IO.IOException">if the original file cannot be moved to the backup location
        ///     </exception>
        public static void Defrag(DefragmentConfig config, IDefragmentListener listener)
        {
            IStorage storage = config.Db4oConfig().Storage;

            EnsureFileExists(storage, config.OrigPath());
            IStorage backupStorage = config.BackupStorage();

            if (backupStorage.Exists(config.BackupPath()))
            {
                if (!config.ForceBackupDelete())
                {
                    throw new IOException("Could not use '" + config.BackupPath() + "' as backup path - file exists."
                                          );
                }
            }
            // Always delete, because !exists can indicate length == 0
            backupStorage.Delete(config.BackupPath());
            MoveToBackup(config);
            if (config.FileNeedsUpgrade())
            {
                UpgradeFile(config);
            }
            DefragmentServicesImpl services = new DefragmentServicesImpl(config, listener);

            try
            {
                FirstPass(services, config);
                services.CommitIds();
                SecondPass(services, config);
                services.CommitIds();
                DefragUnindexed(services);
                services.CommitIds();
                services.DefragIdToTimestampBtree();
                services.ReplaceClassMetadataRepository();
            }
            catch (CorruptionException exc)
            {
                Sharpen.Runtime.PrintStackTrace(exc);
            }
            finally
            {
                services.Close();
            }
        }
		/// <exception cref="System.IO.IOException"></exception>
		internal static LocalObjectContainer FreshTargetFile(DefragmentConfig config)
		{
			config.Db4oConfig().Storage.Delete(config.OrigPath());
			return (LocalObjectContainer)Db4oFactory.OpenFile(config.ClonedDb4oConfig(), config
				.OrigPath());
		}
Beispiel #5
0
 /// <exception cref="System.IO.IOException"></exception>
 internal static LocalObjectContainer FreshTargetFile(DefragmentConfig config)
 {
     config.Db4oConfig().Storage.Delete(config.OrigPath());
     return((LocalObjectContainer)Db4oFactory.OpenFile(config.ClonedDb4oConfig(), config
                                                       .OrigPath()));
 }
		/// <exception cref="System.IO.IOException"></exception>
		private static void MoveToBackup(DefragmentConfig config)
		{
			IStorage origStorage = config.Db4oConfig().Storage;
			if (origStorage == config.BackupStorage())
			{
				origStorage.Rename(config.OrigPath(), config.BackupPath());
				return;
			}
			CopyBin(origStorage, config.BackupStorage(), config.OrigPath(), config.BackupPath
				());
			origStorage.Delete(config.OrigPath());
		}
		/// <summary>
		/// Renames the file at the configured original path to the configured backup
		/// path and then builds a defragmented version of the file in the original
		/// place.
		/// </summary>
		/// <remarks>
		/// Renames the file at the configured original path to the configured backup
		/// path and then builds a defragmented version of the file in the original
		/// place.
		/// </remarks>
		/// <param name="config">The configuration for this defragmentation run.</param>
		/// <param name="listener">
		/// A listener for status notifications during the defragmentation
		/// process.
		/// </param>
		/// <exception cref="System.IO.IOException">if the original file cannot be moved to the backup location
		/// 	</exception>
		public static void Defrag(DefragmentConfig config, IDefragmentListener listener)
		{
			IStorage storage = config.Db4oConfig().Storage;
			EnsureFileExists(storage, config.OrigPath());
			IStorage backupStorage = config.BackupStorage();
			if (backupStorage.Exists(config.BackupPath()))
			{
				if (!config.ForceBackupDelete())
				{
					throw new IOException("Could not use '" + config.BackupPath() + "' as backup path - file exists."
						);
				}
			}
			// Always delete, because !exists can indicate length == 0
			backupStorage.Delete(config.BackupPath());
			MoveToBackup(config);
			if (config.FileNeedsUpgrade())
			{
				UpgradeFile(config);
			}
			DefragmentServicesImpl services = new DefragmentServicesImpl(config, listener);
			try
			{
				FirstPass(services, config);
				services.CommitIds();
				SecondPass(services, config);
				services.CommitIds();
				DefragUnindexed(services);
				services.CommitIds();
				services.DefragIdToTimestampBtree();
				services.ReplaceClassMetadataRepository();
			}
			catch (CorruptionException exc)
			{
				Sharpen.Runtime.PrintStackTrace(exc);
			}
			finally
			{
				services.Close();
			}
		}
		/// <exception cref="System.IO.IOException"></exception>
		internal static LocalObjectContainer FreshTargetFile(DefragmentConfig config)
		{
			config.Db4oConfig().Storage.Delete(config.OrigPath());
			IConfiguration clonedDb4oConfig = config.ClonedDb4oConfig();
			clonedDb4oConfig.ReadOnly(false);
			return (LocalObjectContainer)Db4oFactory.OpenFile(clonedDb4oConfig, config.OrigPath
				());
		}