Search in sources :

Example 41 with DatabaseEntry

use of com.sleepycat.je.DatabaseEntry 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 42 with DatabaseEntry

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

the class BdbDatabaseImpl method getString.

@Override
public String getString(String key) throws DatabaseException {
    DatabaseEntry data = new DatabaseEntry();
    database.get(transaction, new DatabaseEntry(key.getBytes()), data, LockMode.DEFAULT);
    byte[] bytes = data.getData();
    if (bytes == null) {
        return null;
    }
    return new String(bytes);
}
Also used : DatabaseEntry(com.sleepycat.je.DatabaseEntry)

Example 43 with DatabaseEntry

use of com.sleepycat.je.DatabaseEntry 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 44 with DatabaseEntry

use of com.sleepycat.je.DatabaseEntry 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 45 with DatabaseEntry

use of com.sleepycat.je.DatabaseEntry 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)

Aggregations

DatabaseEntry (com.sleepycat.je.DatabaseEntry)153 OperationStatus (com.sleepycat.je.OperationStatus)70 Transaction (com.sleepycat.je.Transaction)58 Database (com.sleepycat.je.Database)46 Cursor (com.sleepycat.je.Cursor)31 DatabaseException (com.sleepycat.je.DatabaseException)26 StoreException (org.apache.qpid.server.store.StoreException)20 UUID (java.util.UUID)17 ArrayList (java.util.ArrayList)13 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)12 DatabaseConfig (com.sleepycat.je.DatabaseConfig)11 ConnectionScopedRuntimeException (org.apache.qpid.server.util.ConnectionScopedRuntimeException)11 LockConflictException (com.sleepycat.je.LockConflictException)9 HashMap (java.util.HashMap)9 Versioned (voldemort.versioning.Versioned)9 HashSet (java.util.HashSet)8 UUIDTupleBinding (org.apache.qpid.server.store.berkeleydb.tuple.UUIDTupleBinding)8 TupleOutput (com.sleepycat.bind.tuple.TupleOutput)6 BimserverLockConflictException (org.bimserver.database.BimserverLockConflictException)6 SirixIOException (org.sirix.exception.SirixIOException)6