use of org.apache.jena.sparql.JenaTransactionException in project jena by apache.
the class DatasetGraphInMemory method begin.
@Override
public void begin(final ReadWrite readWrite) {
if (isInTransaction())
throw new JenaTransactionException("Transactions cannot be nested!");
startTransaction(readWrite);
_begin(readWrite);
}
use of org.apache.jena.sparql.JenaTransactionException in project jena by apache.
the class AbstractTestTransactionLifecycle method testCommitCommit.
private void testCommitCommit(ReadWrite mode) {
Dataset ds = create();
ds.begin(mode);
ds.commit();
try {
ds.commit();
fail("Expected transaction exception - commit-commit(" + mode + ")");
} catch (JenaTransactionException ex) {
safeEnd(ds);
}
}
use of org.apache.jena.sparql.JenaTransactionException in project jena by apache.
the class AbstractTestTransactionLifecycle method testAbortCommit.
private void testAbortCommit(ReadWrite mode) {
assumeTrue(supportsAbort());
Dataset ds = create();
ds.begin(mode);
ds.abort();
try {
ds.commit();
fail("Expected transaction exception - abort-commit(" + mode + ")");
} catch (JenaTransactionException ex) {
safeEnd(ds);
}
}
use of org.apache.jena.sparql.JenaTransactionException in project jena by apache.
the class TxnCounter method begin.
public void begin(ReadWrite readWrite, boolean canBlock) {
// (Readers never block at this point.)
if (readWrite == WRITE) {
// Writers take a WRITE permit from the semaphore to ensure there
// is at most one active writer, else the attempt to start the
// transaction blocks.
// Released by in commit/abort.
acquireWriterLock(canBlock);
}
synchronized (txnLifecycleLock) {
if (txnMode.get() != null)
throw new JenaTransactionException("Already in a transaction");
IntegerState state = new IntegerState(value.get());
txnValue.set(state);
txnMode.set(readWrite);
}
}
use of org.apache.jena.sparql.JenaTransactionException in project jena by apache.
the class DatasetGraphInMemory method mutate.
/**
* Wrap a mutation in a WRITE transaction iff necessary.
*
* @param mutator
* @param payload
*/
private <T> void mutate(final Consumer<T> mutator, final T payload) {
if (isInTransaction()) {
if (!transactionMode().equals(WRITE)) {
TxnType mode = transactionType.get();
switch(mode) {
case WRITE:
break;
case READ:
throw new JenaTransactionException("Tried to write inside a READ transaction!");
case READ_COMMITTED_PROMOTE:
case READ_PROMOTE:
boolean readCommitted = (mode == TxnType.READ_COMMITTED_PROMOTE);
_promote(readCommitted);
break;
}
}
mutator.accept(payload);
} else
Txn.executeWrite(this, () -> mutator.accept(payload));
}
Aggregations