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();
}
};
}
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;
}
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);
}
}
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);
}
}
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);
}
}
Aggregations