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