use of com.sleepycat.je.DatabaseEntry in project qpid-broker-j by apache.
the class UpgradeFrom4To5 method createQueue.
protected void createQueue(final Environment environment, Transaction transaction, final String queueName) {
final QueueRecordBinding binding = new QueueRecordBinding(null);
final BindingTuple bindingTuple = new BindingTuple();
DatabaseRunnable queueCreateOperation = new DatabaseRunnable() {
@Override
public void run(Database newQueueDatabase, Database newBindingsDatabase, Transaction transaction) {
AMQShortString queueNameAMQ = AMQShortString.createAMQShortString(queueName);
QueueRecord record = new QueueRecord(queueNameAMQ, null, false, null);
DatabaseEntry key = new DatabaseEntry();
TupleOutput output = new TupleOutput();
AMQShortStringEncoding.writeShortString(record.getNameShortString(), output);
TupleBase.outputToEntry(output, key);
DatabaseEntry newValue = new DatabaseEntry();
binding.objectToEntry(record, newValue);
newQueueDatabase.put(transaction, key, newValue);
FieldTable emptyArguments = FieldTableFactory.createFieldTable(Collections.emptyMap());
addBindingToDatabase(bindingTuple, newBindingsDatabase, transaction, queueNameAMQ, AMQShortString.valueOf(ExchangeDefaults.DIRECT_EXCHANGE_NAME), queueNameAMQ, emptyArguments);
// TODO QPID-3490 we should not persist a default exchange binding
addBindingToDatabase(bindingTuple, newBindingsDatabase, transaction, queueNameAMQ, AMQShortString.valueOf(ExchangeDefaults.DEFAULT_EXCHANGE_NAME), queueNameAMQ, emptyArguments);
}
};
new DatabaseTemplate(environment, NEW_QUEUE_DB_NAME, NEW_BINDINGS_DB_NAME, transaction).run(queueCreateOperation);
}
use of com.sleepycat.je.DatabaseEntry in project qpid-broker-j by apache.
the class UpgradeFrom4To5 method upgradeQueueBindings.
private void upgradeQueueBindings(Environment environment, UpgradeInteractionHandler handler, final List<AMQShortString> potentialDurableSubs, Transaction transaction) {
if (environment.getDatabaseNames().contains(OLD_BINDINGS_DB_NAME)) {
LOGGER.info("Queue Bindings");
final BindingTuple bindingTuple = new BindingTuple();
CursorOperation databaseOperation = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
// All the information required in binding entries is actually in the *key* not value.
BindingRecord oldBindingRecord = bindingTuple.entryToObject(key);
AMQShortString queueName = oldBindingRecord.getQueueName();
AMQShortString exchangeName = oldBindingRecord.getExchangeName();
AMQShortString routingKey = oldBindingRecord.getRoutingKey();
FieldTable arguments = oldBindingRecord.getArguments();
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("Processing binding for queue %s, exchange %s, routingKey %s arguments %s", queueName, exchangeName, routingKey, arguments));
}
// only topic exchange should have a JMS selector key in binding
if (potentialDurableSubs.contains(queueName) && exchangeName.equals(AMQShortString.valueOf(ExchangeDefaults.TOPIC_EXCHANGE_NAME))) {
Map<String, Object> argumentsMap = new HashMap<>();
if (arguments != null) {
argumentsMap.putAll(FieldTable.convertToMap(arguments));
}
String selectorFilterKey = AMQPFilterTypes.JMS_SELECTOR.getValue();
if (!argumentsMap.containsKey(selectorFilterKey)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.info("adding the empty string (i.e. 'no selector') value for " + queueName + " and exchange " + exchangeName);
}
argumentsMap.put(selectorFilterKey, "");
}
arguments = FieldTable.convertToFieldTable(argumentsMap);
}
addBindingToDatabase(bindingTuple, targetDatabase, transaction, queueName, exchangeName, routingKey, arguments);
}
};
new DatabaseTemplate(environment, OLD_BINDINGS_DB_NAME, NEW_BINDINGS_DB_NAME, transaction).run(databaseOperation);
environment.removeDatabase(transaction, OLD_BINDINGS_DB_NAME);
LOGGER.info(databaseOperation.getRowCount() + " Queue Binding entries");
}
}
use of com.sleepycat.je.DatabaseEntry in project qpid-broker-j by apache.
the class UpgradeFrom4To5 method upgradeMetaData.
private void upgradeMetaData(final Environment environment, final UpgradeInteractionHandler handler, final Set<Long> messagesToDiscard, Transaction transaction) {
LOGGER.info("Message MetaData");
if (environment.getDatabaseNames().contains(OLD_METADATA_DB_NAME)) {
final MessageMetaDataBinding binding = new MessageMetaDataBinding();
CursorOperation databaseOperation = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
StorableMessageMetaData metaData = binding.entryToObject(value);
// get message id
Long messageId = LongBinding.entryToLong(key);
// ONLY copy data if message is delivered to existing queue
if (messagesToDiscard.contains(messageId)) {
return;
}
DatabaseEntry newValue = new DatabaseEntry();
binding.objectToEntry(metaData, newValue);
targetDatabase.put(transaction, key, newValue);
targetDatabase.put(transaction, key, newValue);
deleteCurrent();
}
};
new DatabaseTemplate(environment, OLD_METADATA_DB_NAME, NEW_METADATA_DB_NAME, transaction).run(databaseOperation);
environment.removeDatabase(transaction, OLD_METADATA_DB_NAME);
LOGGER.info(databaseOperation.getRowCount() + " Message MetaData entries");
}
}
use of com.sleepycat.je.DatabaseEntry in project qpid-broker-j by apache.
the class CursorTemplate method processEntries.
public void processEntries() {
_cursor = _database.openCursor(_transaction, CursorConfig.READ_COMMITTED);
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
try {
_iterating = true;
while (_iterating && _cursor.getNext(key, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
_databaseEntryCallback.processEntry(_database, _transaction, key, value);
}
} finally {
_cursor.close();
}
}
use of com.sleepycat.je.DatabaseEntry in project qpid-broker-j by apache.
the class BDBConfigurationStore method writeHierarchyRecords.
private void writeHierarchyRecords(final Transaction txn, final ConfiguredObjectRecord configuredObject) {
OperationStatus status;
HierarchyKeyBinding hierarchyBinding = HierarchyKeyBinding.getInstance();
DatabaseEntry hierarchyKey = new DatabaseEntry();
DatabaseEntry hierarchyValue = new DatabaseEntry();
for (Map.Entry<String, UUID> parent : configuredObject.getParents().entrySet()) {
hierarchyBinding.objectToEntry(new HierarchyKey(configuredObject.getId(), parent.getKey()), hierarchyKey);
UUIDTupleBinding.getInstance().objectToEntry(parent.getValue(), hierarchyValue);
status = getConfiguredObjectHierarchyDb().put(txn, hierarchyKey, hierarchyValue);
if (status != OperationStatus.SUCCESS) {
throw new StoreException("Error writing configured object " + configuredObject + " parent record to database: " + status);
}
}
}
Aggregations