Search in sources :

Example 1 with OperationResult

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

the class BerkeleyJEKeyValueStore method get.

@Override
public StaticBuffer get(StaticBuffer key, StoreTransaction txh) throws BackendException {
    Transaction tx = getTransaction(txh);
    try {
        DatabaseEntry databaseKey = key.as(ENTRY_FACTORY);
        DatabaseEntry data = new DatabaseEntry();
        log.trace("db={}, op=get, tx={}", name, txh);
        OperationResult result = db.get(tx, databaseKey, data, Get.SEARCH, getReadOptions(txh));
        if (result != null) {
            return getBuffer(data);
        } else {
            return null;
        }
    } catch (DatabaseException e) {
        throw new PermanentBackendException(e);
    }
}
Also used : StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) Transaction(com.sleepycat.je.Transaction) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) OperationResult(com.sleepycat.je.OperationResult) DatabaseEntry(com.sleepycat.je.DatabaseEntry) DatabaseException(com.sleepycat.je.DatabaseException)

Example 2 with OperationResult

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

the class BerkeleyJEKeyValueStore method insert.

public void insert(StaticBuffer key, StaticBuffer value, StoreTransaction txh, boolean allowOverwrite, Integer ttl) throws BackendException {
    Transaction tx = getTransaction(txh);
    OperationStatus status;
    log.trace("db={}, op=insert, tx={}", name, txh);
    WriteOptions writeOptions = getWriteOptions(txh);
    if (ttl != null && ttl > 0) {
        int convertedTtl = ttlConverter.apply(ttl);
        writeOptions.setTTL(convertedTtl, TimeUnit.HOURS);
    }
    if (allowOverwrite) {
        OperationResult result = db.put(tx, key.as(ENTRY_FACTORY), value.as(ENTRY_FACTORY), Put.OVERWRITE, writeOptions);
        EnvironmentFailureException.assertState(result != null);
        status = OperationStatus.SUCCESS;
    } else {
        OperationResult result = db.put(tx, key.as(ENTRY_FACTORY), value.as(ENTRY_FACTORY), Put.NO_OVERWRITE, writeOptions);
        status = result == null ? OperationStatus.KEYEXIST : OperationStatus.SUCCESS;
    }
    if (status != OperationStatus.SUCCESS) {
        throw new PermanentBackendException("Key already exists on no-overwrite.");
    }
}
Also used : WriteOptions(com.sleepycat.je.WriteOptions) StoreTransaction(org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction) Transaction(com.sleepycat.je.Transaction) PermanentBackendException(org.janusgraph.diskstorage.PermanentBackendException) OperationStatus(com.sleepycat.je.OperationStatus) OperationResult(com.sleepycat.je.OperationResult)

Aggregations

OperationResult (com.sleepycat.je.OperationResult)2 Transaction (com.sleepycat.je.Transaction)2 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)2 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)2 DatabaseEntry (com.sleepycat.je.DatabaseEntry)1 DatabaseException (com.sleepycat.je.DatabaseException)1 OperationStatus (com.sleepycat.je.OperationStatus)1 WriteOptions (com.sleepycat.je.WriteOptions)1