Search in sources :

Example 56 with Database

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

the class UpgradeFrom4to5Test method assertContentForQueue.

private void assertContentForQueue(String queueName, int expectedQueueSize, final Set<Long> messageIdsForQueue) {
    final AtomicInteger contentCounter = new AtomicInteger();
    final MessageContentKeyBinding keyBinding = new MessageContentKeyBinding();
    CursorOperation cursorOperation = new CursorOperation() {

        private long _prevMsgId = -1;

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
            MessageContentKey contentKey = keyBinding.entryToObject(key);
            long msgId = contentKey.getMessageId();
            if (_prevMsgId != msgId && messageIdsForQueue.contains(msgId)) {
                contentCounter.incrementAndGet();
            }
            _prevMsgId = msgId;
        }
    };
    new DatabaseTemplate(_environment, MESSAGE_CONTENT_DB_NAME, null).run(cursorOperation);
    assertEquals("Unxpected number of entries in content db for queue " + queueName, expectedQueueSize, contentCounter.get());
}
Also used : MessageContentKeyBinding(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom4To5.MessageContentKeyBinding) Transaction(com.sleepycat.je.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) MessageContentKey(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom4To5.MessageContentKey)

Example 57 with Database

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

the class UpgradeFrom7To8Test method loadConfiguredObjects.

private Map<UUID, UpgradeConfiguredObjectRecord> loadConfiguredObjects() {
    final Map<UUID, UpgradeConfiguredObjectRecord> configuredObjectsRecords = new HashMap<UUID, UpgradeConfiguredObjectRecord>();
    final UpgradeConfiguredObjectBinding binding = new UpgradeConfiguredObjectBinding();
    final UpgradeUUIDBinding uuidBinding = new UpgradeUUIDBinding();
    CursorOperation configuredObjectsCursor = new CursorOperation() {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
            UUID id = uuidBinding.entryToObject(key);
            UpgradeConfiguredObjectRecord object = binding.entryToObject(value);
            configuredObjectsRecords.put(id, object);
        }
    };
    new DatabaseTemplate(_environment, CONFIGURED_OBJECTS_DB_NAME, null).run(configuredObjectsCursor);
    return configuredObjectsRecords;
}
Also used : Transaction(com.sleepycat.je.Transaction) HashMap(java.util.HashMap) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) UUID(java.util.UUID)

Example 58 with Database

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

the class UpgraderFailOnNewerVersionTest method getStoreVersion.

private int getStoreVersion() {
    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);
    int storeVersion = -1;
    try (Database versionDb = _environment.openDatabase(null, Upgrader.VERSION_DB_NAME, dbConfig);
        Cursor 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;
            }
        }
    }
    return storeVersion;
}
Also used : Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 59 with Database

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

the class BDBPreferenceStoreTest method populateTestData.

private void populateTestData(final List<PreferenceRecord> records, final String modelVersion) {
    EnvironmentConfig envConfig = new EnvironmentConfig();
    envConfig.setAllowCreate(true);
    envConfig.setTransactional(false);
    try (Environment environment = new Environment(_storeFile, envConfig)) {
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setAllowCreate(true);
        try (Database versionDb = environment.openDatabase(null, "USER_PREFERENCES_VERSION", dbConfig);
            Database preferencesDb = environment.openDatabase(null, "USER_PREFERENCES", dbConfig)) {
            DatabaseEntry key = new DatabaseEntry();
            DatabaseEntry value = new DatabaseEntry();
            UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance();
            MapBinding valueBinding = MapBinding.getInstance();
            for (PreferenceRecord record : records) {
                keyBinding.objectToEntry(record.getId(), key);
                valueBinding.objectToEntry(record.getAttributes(), value);
                preferencesDb.put(null, key, value);
            }
            ByteBinding.byteToEntry((byte) 0, value);
            StringBinding.stringToEntry(modelVersion, key);
            versionDb.put(null, key, value);
        }
    }
}
Also used : MapBinding(org.apache.qpid.server.store.berkeleydb.tuple.MapBinding) EnvironmentConfig(com.sleepycat.je.EnvironmentConfig) Database(com.sleepycat.je.Database) PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) Environment(com.sleepycat.je.Environment) UUIDTupleBinding(org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseConfig(com.sleepycat.je.DatabaseConfig)

Example 60 with Database

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

the class ReplicatedEnvironmentFacade method openDatabase.

@Override
public Database openDatabase(String name, DatabaseConfig databaseConfig) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("openDatabase " + name + " for " + _prettyGroupNodeName);
    }
    if (_state.get() != State.OPEN) {
        throw new ConnectionScopedRuntimeException("Environment facade is not in opened state");
    }
    ReplicatedEnvironment environment = getEnvironment();
    Database cachedHandle = _cachedDatabases.get(name);
    if (cachedHandle == null) {
        Database handle = environment.openDatabase(null, name, databaseConfig);
        Database existingHandle = _cachedDatabases.putIfAbsent(name, handle);
        if (existingHandle == null) {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("openDatabase " + name + " new handle");
            }
            cachedHandle = handle;
        } else {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("openDatabase " + name + " existing handle");
            }
            cachedHandle = existingHandle;
            handle.close();
        }
    }
    return cachedHandle;
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) Database(com.sleepycat.je.Database) ReplicatedEnvironment(com.sleepycat.je.rep.ReplicatedEnvironment)

Aggregations

Database (com.sleepycat.je.Database)73 DatabaseEntry (com.sleepycat.je.DatabaseEntry)46 Transaction (com.sleepycat.je.Transaction)35 DatabaseConfig (com.sleepycat.je.DatabaseConfig)27 UUID (java.util.UUID)12 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)11 Environment (com.sleepycat.je.Environment)10 OperationStatus (com.sleepycat.je.OperationStatus)8 Cursor (com.sleepycat.je.Cursor)7 HashSet (java.util.HashSet)7 StoreException (org.apache.qpid.server.store.StoreException)7 HashMap (java.util.HashMap)6 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)5 File (java.io.File)5 ArrayList (java.util.ArrayList)5 FieldTable (org.apache.qpid.server.protocol.v0_8.FieldTable)5 NewPreparedTransaction (org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewPreparedTransaction)5 OldPreparedTransaction (org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.OldPreparedTransaction)5 Test (org.junit.Test)5 TupleOutput (com.sleepycat.bind.tuple.TupleOutput)4