/// <exception cref="System.IO.IOException"></exception> public DefragmentServicesImpl(DefragmentConfig defragConfig, IDefragmentListener listener) { _listener = listener; var originalConfig = (Config4Impl) defragConfig.Db4oConfig(); var storage = defragConfig.BackupStorage(); if (defragConfig.ReadOnly()) { storage = new NonFlushingStorage(storage); } var sourceConfig = PrepareConfig(originalConfig, storage, defragConfig.ReadOnly ()); _sourceDb = (LocalObjectContainer) Db4oFactory.OpenFile(sourceConfig, defragConfig .TempPath()).Ext(); _sourceDb.ShowInternalClasses(true); defragConfig.Db4oConfig().BlockSize(_sourceDb.BlockSize()); if (!originalConfig.GenerateCommitTimestamps().DefiniteNo()) { defragConfig.Db4oConfig().GenerateCommitTimestamps(_sourceDb.Config().GenerateCommitTimestamps ().DefiniteYes()); } _targetDb = FreshTargetFile(defragConfig); _mapping = defragConfig.Mapping(); _mapping.Open(); _defragConfig = defragConfig; }
public static void NonFlushingStorage() { // #example: Using the non-flushing storage IEmbeddedConfiguration configuration = Db4oEmbedded.NewConfiguration(); IStorage fileStorage = new FileStorage(); // the non-flushing storage improves performance, but risks database corruption. IStorage cachingStorage = new NonFlushingStorage(fileStorage); configuration.File.Storage = cachingStorage; IObjectContainer container = Db4oEmbedded.OpenFile(configuration, "database.db4o"); // #end example }
public virtual void Test() { MockBin mock = new MockBin(); BinConfiguration binConfig = new BinConfiguration("uri", true, 42L, false); IBin storage = new NonFlushingStorage(new _IStorage_19(mock)).Open(binConfig); byte[] buffer = new byte[5]; storage.Read(1, buffer, 4); storage.Write(2, buffer, 3); mock.ReturnValueForNextCall(42); Assert.AreEqual(42, mock.Length()); storage.Sync(); storage.Close(); mock.Verify(new MethodCall[] { new MethodCall("open", new object[] { binConfig }) , new MethodCall("read", new object[] { 1L, buffer, 4 }), new MethodCall("write" , new object[] { 2L, buffer, 3 }), new MethodCall("length", new object[] { }), new MethodCall("close", new object[] { }) }); }