Search in sources :

Example 31 with OperationStatus

use of com.sleepycat.je.OperationStatus in project janusgraph by JanusGraph.

the class BerkeleyJEKeyValueStore method getSlice.

@Override
public RecordIterator<KeyValueEntry> getSlice(KVQuery query, StoreTransaction txh) throws BackendException {
    log.trace("beginning db={}, op=getSlice, tx={}", name, txh);
    final StaticBuffer keyStart = query.getStart();
    final StaticBuffer keyEnd = query.getEnd();
    final KeySelector selector = query.getKeySelector();
    final DatabaseEntry foundKey = keyStart.as(ENTRY_FACTORY);
    final DatabaseEntry foundData = new DatabaseEntry();
    final Cursor cursor = openCursor(txh);
    return new RecordIterator<KeyValueEntry>() {

        private OperationStatus status;

        private KeyValueEntry current;

        @Override
        public boolean hasNext() {
            if (current == null) {
                current = getNextEntry();
            }
            return current != null;
        }

        @Override
        public KeyValueEntry next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            KeyValueEntry next = current;
            current = null;
            return next;
        }

        private KeyValueEntry getNextEntry() {
            if (status != null && status != OperationStatus.SUCCESS) {
                return null;
            }
            while (!selector.reachedLimit()) {
                if (status == null) {
                    status = cursor.get(foundKey, foundData, Get.SEARCH_GTE, getReadOptions(txh)) == null ? OperationStatus.NOTFOUND : OperationStatus.SUCCESS;
                } else {
                    status = cursor.get(foundKey, foundData, Get.NEXT, getReadOptions(txh)) == null ? OperationStatus.NOTFOUND : OperationStatus.SUCCESS;
                }
                if (status != OperationStatus.SUCCESS) {
                    break;
                }
                StaticBuffer key = getBuffer(foundKey);
                if (key.compareTo(keyEnd) >= 0) {
                    status = OperationStatus.NOTFOUND;
                    break;
                }
                if (selector.include(key)) {
                    return new KeyValueEntry(key, getBuffer(foundData));
                }
            }
            return null;
        }

        @Override
        public void close() {
            closeCursor(txh, cursor);
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : RecordIterator(org.janusgraph.diskstorage.util.RecordIterator) OperationStatus(com.sleepycat.je.OperationStatus) StaticBuffer(org.janusgraph.diskstorage.StaticBuffer) DatabaseEntry(com.sleepycat.je.DatabaseEntry) KeySelector(org.janusgraph.diskstorage.keycolumnvalue.keyvalue.KeySelector) Cursor(com.sleepycat.je.Cursor) KeyValueEntry(org.janusgraph.diskstorage.keycolumnvalue.keyvalue.KeyValueEntry) NoSuchElementException(java.util.NoSuchElementException)

Example 32 with OperationStatus

use of com.sleepycat.je.OperationStatus in project leopard by tanhaichao.

the class BdbDatabaseImpl method putNoDupData.

@Override
public boolean putNoDupData(String key, String value) throws DatabaseException {
    OperationStatus status = database.putNoDupData(transaction, new DatabaseEntry(key.getBytes()), new DatabaseEntry(value.getBytes()));
    String result = status.toString();
    if (result.endsWith(".KEYEXIST")) {
        throw new DuplicateEntryException("key[" + key + "]已存在.");
    }
    // System.err.println(status);
    return true;
}
Also used : OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DuplicateEntryException(com.sleepycat.je.tree.DuplicateEntryException)

Example 33 with OperationStatus

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

the class AbstractBDBMessageStore method getMessageMetaData.

/**
 * Retrieves message meta-data.
 *
 * @param messageId The message to get the meta-data for.
 *
 * @return The message meta data.
 *
 * @throws org.apache.qpid.server.store.StoreException If the operation fails for any reason, or if the specified message does not exist.
 */
StorableMessageMetaData getMessageMetaData(long messageId) throws StoreException {
    getLogger().debug("public MessageMetaData getMessageMetaData(Long messageId = {}): called", messageId);
    DatabaseEntry key = new DatabaseEntry();
    LongBinding.longToEntry(messageId, key);
    DatabaseEntry value = new DatabaseEntry();
    MessageMetaDataBinding messageBinding = MessageMetaDataBinding.getInstance();
    try {
        OperationStatus status = getMessageMetaDataDb().get(null, key, value, LockMode.READ_UNCOMMITTED);
        if (status != OperationStatus.SUCCESS) {
            throw new StoreException("Metadata not found for message with id " + messageId);
        }
        StorableMessageMetaData mdd = messageBinding.entryToObject(value);
        return mdd;
    } catch (RuntimeException e) {
        throw getEnvironmentFacade().handleDatabaseException("Error reading message metadata for message with id " + messageId + ": " + e.getMessage(), e);
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) OperationStatus(com.sleepycat.je.OperationStatus) MessageMetaDataBinding(org.apache.qpid.server.store.berkeleydb.tuple.MessageMetaDataBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StorableMessageMetaData(org.apache.qpid.server.store.StorableMessageMetaData) StoreException(org.apache.qpid.server.store.StoreException)

Example 34 with OperationStatus

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

the class AbstractBDBMessageStore method removeXid.

private void removeXid(Transaction txn, long format, byte[] globalId, byte[] branchId) throws StoreException {
    DatabaseEntry key = new DatabaseEntry();
    Xid xid = new Xid(format, globalId, branchId);
    XidBinding keyBinding = XidBinding.getInstance();
    keyBinding.objectToEntry(xid, key);
    try {
        OperationStatus status = getXidDb().delete(txn, key);
        if (status == OperationStatus.NOTFOUND) {
            throw new StoreException("Unable to find xid");
        } else if (status != OperationStatus.SUCCESS) {
            throw new StoreException("Unable to remove xid");
        }
    } catch (RuntimeException e) {
        if (getLogger().isDebugEnabled()) {
            getLogger().error("Failed to remove xid in transaction {}", e);
        }
        throw getEnvironmentFacade().handleDatabaseException("Error accessing database while removing xid: " + e.getMessage(), e);
    }
}
Also used : Xid(org.apache.qpid.server.txn.Xid) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) OperationStatus(com.sleepycat.je.OperationStatus) XidBinding(org.apache.qpid.server.store.berkeleydb.tuple.XidBinding) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StoreException(org.apache.qpid.server.store.StoreException)

Example 35 with OperationStatus

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

the class AbstractBDBMessageStore method addContent.

/**
 * Stores a chunk of message data.
 *
 * @param tx         The transaction for the operation.
 * @param messageId       The message to store the data for.
 * @param contentBody     The content of the data chunk.
 *
 * @throws org.apache.qpid.server.store.StoreException If the operation fails for any reason, or if the specified message does not exist.
 */
private void addContent(final Transaction tx, long messageId, QpidByteBuffer contentBody) throws StoreException {
    DatabaseEntry key = new DatabaseEntry();
    LongBinding.longToEntry(messageId, key);
    DatabaseEntry value = new DatabaseEntry();
    byte[] data = new byte[contentBody.remaining()];
    contentBody.copyTo(data);
    value.setData(data);
    try {
        OperationStatus status = getMessageContentDb().put(tx, key, value);
        if (status != OperationStatus.SUCCESS) {
            throw new StoreException("Error adding content for message id " + messageId + ": " + status);
        }
        getLogger().debug("Storing content for message {} in transaction {}", messageId, tx);
    } catch (RuntimeException e) {
        throw getEnvironmentFacade().handleDatabaseException("Error writing AMQMessage with id " + messageId + " to database: " + e.getMessage(), e);
    }
}
Also used : ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) StoreException(org.apache.qpid.server.store.StoreException)

Aggregations

OperationStatus (com.sleepycat.je.OperationStatus)76 DatabaseEntry (com.sleepycat.je.DatabaseEntry)70 Transaction (com.sleepycat.je.Transaction)23 DatabaseException (com.sleepycat.je.DatabaseException)21 Cursor (com.sleepycat.je.Cursor)15 StoreException (org.apache.qpid.server.store.StoreException)13 Versioned (voldemort.versioning.Versioned)9 Database (com.sleepycat.je.Database)8 ArrayList (java.util.ArrayList)7 LockConflictException (com.sleepycat.je.LockConflictException)6 UUIDTupleBinding (org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding)6 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)6 UUID (java.util.UUID)4 BimserverLockConflictException (org.bimserver.database.BimserverLockConflictException)4 SirixIOException (org.sirix.exception.SirixIOException)4 AsyncOperationStatus (voldemort.server.protocol.admin.AsyncOperationStatus)4 PersistenceFailureException (voldemort.store.PersistenceFailureException)4 DatabaseConfig (com.sleepycat.je.DatabaseConfig)3 LockMode (com.sleepycat.je.LockMode)3 VSystemException (io.vertigo.lang.VSystemException)3