Search in sources :

Example 1 with MapBinding

use of org.apache.qpid.server.store.berkeleydb.tuple.MapBinding in project qpid-broker-j by apache.

the class AbstractBDBPreferenceStore method getPreferenceRecords.

private Collection<PreferenceRecord> getPreferenceRecords(final EnvironmentFacade environmentFacade) {
    Collection<PreferenceRecord> records = new LinkedHashSet<>();
    try (Cursor cursor = getPreferencesDb().openCursor(null, null)) {
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry value = new DatabaseEntry();
        UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance();
        MapBinding valueBinding = MapBinding.getInstance();
        while (cursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
            UUID preferenceId = keyBinding.entryToObject(key);
            Map<String, Object> preferenceAttributes = valueBinding.entryToObject(value);
            PreferenceRecord record = new PreferenceRecordImpl(preferenceId, preferenceAttributes);
            records.add(record);
        }
    } catch (RuntimeException e) {
        throw environmentFacade.handleDatabaseException("Cannot visit preferences", e);
    }
    return records;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MapBinding(org.apache.qpid.server.store.berkeleydb.tuple.MapBinding) PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) PreferenceRecordImpl(org.apache.qpid.server.store.preferences.PreferenceRecordImpl) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor) UUIDTupleBinding(org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding) UUID(java.util.UUID)

Example 2 with MapBinding

use of org.apache.qpid.server.store.berkeleydb.tuple.MapBinding in project qpid-broker-j by apache.

the class AbstractBDBPreferenceStore method updateOrCreateInternal.

private void updateOrCreateInternal(final Transaction txn, final Collection<PreferenceRecord> preferenceRecords) {
    Database preferencesDb = getPreferencesDb();
    DatabaseEntry key = new DatabaseEntry();
    DatabaseEntry value = new DatabaseEntry();
    UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance();
    MapBinding valueBinding = MapBinding.getInstance();
    for (PreferenceRecord record : preferenceRecords) {
        keyBinding.objectToEntry(record.getId(), key);
        valueBinding.objectToEntry(record.getAttributes(), value);
        OperationStatus status = preferencesDb.put(txn, key, value);
        if (status != OperationStatus.SUCCESS) {
            throw new StoreException(String.format("Error writing preference with id '%s' (status %s)", record.getId(), status.name()));
        }
    }
}
Also used : MapBinding(org.apache.qpid.server.store.berkeleydb.tuple.MapBinding) OperationStatus(com.sleepycat.je.OperationStatus) Database(com.sleepycat.je.Database) PreferenceRecord(org.apache.qpid.server.store.preferences.PreferenceRecord) UUIDTupleBinding(org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StoreException(org.apache.qpid.server.store.StoreException)

Example 3 with MapBinding

use of org.apache.qpid.server.store.berkeleydb.tuple.MapBinding 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)

Aggregations

DatabaseEntry (com.sleepycat.je.DatabaseEntry)3 MapBinding (org.apache.qpid.server.store.berkeleydb.tuple.MapBinding)3 UUIDTupleBinding (org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding)3 PreferenceRecord (org.apache.qpid.server.store.preferences.PreferenceRecord)3 Database (com.sleepycat.je.Database)2 Cursor (com.sleepycat.je.Cursor)1 DatabaseConfig (com.sleepycat.je.DatabaseConfig)1 Environment (com.sleepycat.je.Environment)1 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)1 OperationStatus (com.sleepycat.je.OperationStatus)1 LinkedHashSet (java.util.LinkedHashSet)1 UUID (java.util.UUID)1 StoreException (org.apache.qpid.server.store.StoreException)1 PreferenceRecordImpl (org.apache.qpid.server.store.preferences.PreferenceRecordImpl)1