Search in sources :

Example 1 with CursorConfig

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;
}
Also used : Transaction(com.sleepycat.je.Transaction) ObjectId(org.locationtech.geogig.api.ObjectId) OperationStatus(com.sleepycat.je.OperationStatus) List(java.util.List) ArrayList(java.util.ArrayList) DatabaseEntry(com.sleepycat.je.DatabaseEntry) CursorConfig(com.sleepycat.je.CursorConfig) Cursor(com.sleepycat.je.Cursor) ExecutionException(java.util.concurrent.ExecutionException) EnvironmentLockedException(com.sleepycat.je.EnvironmentLockedException)

Example 2 with CursorConfig

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();
    }
}
Also used : Transaction(com.sleepycat.je.Transaction) ObjectId(org.locationtech.geogig.api.ObjectId) OperationStatus(com.sleepycat.je.OperationStatus) DatabaseEntry(com.sleepycat.je.DatabaseEntry) CursorConfig(com.sleepycat.je.CursorConfig) Cursor(com.sleepycat.je.Cursor)

Aggregations

Cursor (com.sleepycat.je.Cursor)2 CursorConfig (com.sleepycat.je.CursorConfig)2 DatabaseEntry (com.sleepycat.je.DatabaseEntry)2 OperationStatus (com.sleepycat.je.OperationStatus)2 Transaction (com.sleepycat.je.Transaction)2 ObjectId (org.locationtech.geogig.api.ObjectId)2 EnvironmentLockedException (com.sleepycat.je.EnvironmentLockedException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1