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