use of com.sleepycat.je.CursorConfig in project GeoGig by boundlessgeo.
the class JEObjectDatabase method deleteAll.
@Override
public long deleteAll(Iterator<ObjectId> ids, final BulkOpListener listener) {
checkWritable();
long count = 0;
UnmodifiableIterator<List<ObjectId>> partition = partition(ids, getBulkPartitionSize());
final DatabaseEntry data = new DatabaseEntry();
// do not retrieve data
data.setPartial(0, 0, true);
while (partition.hasNext()) {
List<ObjectId> nextIds = Lists.newArrayList(partition.next());
Collections.sort(nextIds);
final Transaction transaction = newTransaction();
CursorConfig cconfig = new CursorConfig();
final Cursor cursor = objectDb.openCursor(transaction, cconfig);
try {
DatabaseEntry key = new DatabaseEntry(new byte[ObjectId.NUM_BYTES]);
for (ObjectId id : nextIds) {
// copy id to key object without allocating new byte[]
id.getRawValue(key.getData());
OperationStatus status = cursor.getSearchKey(key, data, LockMode.DEFAULT);
if (OperationStatus.SUCCESS.equals(status)) {
OperationStatus delete = cursor.delete();
if (OperationStatus.SUCCESS.equals(delete)) {
listener.deleted(id);
count++;
} else {
listener.notFound(id);
}
} else {
listener.notFound(id);
}
}
cursor.close();
} catch (Exception e) {
cursor.close();
abort(transaction);
Throwables.propagate(e);
}
commit(transaction);
}
return count;
}
use of com.sleepycat.je.CursorConfig 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();
}
}
Aggregations