use of org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding in project qpid-broker-j by apache.
the class BDBConfigurationStore method update.
private void update(boolean createIfNecessary, ConfiguredObjectRecord record, com.sleepycat.je.Transaction txn) throws StoreException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Updating, creating " + createIfNecessary + " : " + record);
}
DatabaseEntry key = new DatabaseEntry();
UUIDTupleBinding keyBinding = UUIDTupleBinding.getInstance();
keyBinding.objectToEntry(record.getId(), key);
DatabaseEntry value = new DatabaseEntry();
DatabaseEntry newValue = new DatabaseEntry();
ConfiguredObjectBinding configuredObjectBinding = ConfiguredObjectBinding.getInstance();
OperationStatus status = getConfiguredObjectsDb().get(txn, key, value, LockMode.DEFAULT);
final boolean isNewRecord = status == OperationStatus.NOTFOUND;
if (status == OperationStatus.SUCCESS || (createIfNecessary && isNewRecord)) {
// write the updated entry to the store
configuredObjectBinding.objectToEntry(record, newValue);
status = getConfiguredObjectsDb().put(txn, key, newValue);
if (status != OperationStatus.SUCCESS) {
throw new StoreException("Error updating configuration details within the store: " + status);
}
if (isNewRecord) {
writeHierarchyRecords(txn, record);
}
} else if (status != OperationStatus.NOTFOUND) {
throw new StoreException("Error finding configuration details within the store: " + status);
}
}
use of org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding in project qpid-broker-j by apache.
the class BDBConfigurationStore method removeConfiguredObject.
private OperationStatus removeConfiguredObject(Transaction tx, ConfiguredObjectRecord record) throws StoreException {
UUID id = record.getId();
Map<String, UUID> parents = record.getParents();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Removing configured object: " + id);
}
DatabaseEntry key = new DatabaseEntry();
UUIDTupleBinding uuidBinding = UUIDTupleBinding.getInstance();
uuidBinding.objectToEntry(id, key);
OperationStatus status = getConfiguredObjectsDb().delete(tx, key);
if (status == OperationStatus.SUCCESS) {
for (String parentType : parents.keySet()) {
DatabaseEntry hierarchyKey = new DatabaseEntry();
HierarchyKeyBinding keyBinding = HierarchyKeyBinding.getInstance();
keyBinding.objectToEntry(new HierarchyKey(record.getId(), parentType), hierarchyKey);
getConfiguredObjectHierarchyDb().delete(tx, hierarchyKey);
}
}
return status;
}
use of org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding 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