Search in sources :

Example 1 with DatabaseConfig

use of com.sleepycat.je.DatabaseConfig in project BIMserver by opensourceBIM.

the class BerkeleyKeyValueStore method openTable.

public boolean openTable(DatabaseSession databaseSession, String tableName, boolean transactional) throws BimserverDatabaseException {
    if (tables.containsKey(tableName)) {
        throw new BimserverDatabaseException("Table " + tableName + " already opened");
    }
    DatabaseConfig databaseConfig = new DatabaseConfig();
    databaseConfig.setAllowCreate(false);
    boolean finalTransactional = transactional && useTransactions;
    // if (!transactional) {
    // databaseConfig.setCacheMode(CacheMode.EVICT_BIN);
    // }
    databaseConfig.setDeferredWrite(!finalTransactional);
    databaseConfig.setTransactional(finalTransactional);
    databaseConfig.setSortedDuplicates(false);
    Database database = environment.openDatabase(null, tableName, databaseConfig);
    if (database == null) {
        throw new BimserverDatabaseException("Table " + tableName + " not found in database");
    }
    tables.put(tableName, new TableWrapper(database, finalTransactional));
    return true;
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) Database(com.sleepycat.je.Database) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 2 with DatabaseConfig

use of com.sleepycat.je.DatabaseConfig in project BIMserver by opensourceBIM.

the class BerkeleyKeyValueStore method createTable.

public boolean createTable(String tableName, DatabaseSession databaseSession, boolean transactional) throws BimserverDatabaseException {
    if (tables.containsKey(tableName)) {
        throw new BimserverDatabaseException("Table " + tableName + " already created");
    }
    DatabaseConfig databaseConfig = new DatabaseConfig();
    databaseConfig.setAllowCreate(true);
    boolean finalTransactional = transactional && useTransactions;
    databaseConfig.setDeferredWrite(!finalTransactional);
    // if (!transactional) {
    // databaseConfig.setCacheMode(CacheMode.EVICT_BIN);
    // }
    databaseConfig.setTransactional(finalTransactional);
    databaseConfig.setSortedDuplicates(false);
    Database database = environment.openDatabase(null, tableName, databaseConfig);
    if (database == null) {
        return false;
    }
    tables.put(tableName, new TableWrapper(database, finalTransactional));
    return true;
}
Also used : BimserverDatabaseException(org.bimserver.BimserverDatabaseException) Database(com.sleepycat.je.Database) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 3 with DatabaseConfig

use of com.sleepycat.je.DatabaseConfig in project qpid-broker-j by apache.

the class AbstractBDBPreferenceStore method getPreferencesVersionDb.

private Database getPreferencesVersionDb() {
    Database preferencesVersionDb;
    try {
        DatabaseConfig config = new DatabaseConfig().setTransactional(true).setAllowCreate(false);
        preferencesVersionDb = getEnvironmentFacade().openDatabase(PREFERENCES_VERSION_DB_NAME, config);
    } catch (DatabaseNotFoundException e) {
        preferencesVersionDb = updateVersion(null, BrokerModel.MODEL_VERSION);
    }
    return preferencesVersionDb;
}
Also used : DatabaseNotFoundException(com.sleepycat.je.DatabaseNotFoundException) Database(com.sleepycat.je.Database) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 4 with DatabaseConfig

use of com.sleepycat.je.DatabaseConfig in project qpid-broker-j by apache.

the class ReplicatedEnvironmentFacadeTest method testOpenDatabaseReusesCachedHandle.

public void testOpenDatabaseReusesCachedHandle() throws Exception {
    DatabaseConfig createIfAbsentDbConfig = DatabaseConfig.DEFAULT.setAllowCreate(true);
    EnvironmentFacade ef = createMaster();
    Database handle1 = ef.openDatabase("myDatabase", createIfAbsentDbConfig);
    assertNotNull(handle1);
    Database handle2 = ef.openDatabase("myDatabase", createIfAbsentDbConfig);
    assertSame("Database handle should be cached", handle1, handle2);
    ef.closeDatabase("myDatabase");
    Database handle3 = ef.openDatabase("myDatabase", createIfAbsentDbConfig);
    assertNotSame("Expecting a new handle after database closure", handle1, handle3);
}
Also used : Database(com.sleepycat.je.Database) EnvironmentFacade(org.apache.qpid.server.store.berkeleydb.EnvironmentFacade) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 5 with DatabaseConfig

use of com.sleepycat.je.DatabaseConfig in project qpid-broker-j by apache.

the class UpgraderTest method getStoreVersion.

private int getStoreVersion(Environment environment) {
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);
    int storeVersion = -1;
    Database versionDb = null;
    Cursor cursor = null;
    try {
        versionDb = environment.openDatabase(null, Upgrader.VERSION_DB_NAME, dbConfig);
        cursor = versionDb.openCursor(null, null);
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        while (cursor.getNext(key, value, null) == OperationStatus.SUCCESS) {
            int version = IntegerBinding.entryToInt(key);
            if (storeVersion < version) {
                storeVersion = version;
            }
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
        if (versionDb != null) {
            versionDb.close();
        }
    }
    return storeVersion;
}
Also used : Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Aggregations

DatabaseConfig (com.sleepycat.je.DatabaseConfig)42 Database (com.sleepycat.je.Database)25 Environment (com.sleepycat.je.Environment)18 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)16 DatabaseEntry (com.sleepycat.je.DatabaseEntry)11 File (java.io.File)8 Cursor (com.sleepycat.je.Cursor)6 Transaction (com.sleepycat.je.Transaction)6 DatabaseException (com.sleepycat.je.DatabaseException)4 IOException (java.io.IOException)4 StoreException (org.apache.qpid.server.store.StoreException)4 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)4 OperationStatus (com.sleepycat.je.OperationStatus)3 TupleInput (com.sleepycat.bind.tuple.TupleInput)2 TupleOutput (com.sleepycat.bind.tuple.TupleOutput)2 DatabaseNotFoundException (com.sleepycat.je.DatabaseNotFoundException)2 RuntimeIOException (htsjdk.samtools.util.RuntimeIOException)2 LineIterator (htsjdk.tribble.readers.LineIterator)2 ArrayList (java.util.ArrayList)2 BdbDbCreationException (nl.knaw.huygens.timbuctoo.v5.berkeleydb.exceptions.BdbDbCreationException)2