Search in sources :

Example 61 with Transaction

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");
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) UUID(java.util.UUID)

Example 62 with Transaction

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);
    }
}
Also used : Xid(org.apache.qpid.server.txn.Xid) PreparedTransaction(org.apache.qpid.server.store.berkeleydb.entry.PreparedTransaction) PreparedTransaction(org.apache.qpid.server.store.berkeleydb.entry.PreparedTransaction) Transaction(com.sleepycat.je.Transaction) StoredMessage(org.apache.qpid.server.store.StoredMessage) XidBinding(org.apache.qpid.server.store.berkeleydb.tuple.XidBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 63 with Transaction

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;
}
Also used : Transaction(com.sleepycat.je.Transaction) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) Cursor(com.sleepycat.je.Cursor)

Example 64 with Transaction

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);
}
Also used : Transaction(com.sleepycat.je.Transaction) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 65 with Transaction

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();
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Aggregations

Transaction (com.sleepycat.je.Transaction)74 DatabaseEntry (com.sleepycat.je.DatabaseEntry)55 Database (com.sleepycat.je.Database)35 OperationStatus (com.sleepycat.je.OperationStatus)20 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)12 UUID (java.util.UUID)11 Cursor (com.sleepycat.je.Cursor)10 DatabaseConfig (com.sleepycat.je.DatabaseConfig)7 DatabaseException (com.sleepycat.je.DatabaseException)6 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Environment (com.sleepycat.je.Environment)5 HashMap (java.util.HashMap)5 FieldTable (org.apache.qpid.server.protocol.v0_8.FieldTable)5 NewPreparedTransaction (org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.NewPreparedTransaction)5 OldPreparedTransaction (org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom5To6.OldPreparedTransaction)5 EnvironmentConfig (com.sleepycat.je.EnvironmentConfig)4 StoreException (org.apache.qpid.server.store.StoreException)4 TupleOutput (com.sleepycat.bind.tuple.TupleOutput)3 LockMode (com.sleepycat.je.LockMode)3