Search in sources :

Example 46 with Transaction

use of com.sleepycat.je.Transaction in project GeoGig by boundlessgeo.

the class JEObjectDatabase method delete.

@Override
public boolean delete(final ObjectId id) {
    checkWritable();
    final byte[] rawKey = id.getRawValue();
    final DatabaseEntry key = new DatabaseEntry(rawKey);
    final Transaction transaction = newTransaction();
    final OperationStatus status;
    try {
        status = objectDb.delete(transaction, key);
        commit(transaction);
    } catch (RuntimeException e) {
        abort(transaction);
        throw e;
    }
    return SUCCESS.equals(status);
}
Also used : Transaction(com.sleepycat.je.Transaction) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 47 with Transaction

use of com.sleepycat.je.Transaction in project GeoGig by boundlessgeo.

the class JEObjectDatabase method putInternal.

@Override
protected boolean putInternal(final ObjectId id, final byte[] rawData) {
    checkWritable();
    final Transaction transaction = newTransaction();
    final OperationStatus status;
    try {
        status = putInternal(id, rawData, transaction);
        commit(transaction);
    } catch (RuntimeException e) {
        abort(transaction);
        throw e;
    }
    final boolean didntExist = SUCCESS.equals(status);
    return didntExist;
}
Also used : Transaction(com.sleepycat.je.Transaction) OperationStatus(com.sleepycat.je.OperationStatus)

Example 48 with Transaction

use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.

the class UpgradeFrom4to5Test method assertContentForQueue.

private void assertContentForQueue(String queueName, int expectedQueueSize, final Set<Long> messageIdsForQueue) {
    final AtomicInteger contentCounter = new AtomicInteger();
    final MessageContentKeyBinding keyBinding = new MessageContentKeyBinding();
    CursorOperation cursorOperation = new CursorOperation() {

        private long _prevMsgId = -1;

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
            MessageContentKey contentKey = keyBinding.entryToObject(key);
            long msgId = contentKey.getMessageId();
            if (_prevMsgId != msgId && messageIdsForQueue.contains(msgId)) {
                contentCounter.incrementAndGet();
            }
            _prevMsgId = msgId;
        }
    };
    new DatabaseTemplate(_environment, MESSAGE_CONTENT_DB_NAME, null).run(cursorOperation);
    assertEquals("Unxpected number of entries in content db for queue " + queueName, expectedQueueSize, contentCounter.get());
}
Also used : MessageContentKeyBinding(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom4To5.MessageContentKeyBinding) Transaction(com.sleepycat.je.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) MessageContentKey(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom4To5.MessageContentKey)

Example 49 with Transaction

use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.

the class UpgradeFrom4to5Test method loadBindings.

private List<BindingRecord> loadBindings() {
    final BindingTuple bindingTuple = new BindingTuple();
    final List<BindingRecord> queueBindings = new ArrayList<BindingRecord>();
    CursorOperation databaseOperation = new CursorOperation() {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
            BindingRecord bindingRecord = bindingTuple.entryToObject(key);
            AMQShortString queueName = bindingRecord.getQueueName();
            AMQShortString exchangeName = bindingRecord.getExchangeName();
            AMQShortString routingKey = bindingRecord.getRoutingKey();
            FieldTable arguments = bindingRecord.getArguments();
            queueBindings.add(new BindingRecord(exchangeName, queueName, routingKey, arguments));
        }
    };
    new DatabaseTemplate(_environment, BINDING_DB_NAME, null).run(databaseOperation);
    return queueBindings;
}
Also used : AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) Transaction(com.sleepycat.je.Transaction) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) BindingTuple(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom4To5.BindingTuple) ArrayList(java.util.ArrayList) Database(com.sleepycat.je.Database) DatabaseEntry(com.sleepycat.je.DatabaseEntry) BindingRecord(org.apache.qpid.server.store.berkeleydb.upgrade.UpgradeFrom4To5.BindingRecord)

Example 50 with Transaction

use of com.sleepycat.je.Transaction in project qpid-broker-j by apache.

the class UpgradeFrom4to5Test method assertMetadataForQueue.

private void assertMetadataForQueue(final String queueName, final int expectedQueueSize, final Set<Long> messageIdsForQueue) {
    final AtomicInteger metadataCounter = new AtomicInteger();
    CursorOperation databaseOperation = new CursorOperation() {

        @Override
        public void processEntry(Database sourceDatabase, Database targetDatabase, Transaction transaction, DatabaseEntry key, DatabaseEntry value) {
            Long messageId = LongBinding.entryToLong(key);
            boolean messageIsForTheRightQueue = messageIdsForQueue.contains(messageId);
            if (messageIsForTheRightQueue) {
                metadataCounter.incrementAndGet();
            }
        }
    };
    new DatabaseTemplate(_environment, MESSAGE_META_DATA_DB_NAME, null).run(databaseOperation);
    assertEquals("Unxpected number of entries in metadata db for queue " + queueName, expectedQueueSize, metadataCounter.get());
}
Also used : Transaction(com.sleepycat.je.Transaction) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Database(com.sleepycat.je.Database) 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