Search in sources :

Example 1 with WriteOptions

use of com.sleepycat.je.WriteOptions 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)1 OperationStatus (com.sleepycat.je.OperationStatus)1 Transaction (com.sleepycat.je.Transaction)1 WriteOptions (com.sleepycat.je.WriteOptions)1 PermanentBackendException (org.janusgraph.diskstorage.PermanentBackendException)1 StoreTransaction (org.janusgraph.diskstorage.keycolumnvalue.StoreTransaction)1