Search in sources :

Example 11 with LockResult

use of org.cojen.tupl.LockResult in project Tupl by cojen.

the class BoundedCursor method find.

@Override
public LockResult find(byte[] key) throws IOException {
    if (mView.inRange(key)) {
        LockResult result = mSource.find(key);
        mOutOfBounds = false;
        return result;
    } else {
        mOutOfBounds = true;
        ViewUtils.findNoLock(mSource, key);
        return LockResult.UNOWNED;
    }
}
Also used : LockResult(org.cojen.tupl.LockResult)

Example 12 with LockResult

use of org.cojen.tupl.LockResult in project Tupl by cojen.

the class BoundedCursor method first.

@Override
public LockResult first() throws IOException {
    LockResult result;
    final BoundedView view = mView;
    final byte[] start = view.mStart;
    final Cursor source = mSource;
    if (view.mEnd == null) {
        if (start == null) {
            result = source.first();
        } else if ((view.mMode & START_EXCLUSIVE) == 0) {
            result = source.findGe(start);
        } else {
            result = source.findGt(start);
        }
    } else if (start == null) {
        // If isolation level is read committed, then the first key must be
        // locked. Otherwise, an uncommitted delete could be observed.
        result = source.first();
        byte[] key = source.key();
        if (key == null) {
            result = LockResult.UNOWNED;
        } else if (view.endRangeCompare(view.mEnd, key) > 0) {
            if (result == LockResult.ACQUIRED) {
                source.link().unlock();
            }
            source.reset();
            result = LockResult.UNOWNED;
        }
    } else if (view.endRangeCompare(view.mEnd, start) > 0) {
        source.reset();
        result = LockResult.UNOWNED;
    } else if ((view.mMode & START_EXCLUSIVE) == 0) {
        // If isolation level is read committed, then the first key must be
        // locked. Otherwise, an uncommitted delete could be observed.
        result = source.find(start);
        if (source.value() == null) {
            if (result == LockResult.ACQUIRED) {
                source.link().unlock();
            }
            return next();
        }
    } else {
        ViewUtils.findNoLock(source, start);
        return next();
    }
    mOutOfBounds = false;
    return result;
}
Also used : LockResult(org.cojen.tupl.LockResult) BoundedView(org.cojen.tupl.views.BoundedView) Cursor(org.cojen.tupl.Cursor)

Example 13 with LockResult

use of org.cojen.tupl.LockResult in project Tupl by cojen.

the class BoundedCursor method findNearbyGe.

@Override
public LockResult findNearbyGe(byte[] key) throws IOException {
    final BoundedView view = mView;
    if (view.startRangeCompare(key) < 0) {
        return first();
    }
    LockResult result;
    final Cursor source = mSource;
    if (view.mEnd == null) {
        result = source.findNearbyGe(key);
    } else if (view.endRangeCompare(view.mEnd, key) > 0) {
        source.reset();
        result = LockResult.UNOWNED;
    } else {
        // If isolation level is read committed, then the first key must be
        // locked. Otherwise, an uncommitted delete could be observed.
        result = source.findNearby(key);
        if (source.value() == null) {
            if (result == LockResult.ACQUIRED) {
                source.link().unlock();
            }
            return next();
        }
    }
    mOutOfBounds = false;
    return result;
}
Also used : LockResult(org.cojen.tupl.LockResult) BoundedView(org.cojen.tupl.views.BoundedView) Cursor(org.cojen.tupl.Cursor)

Example 14 with LockResult

use of org.cojen.tupl.LockResult in project Tupl by cojen.

the class BoundedCursor method findGt.

@Override
public LockResult findGt(byte[] key) throws IOException {
    BoundedView view = mView;
    if (view.startRangeCompare(key) < 0) {
        return first();
    }
    LockResult result;
    final Cursor source = mSource;
    if (view.mEnd == null) {
        result = source.findGt(key);
    } else if (view.endRangeCompare(view.mEnd, key) > 0) {
        source.reset();
        result = LockResult.UNOWNED;
    } else {
        ViewUtils.findNoLock(source, key);
        return next();
    }
    mOutOfBounds = false;
    return result;
}
Also used : LockResult(org.cojen.tupl.LockResult) BoundedView(org.cojen.tupl.views.BoundedView) Cursor(org.cojen.tupl.Cursor)

Example 15 with LockResult

use of org.cojen.tupl.LockResult in project Tupl by cojen.

the class BoundedCursor method skip.

@Override
public LockResult skip(long amount, byte[] limitKey, boolean inclusive) throws IOException {
    LockResult result;
    if (amount == 0 || limitKey == null) {
        result = mSource.skip(0);
    } else {
        BoundedView view = mView;
        if (amount > 0) {
            if (view.endRangeCompare(limitKey) > 0) {
                limitKey = view.mEnd;
                inclusive = (view.mMode & END_EXCLUSIVE) == 0;
            }
        } else {
            if (view.startRangeCompare(limitKey) < 0) {
                limitKey = view.mStart;
                inclusive = (view.mMode & START_EXCLUSIVE) == 0;
            }
        }
        result = mSource.skip(amount, limitKey, inclusive);
    }
    mOutOfBounds = false;
    return result;
}
Also used : LockResult(org.cojen.tupl.LockResult) BoundedView(org.cojen.tupl.views.BoundedView)

Aggregations

LockResult (org.cojen.tupl.LockResult)68 Cursor (org.cojen.tupl.Cursor)28 BoundedView (org.cojen.tupl.views.BoundedView)14 LockFailureException (org.cojen.tupl.LockFailureException)13 Transaction (org.cojen.tupl.Transaction)8 UnpositionedCursorException (org.cojen.tupl.UnpositionedCursorException)5 LockMode (org.cojen.tupl.LockMode)4 IOException (java.io.IOException)1 SoftReference (java.lang.ref.SoftReference)1 Combiner (org.cojen.tupl.Combiner)1 RowPredicateLock (org.cojen.tupl.core.RowPredicateLock)1 LocalPool (org.cojen.tupl.util.LocalPool)1