use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class UpgradeFrom4to5Test method assertQueues.
private void assertQueues(Set<String> expectedQueueNames) {
List<AMQShortString> durableSubNames = Collections.emptyList();
final UpgradeFrom4To5.QueueRecordBinding binding = new UpgradeFrom4To5.QueueRecordBinding(durableSubNames);
final Set<String> actualQueueNames = new HashSet<String>();
CursorOperation queueNameCollector = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
QueueRecord record = binding.entryToObject(value);
String queueName = record.getNameShortString().toString();
actualQueueNames.add(queueName);
}
};
new DatabaseTemplate(_environment, "queueDb_v5", null).run(queueNameCollector);
assertEquals("Unexpected queue names", expectedQueueNames, actualQueueNames);
}
use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class UpgradeFrom4to5Test method assertQueueHasOwner.
private void assertQueueHasOwner(String queueName, final String expectedOwner) {
List<AMQShortString> durableSubNames = Collections.emptyList();
final UpgradeFrom4To5.QueueRecordBinding binding = new UpgradeFrom4To5.QueueRecordBinding(durableSubNames);
final AtomicReference<String> actualOwner = new AtomicReference<String>();
final AtomicBoolean foundQueue = new AtomicBoolean(false);
CursorOperation queueNameCollector = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
QueueRecord record = binding.entryToObject(value);
String queueName = record.getNameShortString().toString();
if (queueName.equals(queueName)) {
foundQueue.set(true);
actualOwner.set(AMQShortString.toString(record.getOwner()));
}
}
};
new DatabaseTemplate(_environment, "queueDb_v5", null).run(queueNameCollector);
assertTrue("Could not find queue in database", foundQueue.get());
assertEquals("Queue has unexpected owner", expectedOwner, actualOwner.get());
}
use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class UpgradeFrom7To8Test method loadConfiguredObjectHierarchy.
private Map<UpgradeHierarchyKey, UUID> loadConfiguredObjectHierarchy() {
final Map<UpgradeHierarchyKey, UUID> hierarchyRecords = new HashMap<UpgradeHierarchyKey, UUID>();
final UpgradeHierarchyKeyBinding hierarchyKeyBinding = new UpgradeHierarchyKeyBinding();
final UpgradeUUIDBinding uuidParentBinding = new UpgradeUUIDBinding();
CursorOperation hierarchyCursor = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
UpgradeHierarchyKey hierarchyKey = hierarchyKeyBinding.entryToObject(key);
UUID parentId = uuidParentBinding.entryToObject(value);
hierarchyRecords.put(hierarchyKey, parentId);
}
};
new DatabaseTemplate(_environment, CONFIGURED_OBJECT_HIERARCHY_DB_NAME, null).run(hierarchyCursor);
return hierarchyRecords;
}
use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class UpgradeFrom5To6 method upgradeQueues.
private List<String> upgradeQueues(Environment environment, Transaction transaction, final String virtualHostName) {
final List<String> queueNames = new ArrayList<String>();
LOGGER.info("Queues");
if (environment.getDatabaseNames().contains(OLD_QUEUE_DB_NAME)) {
final UpgradeQueueBinding queueBinding = new UpgradeQueueBinding();
CursorOperation queueCursor = new CursorOperation() {
@Override
public void processEntry(Database queueDatabase, Database configuredObjectsDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
OldQueueRecord queueRecord = queueBinding.entryToObject(value);
String queueName = queueRecord.getNameShortString().toString();
queueNames.add(queueName);
String owner = queueRecord.getOwner() == null ? null : queueRecord.getOwner().toString();
boolean exclusive = queueRecord.isExclusive();
FieldTable arguments = queueRecord.getArguments();
UUID queueId = UUIDGenerator.generateQueueUUID(queueName, virtualHostName);
UpgradeConfiguredObjectRecord configuredObject = createQueueConfiguredObjectRecord(queueName, owner, exclusive, arguments);
storeConfiguredObjectEntry(configuredObjectsDatabase, queueId, configuredObject, transaction);
}
};
new DatabaseTemplate(environment, OLD_QUEUE_DB_NAME, CONFIGURED_OBJECTS_DB_NAME, transaction).run(queueCursor);
environment.removeDatabase(transaction, OLD_QUEUE_DB_NAME);
LOGGER.info(queueCursor.getRowCount() + " Queue Entries");
}
return queueNames;
}
use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class UpgradeFrom5To6 method upgradeXidEntries.
private void upgradeXidEntries(Environment environment, Transaction transaction, final String virtualHostName) {
if (environment.getDatabaseNames().contains(OLD_XID_DB_NAME)) {
LOGGER.info("Xid Records");
final OldPreparedTransactionBinding oldTransactionBinding = new OldPreparedTransactionBinding();
final NewPreparedTransactionBinding newTransactionBinding = new NewPreparedTransactionBinding();
CursorOperation xidEntriesCursor = new CursorOperation() {
@Override
public void processEntry(Database oldXidDatabase, Database newXidDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
OldPreparedTransaction oldPreparedTransaction = oldTransactionBinding.entryToObject(value);
OldRecordImpl[] oldDequeues = oldPreparedTransaction.getDequeues();
OldRecordImpl[] oldEnqueues = oldPreparedTransaction.getEnqueues();
NewRecordImpl[] newEnqueues = null;
NewRecordImpl[] newDequeues = null;
if (oldDequeues != null) {
newDequeues = new NewRecordImpl[oldDequeues.length];
for (int i = 0; i < newDequeues.length; i++) {
OldRecordImpl dequeue = oldDequeues[i];
UUID id = UUIDGenerator.generateQueueUUID(dequeue.getQueueName(), virtualHostName);
newDequeues[i] = new NewRecordImpl(id, dequeue.getMessageNumber());
}
}
if (oldEnqueues != null) {
newEnqueues = new NewRecordImpl[oldEnqueues.length];
for (int i = 0; i < newEnqueues.length; i++) {
OldRecordImpl enqueue = oldEnqueues[i];
UUID id = UUIDGenerator.generateQueueUUID(enqueue.getQueueName(), virtualHostName);
newEnqueues[i] = new NewRecordImpl(id, enqueue.getMessageNumber());
}
}
NewPreparedTransaction newPreparedTransaction = new NewPreparedTransaction(newEnqueues, newDequeues);
DatabaseEntry newValue = new DatabaseEntry();
newTransactionBinding.objectToEntry(newPreparedTransaction, newValue);
put(newXidDatabase, transaction, key, newValue);
}
};
new DatabaseTemplate(environment, OLD_XID_DB_NAME, NEW_XID_DB_NAME, transaction).run(xidEntriesCursor);
environment.removeDatabase(transaction, OLD_XID_DB_NAME);
LOGGER.info(xidEntriesCursor.getRowCount() + " Xid Entries");
}
}
Aggregations