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