Opening Persistent Databases with the Java API

As explained for In-Memory Databases, before performing data storage and retrieval operations, we must open and connect to the database. To open the database Java applications call Database method open() with a number of possible parameters including a Database.Parameters object and an array of Database. Device objects. This is demonstrated in SDK sample samples/java/open/Open.

To specify that the database classes are stored on persistent media, the class is declares with the annotation @Persistent(disk=true. And the Database constructor must be called with DiskSupport enabled. For example:

 
    @Persistent(disk=true)
            
    class Employee
    {
        ...
    }
    ...
        Database.Mode mode = Database.MCO_CFG_DISK_SUPPORT;
        Database db = new Database(mode);
     

Defining Storage Devices

eXtremeDB uses the notion of logical devices to describe storage locations. Whereas for an all-in-memory database, there can be a single device to describe the conventional (aka local or in-process) or shared memory for the database, for persistent databases, or hybrid databases (which contain both transient and persistent classes), a minimum of four devices must be defined. For example:

 
    static final int  DATABASE_SIZE =       (600 * 1024 * 10);
    static final int  DISK_CACHE_SIZE =          (300 * 1024 * 10);
     
    Database.Device devs[] = new Database.Device[4];
 
    /* Configure first memory device as a plain conventional memory region */
    devs[0] = new Database.PrivateMemoryDevice(Database.Device.Kind.Data, DATABASE_SIZE);
     
    /* Configure conventional memory region for cache */
    devs[1] = new Database.PrivateMemoryDevice(Database.Device.Kind.DiskCache, DISK_CACHE_SIZE);
     
    /* Configure FILE memory device for main database storage */
    devs[2] = new Database.FileDevice(Database.Device.Kind.Data, "opendb.dbs");
     
    /* Configure FILE memory device for transaction log */
    devs[3] = new Database.FileDevice(Database.Device.Kind.TransactionLog, "opendb.log");
     

Database Parameters

The database open parameters are defined in class Database.Parameters. The parameters are initialized to default values in the constructor, then the following application-specific parameters are assigned:

 
    #define  MEMORY_PAGE_SIZE     128
    #define  PSTORAGE_PAGE_SIZE   4096
     
    Database.Parameters params = new Database.Parameters();
     
    /* Initialize and customize the database parameters */
    params.memPageSize =  MEMORY_PAGE_SIZE;
    params.classes = new Class[] { OpenObj.class }; // List of classes which will be stored in eXtremeDB database. 
    params.maxConnections = 10;
    params.diskPageSize = PSTORAGE_PAGE_SIZE;
    params.diskClassesByDefault = true; // Mark @Persistent classes as on-disk classes by default
     

Database Operations

Once the persistent database devices and parameters are specified, the database open method open(), the Connection class and all other APIs to perform database operations are identical to those for In-Memory databases. Please refer to SDK sample samples/java/open/Open for further implementation details.