use of org.cojen.tupl.LockMode 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.LockMode 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.LockMode in project Tupl by cojen.
the class UpgradableRowUpdater method toNext.
@Override
protected LockResult toNext(Cursor c) throws IOException {
Transaction txn = c.link();
LockMode original = txn.lockMode();
txn.lockMode(LockMode.UPGRADABLE_READ);
try {
return super.toNext(c);
} finally {
txn.lockMode(original);
}
}
use of org.cojen.tupl.LockMode in project Tupl by cojen.
the class CursorNonRepeatableUpdater method update.
@Override
public boolean update(byte[] value) throws IOException {
Cursor c = mCursor;
try {
c.store(value);
} catch (UnpositionedCursorException e) {
close();
return false;
} catch (Throwable e) {
throw Utils.fail(this, e);
}
tryStep: {
LockResult result;
try {
Transaction txn = c.link();
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.LockMode 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);
}
Aggregations