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;
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations