use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class UpgradeFrom5To6 method upgradeQueueBindings.
private void upgradeQueueBindings(Environment environment, Transaction transaction, final UpgradeInteractionHandler handler, final String virtualHostName) {
LOGGER.info("Queue Bindings");
if (environment.getDatabaseNames().contains(OLD_QUEUE_BINDINGS_DB_NAME)) {
final QueueBindingBinding binding = new QueueBindingBinding();
CursorOperation bindingCursor = new CursorOperation() {
@Override
public void processEntry(Database exchangeDatabase, Database configuredObjectsDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
// TODO: check and remove orphaned bindings
BindingRecord bindingRecord = binding.entryToObject(key);
String exchangeName = bindingRecord.getExchangeName() == null ? ExchangeDefaults.DEFAULT_EXCHANGE_NAME : bindingRecord.getExchangeName().toString();
String queueName = bindingRecord.getQueueName().toString();
String routingKey = bindingRecord.getRoutingKey().toString();
FieldTable arguments = bindingRecord.getArguments();
UUID bindingId = UUIDGenerator.generateBindingUUID(exchangeName, queueName, routingKey, virtualHostName);
UpgradeConfiguredObjectRecord configuredObject = createBindingConfiguredObjectRecord(exchangeName, queueName, routingKey, arguments, virtualHostName);
storeConfiguredObjectEntry(configuredObjectsDatabase, bindingId, configuredObject, transaction);
}
};
new DatabaseTemplate(environment, OLD_QUEUE_BINDINGS_DB_NAME, CONFIGURED_OBJECTS_DB_NAME, transaction).run(bindingCursor);
environment.removeDatabase(transaction, OLD_QUEUE_BINDINGS_DB_NAME);
LOGGER.info(bindingCursor.getRowCount() + " Queue Binding Entries");
}
}
use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class AbstractBDBPreferenceStore method updateVersion.
private Database updateVersion(Transaction txn, final String currentVersion) {
final Database preferencesVersionDb = getEnvironmentFacade().openDatabase(PREFERENCES_VERSION_DB_NAME, DEFAULT_DATABASE_CONFIG);
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
StringBinding.stringToEntry(currentVersion, key);
LongBinding.longToEntry(System.currentTimeMillis(), value);
preferencesVersionDb.put(txn, key, value);
return preferencesVersionDb;
}
use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class UpgradeFrom4To5 method upgradeContent.
private void upgradeContent(final Environment environment, final UpgradeInteractionHandler handler, final Set<Long> messagesToDiscard, Transaction transaction) {
LOGGER.info("Message Contents");
if (environment.getDatabaseNames().contains(OLD_CONTENT_DB_NAME)) {
final MessageContentKeyBinding keyBinding = new MessageContentKeyBinding();
final ContentBinding contentBinding = new ContentBinding();
CursorOperation cursorOperation = new CursorOperation() {
private long _prevMsgId = -1;
private int _bytesSeenSoFar;
@Override
public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
// determine the msgId of the current entry
MessageContentKey contentKey = keyBinding.entryToObject(key);
long msgId = contentKey.getMessageId();
// ONLY copy data if message is delivered to existing queue
if (messagesToDiscard.contains(msgId)) {
return;
}
// if this is a new message, restart the byte offset count.
if (_prevMsgId != msgId) {
_bytesSeenSoFar = 0;
}
// determine the content size
ByteBuffer content = contentBinding.entryToObject(value);
int contentSize = content.limit();
// create the new key: id + previously seen data count
MessageContentKey newKey = new MessageContentKey(msgId, _bytesSeenSoFar);
DatabaseEntry newKeyEntry = new DatabaseEntry();
keyBinding.objectToEntry(newKey, newKeyEntry);
DatabaseEntry newValueEntry = new DatabaseEntry();
contentBinding.objectToEntry(content, newValueEntry);
targetDatabase.put(null, newKeyEntry, newValueEntry);
_prevMsgId = msgId;
_bytesSeenSoFar += contentSize;
}
};
new DatabaseTemplate(environment, OLD_CONTENT_DB_NAME, NEW_CONTENT_DB_NAME, transaction).run(cursorOperation);
environment.removeDatabase(transaction, OLD_CONTENT_DB_NAME);
LOGGER.info(cursorOperation.getRowCount() + " Message Content entries");
}
}
use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class DatabaseTemplate method call.
public <T> T call(DatabaseCallable<T> databaseCallable) {
Database sourceDatabase = null;
Database targetDatabase = null;
try {
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(true);
dbConfig.setAllowCreate(true);
sourceDatabase = _environment.openDatabase(_parentTransaction, _sourceDatabaseName, dbConfig);
if (_targetDatabaseName != null) {
targetDatabase = _environment.openDatabase(_parentTransaction, _targetDatabaseName, dbConfig);
}
return databaseCallable.call(sourceDatabase, targetDatabase, _parentTransaction);
} finally {
closeDatabase(sourceDatabase);
closeDatabase(targetDatabase);
}
}
use of com.sleepycat.je.Database in project qpid-broker-j by apache.
the class UpgradeFrom6To7 method performUpgrade.
@Override
public void performUpgrade(Environment environment, UpgradeInteractionHandler handler, ConfiguredObject<?> parent) {
reportStarting(environment, 6);
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setTransactional(true);
dbConfig.setAllowCreate(true);
Database versionDb = environment.openDatabase(null, "CONFIG_VERSION", dbConfig);
if (versionDb.count() == 0L) {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry value = new DatabaseEntry();
IntegerBinding.intToEntry(DEFAULT_CONFIG_VERSION, value);
ByteBinding.byteToEntry((byte) 0, key);
OperationStatus status = versionDb.put(null, key, value);
if (status != OperationStatus.SUCCESS) {
throw new StoreException("Error initialising config version: " + status);
}
}
versionDb.close();
reportFinished(environment, 7);
}
Aggregations