use of org.cojen.tupl.UnpositionedCursorException in project Tupl by cojen.
the class BasicRowUpdater method joinedUpdateCurrent.
// Called by JoinedRowUpdater.
final void joinedUpdateCurrent() throws IOException {
try {
R current = mRow;
if (current == null) {
throw new IllegalStateException("No current row");
}
Cursor c = mCursor;
byte[] key, value;
{
RowEvaluator<R> evaluator = mEvaluator;
key = evaluator.updateKey(current, c.key());
value = evaluator.updateValue(current, c.value());
}
if (Arrays.equals(key, c.key())) {
doUpdateAsStore(c, value);
} else {
doUpdateAsDeleteInsert(current, c, key, value);
}
} catch (UnpositionedCursorException e) {
finished();
throw new IllegalStateException("No current row");
} catch (UniqueConstraintException e) {
throw e;
} catch (Throwable e) {
throw RowUtils.fail(this, e);
}
// prevent subclass from attempting to release the lock
unlocked();
}
use of org.cojen.tupl.UnpositionedCursorException in project Tupl by cojen.
the class BasicRowScanner method doStep.
protected final R doStep(R row) throws IOException {
Cursor c = mCursor;
try {
a: while (true) {
LockResult result = toNext(c);
b: while (true) {
while (c.key() == null) {
if (!mController.next()) {
break a;
}
setEvaluator(mController.evaluator());
Transaction txn = c.link();
mCursor = c = mController.newCursor(mTable.mSource, txn);
toFirst(c);
}
try {
R decoded = decodeRow(c, result, row);
if (decoded != null) {
mRow = decoded;
return decoded;
}
} catch (StoppedCursorException e) {
if (result == LockResult.ACQUIRED) {
c.link().unlock();
unlocked();
}
continue b;
}
if (result == LockResult.ACQUIRED) {
c.link().unlock();
unlocked();
}
continue a;
}
}
} catch (UnpositionedCursorException e) {
} catch (Throwable e) {
throw RowUtils.fail(this, e);
}
finished();
return null;
}
use of org.cojen.tupl.UnpositionedCursorException in project Tupl by cojen.
the class CursorAutoCommitUpdater method update.
@Override
public boolean update(byte[] value) throws IOException {
Cursor c = mCursor;
try {
c.commit(value);
} catch (UnpositionedCursorException e) {
close();
return false;
} catch (Throwable e) {
throw Utils.fail(this, e);
}
tryStep: {
LockResult result;
try {
result = c.next();
} catch (UnpositionedCursorException e) {
break tryStep;
} catch (Throwable e) {
throw Utils.fail(this, e);
}
if (c.key() != null) {
mLockResult = result;
return true;
}
}
mLockResult = null;
c.link().exit();
return false;
}
use of org.cojen.tupl.UnpositionedCursorException in project Tupl by cojen.
the class CursorNonRepeatableUpdater method step.
@Override
public boolean step() throws IOException {
LockResult result = mLockResult;
if (result == null) {
return false;
}
Cursor c = mCursor;
Transaction txn = c.link();
tryStep: {
try {
if (result.isAcquired()) {
// If the transaction is being acted upon independently of this updater,
// then this technique might throw an IllegalStateException.
txn.unlock();
}
LockMode original = txn.lockMode();
txn.lockMode(LockMode.UPGRADABLE_READ);
try {
result = c.next();
} finally {
txn.lockMode(original);
}
} catch (UnpositionedCursorException e) {
break tryStep;
} catch (Throwable e) {
throw Utils.fail(this, e);
}
if (c.key() != null) {
mLockResult = result;
return true;
}
}
mLockResult = null;
return false;
}
use of org.cojen.tupl.UnpositionedCursorException in project Tupl by cojen.
the class CursorAutoCommitUpdater method step.
@Override
public boolean step() throws IOException {
LockResult result = mLockResult;
if (result == null) {
return false;
}
Cursor c = mCursor;
Transaction txn = c.link();
tryStep: {
try {
if (result.isAcquired()) {
txn.unlock();
}
result = c.next();
} catch (UnpositionedCursorException e) {
break tryStep;
} catch (Throwable e) {
throw Utils.fail(this, e);
}
if (c.key() != null) {
mLockResult = result;
return true;
}
}
mLockResult = null;
txn.exit();
return false;
}
Aggregations