use of com.sleepycat.je.OperationStatus in project crawler4j by yasserg.
the class InProcessPagesDB method removeURL.
public boolean removeURL(WebURL webUrl) {
synchronized (mutex) {
DatabaseEntry key = getDatabaseEntryKey(webUrl);
DatabaseEntry value = new DatabaseEntry();
Transaction txn = beginTransaction();
try (Cursor cursor = openCursor(txn)) {
OperationStatus result = cursor.getSearchKey(key, value, null);
if (result == OperationStatus.SUCCESS) {
result = cursor.delete();
if (result == OperationStatus.SUCCESS) {
return true;
}
}
} finally {
commit(txn);
}
}
return false;
}
use of com.sleepycat.je.OperationStatus in project GeoGig by boundlessgeo.
the class JEObjectDatabase method lookUpInternal.
@Override
protected List<ObjectId> lookUpInternal(final byte[] partialId) {
checkOpen();
DatabaseEntry key;
{
byte[] keyData = partialId.clone();
key = new DatabaseEntry(keyData);
}
DatabaseEntry data = new DatabaseEntry();
// do not retrieve data
data.setPartial(0, 0, true);
List<ObjectId> matches;
CursorConfig cursorConfig = new CursorConfig();
cursorConfig.setReadUncommitted(true);
Transaction transaction = null;
Cursor cursor = objectDb.openCursor(transaction, cursorConfig);
try {
// position cursor at the first closest key to the one looked up
OperationStatus status = cursor.getSearchKeyRange(key, data, LockMode.READ_UNCOMMITTED);
if (SUCCESS.equals(status)) {
matches = new ArrayList<ObjectId>(2);
final byte[] compKey = new byte[partialId.length];
while (SUCCESS.equals(status)) {
byte[] keyData = key.getData();
System.arraycopy(keyData, 0, compKey, 0, compKey.length);
if (Arrays.equals(partialId, compKey)) {
matches.add(new ObjectId(keyData));
} else {
break;
}
status = cursor.getNext(key, data, LockMode.READ_UNCOMMITTED);
}
} else {
matches = Collections.emptyList();
}
return matches;
} finally {
cursor.close();
}
}
use of com.sleepycat.je.OperationStatus in project GeoGig by boundlessgeo.
the class JEObjectDatabase method delete.
@Override
public boolean delete(final ObjectId id) {
checkWritable();
final byte[] rawKey = id.getRawValue();
final DatabaseEntry key = new DatabaseEntry(rawKey);
final Transaction transaction = newTransaction();
final OperationStatus status;
try {
status = objectDb.delete(transaction, key);
commit(transaction);
} catch (RuntimeException e) {
abort(transaction);
throw e;
}
return SUCCESS.equals(status);
}
use of com.sleepycat.je.OperationStatus in project GeoGig by boundlessgeo.
the class JEObjectDatabase method putInternal.
@Override
protected boolean putInternal(final ObjectId id, final byte[] rawData) {
checkWritable();
final Transaction transaction = newTransaction();
final OperationStatus status;
try {
status = putInternal(id, rawData, transaction);
commit(transaction);
} catch (RuntimeException e) {
abort(transaction);
throw e;
}
final boolean didntExist = SUCCESS.equals(status);
return didntExist;
}
Aggregations