To create or open a persistent database, the application first specifies the
Database.Mode.DiskSupportflag in themodeargument passed to the Database constructor.Whereas an in-memory database application needs only a single memory device, persistent database applications must define at least 4 memory devices. These are defined in an array that is passed to the Database method
Open().Also at least the following two properties are specified in the Database.Parameters that are passed to the
Open()method:
DiskPageSize- It is recommended to set this to the blocking factor of the persistent media
DiskClassesByDefault- Marks all classes with attribute [Persistent] to be stored on persistent media (Disk-based classes can also be defined explicitly with the attribute[Persistent(Disk=true)])Parameter Settings
Please refer to the general guidelines discussed in the Creating Databases page for determining the proper values for
MemPageSize,DiskPageSize,MaxConnections,MaxDiskDatabaseSizeandLogType.Log Type and Transaction Commit Policy
Applications set the
DatabaseParameters.LogTypetoRedoLog, UndoLogorNoLogfor the Database methodOpen().Depending on the log type selected, the additional Database.Parameters propertyRedoLogLimitorDelayedCommitThresholdcan be set. (Please see the Persistent Database I/O page for detailed explanations.)Note that if the
NoLoglog type is selected, the application can explicitly force the cache to be flushed to the media with the Connection methodDiskFlush().
Database Creation Example
Typical application code to create a persistent database could look like the following:
[Persistent] class Obj { public int i4; }; ... const int PAGE_SIZE = 128; const int DISK_PAGE_SIZE = 4096; const int DISK_CACHE_SIZE = 8*1024*1024; const int DATABASE_SIZE = 16*1024*1024; Database.Mode mode = Database.Mode.DiskSupport; Database.Parameters parameters = new Database.Parameters(); devs = new Database.Device[4]; Database db = new Database(mode); parameters.MemPageSize = PAGE_SIZE; parameters.Classes = new Type[] { typeof(Obj) }; parameters.MaxConnections = 10; parameters.DiskPageSize = DISK_PAGE_SIZE; parameters.DiskClassesByDefault = true; parameters.LogType = Database.LogType.NoLog; devs[0] = new Database.PrivateMemoryDevice(Database.Device.Kind.Data, DATABASE_SIZE); devs[1] = new Database.PrivateMemoryDevice(Database.Device.Kind.DiskCache, DISK_CACHE_SIZE); devs[2] = new Database.FileDevice(Database.Device.Kind.Data, "opendb.dbs"); devs[3] = new Database.FileDevice(Database.Device.Kind.TransactionLog, "opendb.log"); db.Open("opendb", parameters, devs); // Do database processing db.Close();