Search in sources :

Example 6 with Transaction

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

the class JoinedRowUpdater method updateCurrent.

private void updateCurrent() throws IOException {
    Transaction txn = txn();
    Object old = attachAccessor(txn);
    try {
        mPrimaryUpdater.mRow = mRow;
        mPrimaryUpdater.joinedUpdateCurrent();
    } finally {
        txn.attach(old);
    }
}
Also used : Transaction(org.cojen.tupl.Transaction)

Example 7 with Transaction

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

the class JoinedRowUpdater method deleteCurrent.

private void deleteCurrent() throws IOException {
    Transaction txn = txn();
    Object old = attachAccessor(txn);
    try {
        mPrimaryUpdater.mRow = mRow;
        mPrimaryUpdater.deleteCurrent();
    } finally {
        txn.attach(old);
    }
}
Also used : Transaction(org.cojen.tupl.Transaction)

Example 8 with Transaction

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

the class NonRepeatableRowUpdater method toFirst.

@Override
protected LockResult toFirst(Cursor c) throws IOException {
    Transaction txn = c.link();
    LockMode original = txn.lockMode();
    txn.lockMode(LockMode.UPGRADABLE_READ);
    try {
        return mLockResult = super.toFirst(c);
    } finally {
        txn.lockMode(original);
    }
}
Also used : Transaction(org.cojen.tupl.Transaction) LockMode(org.cojen.tupl.LockMode)

Example 9 with Transaction

use of org.cojen.tupl.Transaction 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 10 with Transaction

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

the class JoinedScanController method join.

// Subclass should implement one of these methods. The secondaryValue param is required
// for alternate keys.
// protected static byte[] toPrimaryKey(byte[] secondaryKey);
// protected static byte[] toPrimaryKey(byte[] secondaryKey, byte[] secondaryValue);
/**
 * Given a positioned cursor over the secondary index and a decoded primary key, return the
 * associated primary value, or null if not found.
 *
 * @param secondaryCursor must have a non-null transaction
 */
protected byte[] join(Cursor secondaryCursor, LockResult result, byte[] primaryKey) throws IOException {
    Transaction txn = secondaryCursor.link();
    byte[] primaryValue = mPrimaryIndex.load(txn, primaryKey);
    if (result == LockResult.ACQUIRED && txn.lastLockedKey() == primaryKey && txn.lastLockedIndex() == mPrimaryIndex.id()) {
        // Combine the secondary and primary locks together, so that they can be released
        // together if the row is filtered out.
        txn.unlockCombine();
    }
    return validate(secondaryCursor, txn, primaryValue);
}
Also used : Transaction(org.cojen.tupl.Transaction)

Aggregations

Transaction (org.cojen.tupl.Transaction)36 Cursor (org.cojen.tupl.Cursor)12 Index (org.cojen.tupl.Index)10 LockMode (org.cojen.tupl.LockMode)8 LockResult (org.cojen.tupl.LockResult)8 Database (org.cojen.tupl.Database)6 UnpositionedCursorException (org.cojen.tupl.UnpositionedCursorException)5 IOException (java.io.IOException)4 UnmodifiableReplicaException (org.cojen.tupl.UnmodifiableReplicaException)4 PrepareHandler (org.cojen.tupl.ext.PrepareHandler)4 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)3 WeakReference (java.lang.ref.WeakReference)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TreeMap (java.util.TreeMap)2 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)2 TimeUnit (java.util.concurrent.TimeUnit)2 Label (org.cojen.maker.Label)2 MethodMaker (org.cojen.maker.MethodMaker)2 Variable (org.cojen.maker.Variable)2