private bool CreateDbConnection() { try { if (_db != null) { _db.Close(); _db.Dispose(); System.IO.File.Delete(_databaseName); } _dbConfig = Db4oEmbedded.NewConfiguration(); _dbConfig.Common.ObjectClass(typeof(TrackData)).ObjectField("_id").Indexed(true); _dbConfig.Common.ActivationDepth = 3; // To increase performance _dbConfig.Common.ObjectClass(typeof(TrackData)).CascadeOnUpdate(true); IStorage fileStorage = new FileStorage(); IStorage cachingStorage = new CachingStorage(fileStorage, 128, 2048); _dbConfig.File.Storage = cachingStorage; _db = Db4oEmbedded.OpenFile(_dbConfig, _databaseName); return(true); } catch (Exception ex) { ServiceScope.Get <ILogger>().GetLogger.Error("Error creating DB Connection. Database Mode disabled. {0}", ex.Message); } return(false); }
public static void CachingStorage() { // #example: Using a caching storage IEmbeddedConfiguration configuration = Db4oEmbedded.NewConfiguration(); IStorage fileStorage = new FileStorage(); IStorage cachingStorage = new CachingStorage(fileStorage, 128, 1024); configuration.File.Storage = cachingStorage; IObjectContainer container = Db4oEmbedded.OpenFile(configuration, "database.db4o"); // #end example }
public static void StorageStack() { IEmbeddedConfiguration configuration = Db4oEmbedded.NewConfiguration(); // #example: You stack up different storage-decorator to add functionality // the basic file storage IStorage fileStorage = new FileStorage(); // add your own decorator IStorage myStorageDecorator = new MyStorageDecorator(fileStorage); // add caching to the storage IStorage storageWithCaching = new CachingStorage(myStorageDecorator); // finally configure db4o with our storage-stack configuration.File.Storage = storageWithCaching; // #end example IObjectContainer container = Db4oEmbedded.OpenFile(configuration, "database.db4o"); }