use of com.sleepycat.je.Transaction 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.Transaction in project qpid-broker-j by apache.
the class AbstractBDBMessageStore method recordXid.
private List<Runnable> recordXid(Transaction txn, long format, byte[] globalId, byte[] branchId, org.apache.qpid.server.store.Transaction.EnqueueRecord[] enqueues, org.apache.qpid.server.store.Transaction.DequeueRecord[] dequeues) throws StoreException {
DatabaseEntry key = new DatabaseEntry();
Xid xid = new Xid(format, globalId, branchId);
XidBinding keyBinding = XidBinding.getInstance();
keyBinding.objectToEntry(xid, key);
DatabaseEntry value = new DatabaseEntry();
PreparedTransaction preparedTransaction = new PreparedTransaction(enqueues, dequeues);
PreparedTransactionBinding.objectToEntry(preparedTransaction, value);
for (org.apache.qpid.server.store.Transaction.EnqueueRecord enqueue : enqueues) {
StoredMessage storedMessage = enqueue.getMessage().getStoredMessage();
if (storedMessage instanceof StoredBDBMessage) {
((StoredBDBMessage) storedMessage).store(txn);
}
}
try {
getXidDb().put(txn, key, value);
return Collections.emptyList();
} catch (RuntimeException e) {
getLogger().error("Failed to write xid: " + e.getMessage(), e);
throw getEnvironmentFacade().handleDatabaseException("Error writing xid to database", e);
}
}
use of com.sleepycat.je.Transaction in project crawler4j by yasserg.
the class InProcessPagesDB method removeURL.
public boolean removeURL(WebURL webUrl) {
synchronized (mutex) {
DatabaseEntry key = getDatabaseEntryKey(webUrl);
DatabaseEntry value = new DatabaseEntry();
Transaction txn = beginTransaction();
try (Cursor cursor = openCursor(txn)) {
OperationStatus result = cursor.getSearchKey(key, value, null);
if (result == OperationStatus.SUCCESS) {
result = cursor.delete();
if (result == OperationStatus.SUCCESS) {
return true;
}
}
} finally {
commit(txn);
}
}
return false;
}
use of com.sleepycat.je.Transaction in project crawler4j by yasserg.
the class WorkQueues method put.
public void put(WebURL url) {
DatabaseEntry value = new DatabaseEntry();
webURLBinding.objectToEntry(url, value);
Transaction txn = beginTransaction();
urlsDB.put(txn, getDatabaseEntryKey(url), value);
commit(txn);
}
use of com.sleepycat.je.Transaction in project bboxdb by jnidzwetzki.
the class BDBWriterRunnable method storeNode.
@SuppressWarnings("unused")
protected void storeNode(final SerializableNode node) {
final byte[] nodeBytes = node.toByteArray();
Transaction txn = null;
if (OSMBDBNodeStore.USE_TRANSACTIONS) {
txn = environment.beginTransaction(null, null);
}
final DatabaseEntry key = OSMBDBNodeStore.buildDatabaseKeyEntry(node.getId());
final DatabaseEntry value = new DatabaseEntry(nodeBytes);
final OperationStatus status = database.put(txn, key, value);
if (status != OperationStatus.SUCCESS) {
throw new RuntimeException("Data insertion got status " + status);
}
if (txn != null) {
txn.commit();
}
}
Aggregations