Step 2: Opening Databases

SDK sample samples/java/open/Open illustrates how to open a simple In-Memory database. The sample also demonstrates how to display runtime information by calling the Database method getRunTimeInfo(). Please build and run the sample application and examine the source code. Note that the integer variable config is set according to command line arguments:

 
    int config;
     
    // Get config parameters from the command line
    for (String s : args) 
    {
        if ("disk".equals(s))  config |= Database.MCO_CFG_DISK_SUPPORT;
        if ("shm".equals(s))   config |= Database.MCO_CFG_SHARED_MEMORY;
        if ("debug".equals(s)) config |= Database.MCO_CFG_DEBUG_LIBRARY;
        if ("mvcc".equals(s))  config |= Database.MCO_CFG_MVCC_TRANSACTION_MANAGER;
        if (s.startsWith("license:")) params.license_key = s.substring(8);
    }
     

Then config is used in the Database class constructor. This loads the appropriate runtime libraries dynamically. Once instantiated, the method getRunTimeInfo() is called to obtain information about the currently loaded runtime libraries:

 
    Database db;
     
    db = new Database(config);
    Database.RuntimeInfo ri = db.getRunTimeInfo();
     

Database memory devices and parameters are initialized and passed to the Database method open():

 
    Database.Device devs[];
    Database.Parameters params = new Database.Parameters();
     
    ...
    params.memPageSize = PAGE_SIZE; // Memory page size
    params.classes = new Class[] { OpenObj.class }; // List of classes which will be stored in eXtremeDB database.
    params.maxConnections = 10;
    ...
    devs = new Database.Device[1];
    ...
    devs[0] = new Database.PrivateMemoryDevice(Database.Device.Kind.Data, DATABASE_SIZE);
    ...
    db.open("opendb", params, devs);
     

For persistent databases, a minimum of four storage devices must be defined and the Database constructor must be called with DiskSupport enabled. Please see the Opening Persistent Databases page for further details.