use of com.sleepycat.je.DatabaseEntry in project qpid-broker-j by apache.
the class UpgradeFrom5To6 method getMessageData.
/**
* @return a (sorted) map of offset -> data for the given message id
*/
private SortedMap<Integer, byte[]> getMessageData(final long messageId, final Database oldDatabase) {
TreeMap<Integer, byte[]> data = new TreeMap<Integer, byte[]>();
Cursor cursor = oldDatabase.openCursor(null, CursorConfig.READ_COMMITTED);
try {
DatabaseEntry contentKeyEntry = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
CompoundKeyBinding binding = new CompoundKeyBinding();
binding.objectToEntry(new CompoundKey(messageId, 0), contentKeyEntry);
OperationStatus status = cursor.getSearchKeyRange(contentKeyEntry, value, LockMode.DEFAULT);
OldDataBinding dataBinding = new OldDataBinding();
while (status == OperationStatus.SUCCESS) {
CompoundKey compoundKey = binding.entryToObject(contentKeyEntry);
long id = compoundKey.getMessageId();
if (id != messageId) {
// we have exhausted all chunks for this message id, break
break;
}
int offsetInMessage = compoundKey.getOffset();
OldDataValue dataValue = dataBinding.entryToObject(value);
data.put(offsetInMessage, dataValue.getData());
status = cursor.getNext(contentKeyEntry, value, LockMode.DEFAULT);
}
} finally {
cursor.close();
}
return data;
}
use of com.sleepycat.je.DatabaseEntry in project qpid-broker-j by apache.
the class UpgradeFrom5To6 method upgradeQueueEntries.
private void upgradeQueueEntries(Environment environment, Transaction transaction, final String virtualHostName) {
LOGGER.info("Queue Delivery Records");
if (environment.getDatabaseNames().contains(OLD_DELIVERY_DB_NAME)) {
final OldQueueEntryBinding oldBinding = new OldQueueEntryBinding();
final NewQueueEntryBinding newBinding = new NewQueueEntryBinding();
CursorOperation queueEntriesCursor = new CursorOperation() {
@Override
public void processEntry(Database oldDeliveryDatabase, Database newDeliveryDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
OldQueueEntryKey oldEntryRecord = oldBinding.entryToObject(key);
UUID queueId = UUIDGenerator.generateQueueUUID(oldEntryRecord.getQueueName().toString(), virtualHostName);
NewQueueEntryKey newEntryRecord = new NewQueueEntryKey(queueId, oldEntryRecord.getMessageId());
DatabaseEntry newKey = new DatabaseEntry();
newBinding.objectToEntry(newEntryRecord, newKey);
put(newDeliveryDatabase, transaction, newKey, value);
}
};
new DatabaseTemplate(environment, OLD_DELIVERY_DB_NAME, NEW_DELIVERY_DB_NAME, transaction).run(queueEntriesCursor);
environment.removeDatabase(transaction, OLD_DELIVERY_DB_NAME);
LOGGER.info(queueEntriesCursor.getRowCount() + " Queue Delivery Record Entries");
}
}
use of com.sleepycat.je.DatabaseEntry in project qpid-broker-j by apache.
the class ReplicatedEnvironmentFacadeTest method getTestKeyValue.
private String getTestKeyValue(final Database db, final int keyValue) {
final DatabaseEntry key = new DatabaseEntry();
final DatabaseEntry result = new DatabaseEntry();
IntegerBinding.intToEntry(keyValue, key);
final OperationStatus status = db.get(null, key, result, LockMode.DEFAULT);
if (status == OperationStatus.SUCCESS) {
return StringBinding.entryToString(result);
}
return null;
}
use of com.sleepycat.je.DatabaseEntry in project qpid-broker-j by apache.
the class UpgradeFrom4to5Test method assertContent.
private void assertContent() {
final UpgradeFrom4To5.ContentBinding contentBinding = new UpgradeFrom4To5.ContentBinding();
CursorOperation contentCursorOperation = new CursorOperation() {
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
long id = LongBinding.entryToLong(key);
assertTrue("Unexpected id", id > 0);
ByteBuffer content = contentBinding.entryToObject(value);
assertNotNull("Unexpected content", content);
}
};
new DatabaseTemplate(_environment, MESSAGE_CONTENT_DB_NAME, null).run(contentCursorOperation);
}
use of com.sleepycat.je.DatabaseEntry 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);
}
Aggregations