use of org.cojen.tupl.Transaction in project Tupl by cojen.
the class MergeCursor method perform.
/**
* Performs the given action with an appropriate lock mode.
*/
private LockResult perform(Action action) throws IOException {
Transaction txn = mTxn;
if (mView.mCombiner.combineLocks()) {
if (txn == null) {
txn = mView.newTransaction(null);
try {
txn.lockMode(LockMode.REPEATABLE_READ);
action.perform(txn);
} finally {
txn.reset();
}
return LockResult.UNOWNED;
} else if (txn.lockMode() == LockMode.READ_COMMITTED) {
LockResult result;
final LockMode original = txn.lockMode();
try {
txn.lockMode(LockMode.REPEATABLE_READ);
result = action.perform(txn);
if (result.isAcquired()) {
txn.unlock();
result = LockResult.UNOWNED;
}
} finally {
txn.lockMode(original);
}
return result;
}
}
return action.perform(txn);
}
use of org.cojen.tupl.Transaction in project Tupl by cojen.
the class ViewUtils method findNoLock.
public static void findNoLock(Cursor c, byte[] key) throws IOException {
final boolean auto = c.autoload(false);
final Transaction txn = c.link(Transaction.BOGUS);
try {
c.find(key);
} finally {
c.link(txn);
c.autoload(auto);
}
}
use of org.cojen.tupl.Transaction in project Tupl by cojen.
the class ViewUtils method previousCmp.
/**
* @param cmp 0 for previousGt, -1 for previousGe
*/
public static LockResult previousCmp(Cursor c, byte[] limitKey, int cmp) throws IOException {
Utils.keyCheck(limitKey);
while (true) {
final boolean auto = c.autoload(false);
final Transaction txn = c.link(Transaction.BOGUS);
try {
c.previous();
} finally {
c.link(txn);
c.autoload(auto);
}
if (c.key() != null) {
if (c.compareKeyTo(limitKey) > cmp) {
LockResult result = auto ? c.load() : c.lock();
if (c.value() != null) {
return result;
}
continue;
}
c.reset();
}
return LockResult.UNOWNED;
}
}
use of org.cojen.tupl.Transaction in project Tupl by cojen.
the class CursorUpgradableUpdater method step.
@Override
public boolean step() throws IOException {
tryStep: {
Cursor c = mCursor;
try {
Transaction txn = c.link();
LockMode original = txn.lockMode();
txn.lockMode(LockMode.UPGRADABLE_READ);
try {
c.next();
} finally {
txn.lockMode(original);
}
} catch (UnpositionedCursorException e) {
break tryStep;
} catch (Throwable e) {
throw Utils.fail(this, e);
}
if (c.key() != null) {
return true;
}
}
return false;
}
use of org.cojen.tupl.Transaction in project Tupl by cojen.
the class UpgradableRowUpdater 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 super.toFirst(c);
} finally {
txn.lockMode(original);
}
}
Aggregations