use of org.apache.qpid.server.store.berkeleydb.tuple.ConfiguredObjectBinding in project qpid-broker-j by apache.
the class BDBConfigurationStore method storeConfiguredObjectEntry.
private void storeConfiguredObjectEntry(final Transaction txn, ConfiguredObjectRecord configuredObject) throws StoreException {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Storing configured object record: " + configuredObject);
}
DatabaseEntry key = new DatabaseEntry();
UUIDTupleBinding uuidBinding = UUIDTupleBinding.getInstance();
uuidBinding.objectToEntry(configuredObject.getId(), key);
DatabaseEntry value = new DatabaseEntry();
ConfiguredObjectBinding queueBinding = ConfiguredObjectBinding.getInstance();
queueBinding.objectToEntry(configuredObject, value);
try {
OperationStatus status = getConfiguredObjectsDb().put(txn, key, value);
if (status != OperationStatus.SUCCESS) {
throw new StoreException("Error writing configured object " + configuredObject + " to database: " + status);
}
writeHierarchyRecords(txn, configuredObject);
} catch (RuntimeException e) {
throw _environmentFacade.handleDatabaseException("Error writing configured object " + configuredObject + " to database: " + e.getMessage(), e);
}
}
use of org.apache.qpid.server.store.berkeleydb.tuple.ConfiguredObjectBinding in project qpid-broker-j by apache.
the class UpgradeFrom7To8 method storeConfiguredObjectEntry.
private void storeConfiguredObjectEntry(Database configuredObjectsDb, final Transaction txn, ConfiguredObjectRecord configuredObject) {
DatabaseEntry key = new DatabaseEntry();
UUIDTupleBinding uuidBinding = UUIDTupleBinding.getInstance();
uuidBinding.objectToEntry(configuredObject.getId(), key);
DatabaseEntry value = new DatabaseEntry();
ConfiguredObjectBinding configuredObjectBinding = ConfiguredObjectBinding.getInstance();
configuredObjectBinding.objectToEntry(configuredObject, value);
OperationStatus status = configuredObjectsDb.put(txn, key, value);
if (status != OperationStatus.SUCCESS) {
throw new StoreException("Error writing configured object " + configuredObject + " to database: " + status);
}
}
use of org.apache.qpid.server.store.berkeleydb.tuple.ConfiguredObjectBinding in project qpid-broker-j by apache.
the class BDBConfigurationStore method doVisitAllConfiguredObjectRecords.
private Collection<? extends ConfiguredObjectRecord> doVisitAllConfiguredObjectRecords() {
Map<UUID, BDBConfiguredObjectRecord> configuredObjects = new HashMap<>();
try (Cursor objectsCursor = getConfiguredObjectsDb().openCursor(null, null)) {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
while (objectsCursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
UUID id = UUIDTupleBinding.getInstance().entryToObject(key);
BDBConfiguredObjectRecord configuredObject = (BDBConfiguredObjectRecord) new ConfiguredObjectBinding(id).entryToObject(value);
configuredObjects.put(configuredObject.getId(), configuredObject);
}
// set parents
try (Cursor hierarchyCursor = getConfiguredObjectHierarchyDb().openCursor(null, null)) {
while (hierarchyCursor.getNext(key, value, LockMode.READ_UNCOMMITTED) == OperationStatus.SUCCESS) {
HierarchyKey hk = HierarchyKeyBinding.getInstance().entryToObject(key);
UUID parentId = UUIDTupleBinding.getInstance().entryToObject(value);
BDBConfiguredObjectRecord child = configuredObjects.get(hk.getChildId());
if (child != null) {
ConfiguredObjectRecord parent = configuredObjects.get(parentId);
if (parent != null) {
child.addParent(hk.getParentType(), parent);
}
}
}
}
}
return configuredObjects.values();
}
use of org.apache.qpid.server.store.berkeleydb.tuple.ConfiguredObjectBinding 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);
}
}
Aggregations