Search in sources :

Example 31 with DatabaseConfig

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

the class Upgrader method upgradeIfNecessary.

public void upgradeIfNecessary() {
    boolean isEmpty = _environment.getDatabaseNames().isEmpty();
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);
    Database versionDb = null;
    try {
        versionDb = _environment.openDatabase(null, VERSION_DB_NAME, dbConfig);
        if (versionDb.count() == 0L) {
            int sourceVersion = isEmpty ? BDBConfigurationStore.VERSION : identifyOldStoreVersion();
            DatabaseEntry key = new DatabaseEntry();
            IntegerBinding.intToEntry(sourceVersion, key);
            DatabaseEntry value = new DatabaseEntry();
            LongBinding.longToEntry(System.currentTimeMillis(), value);
            versionDb.put(null, key, value);
        }
        int version = getSourceVersion(versionDb);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Source message store version is " + version);
        }
        if (version > BDBConfigurationStore.VERSION) {
            throw new StoreException("Database version " + version + " is higher than the most recent known version: " + BDBConfigurationStore.VERSION);
        }
        performUpgradeFromVersion(version, versionDb);
    } finally {
        if (versionDb != null) {
            versionDb.close();
        }
    }
}
Also used : Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseConfig(com.sleepycat.je.DatabaseConfig) StoreException(org.apache.qpid.server.store.StoreException)

Example 32 with DatabaseConfig

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

the class DatabaseTemplate method call.

public <T> T call(DatabaseCallable<T> databaseCallable) {
    Database sourceDatabase = null;
    Database targetDatabase = null;
    try {
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setTransactional(true);
        dbConfig.setAllowCreate(true);
        sourceDatabase = _environment.openDatabase(_parentTransaction, _sourceDatabaseName, dbConfig);
        if (_targetDatabaseName != null) {
            targetDatabase = _environment.openDatabase(_parentTransaction, _targetDatabaseName, dbConfig);
        }
        return databaseCallable.call(sourceDatabase, targetDatabase, _parentTransaction);
    } finally {
        closeDatabase(sourceDatabase);
        closeDatabase(targetDatabase);
    }
}
Also used : Database(com.sleepycat.je.Database) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 33 with DatabaseConfig

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

the class UpgradeFrom6To7 method performUpgrade.

@Override
public void performUpgrade(Environment environment, UpgradeInteractionHandler handler, ConfiguredObject<?> parent) {
    reportStarting(environment, 6);
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);
    Database versionDb = environment.openDatabase(null, "CONFIG_VERSION", dbConfig);
    if (versionDb.count() == 0L) {
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        IntegerBinding.intToEntry(DEFAULT_CONFIG_VERSION, value);
        ByteBinding.byteToEntry((byte) 0, key);
        OperationStatus status = versionDb.put(null, key, value);
        if (status != OperationStatus.SUCCESS) {
            throw new StoreException("Error initialising config version: " + status);
        }
    }
    versionDb.close();
    reportFinished(environment, 7);
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseConfig(com.sleepycat.je.DatabaseConfig) StoreException(org.apache.qpid.server.store.StoreException)

Example 34 with DatabaseConfig

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

the class ReplicatedEnvironmentFacadeTest method testOpenDatabaseWhenFacadeIsNotOpened.

@Test
public void testOpenDatabaseWhenFacadeIsNotOpened() throws Exception {
    DatabaseConfig createIfAbsentDbConfig = DatabaseConfig.DEFAULT.setAllowCreate(true);
    EnvironmentFacade ef = createMaster();
    ef.close();
    try {
        ef.openDatabase("myDatabase", createIfAbsentDbConfig);
        fail("Database open should fail");
    } catch (ConnectionScopedRuntimeException e) {
        assertEquals("Unexpected exception", "Environment facade is not in opened state", e.getMessage());
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) ReplicatedEnvironmentFacade(org.apache.qpid.server.store.berkeleydb.replication.ReplicatedEnvironmentFacade) EnvironmentFacade(org.apache.qpid.server.store.berkeleydb.EnvironmentFacade) DatabaseConfig(com.sleepycat.je.DatabaseConfig) Test(org.junit.Test)

Example 35 with DatabaseConfig

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

the class ReplicatedEnvironmentFacadeTest method createDatabaseConfig.

private DatabaseConfig createDatabaseConfig() {
    final DatabaseConfig createConfig = new DatabaseConfig();
    createConfig.setAllowCreate(true);
    createConfig.setTransactional(true);
    return createConfig;
}
Also used : DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Aggregations

DatabaseConfig (com.sleepycat.je.DatabaseConfig)56 Database (com.sleepycat.je.Database)30 Environment (com.sleepycat.je.Environment)26 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)23 DatabaseEntry (com.sleepycat.je.DatabaseEntry)13 File (java.io.File)12 Transaction (com.sleepycat.je.Transaction)7 Test (org.junit.Test)7 Cursor (com.sleepycat.je.Cursor)6 DatabaseException (com.sleepycat.je.DatabaseException)6 IOException (java.io.IOException)4 Map (java.util.Map)4 StoreException (org.apache.qpid.server.store.StoreException)4 BimserverDatabaseException (org.bimserver.BimserverDatabaseException)4 OperationStatus (com.sleepycat.je.OperationStatus)3 HashMap (java.util.HashMap)3 StoredClassCatalog (com.sleepycat.bind.serial.StoredClassCatalog)2 StringBinding (com.sleepycat.bind.tuple.StringBinding)2 TupleInput (com.sleepycat.bind.tuple.TupleInput)2 TupleOutput (com.sleepycat.bind.tuple.TupleOutput)2