Search in sources :

Example 1 with UnpositionedCursorException

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();
}
Also used : UnpositionedCursorException(org.cojen.tupl.UnpositionedCursorException) UniqueConstraintException(org.cojen.tupl.UniqueConstraintException) Cursor(org.cojen.tupl.Cursor)

Example 2 with UnpositionedCursorException

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;
}
Also used : LockResult(org.cojen.tupl.LockResult) UnpositionedCursorException(org.cojen.tupl.UnpositionedCursorException) Transaction(org.cojen.tupl.Transaction) Cursor(org.cojen.tupl.Cursor)

Example 3 with UnpositionedCursorException

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;
}
Also used : UnpositionedCursorException(org.cojen.tupl.UnpositionedCursorException) LockResult(org.cojen.tupl.LockResult) Cursor(org.cojen.tupl.Cursor)

Example 4 with UnpositionedCursorException

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;
}
Also used : LockResult(org.cojen.tupl.LockResult) UnpositionedCursorException(org.cojen.tupl.UnpositionedCursorException) Transaction(org.cojen.tupl.Transaction) LockMode(org.cojen.tupl.LockMode) Cursor(org.cojen.tupl.Cursor)

Example 5 with UnpositionedCursorException

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;
}
Also used : LockResult(org.cojen.tupl.LockResult) UnpositionedCursorException(org.cojen.tupl.UnpositionedCursorException) Transaction(org.cojen.tupl.Transaction) Cursor(org.cojen.tupl.Cursor)

Aggregations

Cursor (org.cojen.tupl.Cursor)7 UnpositionedCursorException (org.cojen.tupl.UnpositionedCursorException)7 LockResult (org.cojen.tupl.LockResult)5 Transaction (org.cojen.tupl.Transaction)5 LockMode (org.cojen.tupl.LockMode)3 UniqueConstraintException (org.cojen.tupl.UniqueConstraintException)1