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;
}
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()));
}
}
}
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);
}
}
}
Aggregations