use of org.apache.jena.sparql.JenaTransactionException in project jena by apache.
the class DatasetGraphTransaction method requireWrite.
public void requireWrite() {
if (!isInTransaction())
return;
DatasetGraphTxn dsgTxn = dsgtxn.get();
if (dsgTxn.getTransaction().isRead()) {
TxnType txnType = dsgTxn.getTransaction().getTxnType();
Promote promoteMode;
switch(txnType) {
case READ:
throw new JenaTransactionException("Attempt to update in a read transaction");
case WRITE:
// Impossible. We're in read-mode.
throw new TDBException("Internal inconsistency: read-mode write transaction");
case READ_PROMOTE:
promoteMode = Promote.ISOLATED;
break;
case READ_COMMITTED_PROMOTE:
promoteMode = Promote.READ_COMMITTED;
break;
default:
throw new TDBException("Internal inconsistency: null transaction type");
}
// Promotion.
boolean b = promoteStep(dsgTxn, promoteMode);
if (!b)
// Returning false makes no sense.
throw new JenaTransactionException("Can't promote " + txnType + "- dataset has been written to");
}
}
use of org.apache.jena.sparql.JenaTransactionException in project jena by apache.
the class TestDatasetPrefixes method dsg_prefixes_txn_2.
// Legacy: TDBTransactionException is not under JenaTransactionException.
@Test(expected = JenaException.class)
public void dsg_prefixes_txn_2() {
Assume.assumeTrue(txnIsolation);
DatasetGraph dsg = create();
Txn.executeRead(dsg, () -> {
PrefixMap pmap = dsg.prefixes();
try {
// Write inside read.
// TIM prefixes are standalone, MRSW so they are thread safe but not tied to the TIM transaction lifecycle.
// No Isolation.
pmap.add("ex", "http://example/2");
} catch (JenaTransactionException | TDBTransactionException ex) {
throw ex;
}
});
}
use of org.apache.jena.sparql.JenaTransactionException in project jena by apache.
the class AbstractTestTransPromote method run_05.
private void run_05(boolean readCommitted) {
Assume.assumeTrue(!readCommitted || supportsReadCommitted());
setReadCommitted(readCommitted);
DatasetGraph dsg = create();
dsg.begin(ReadWrite.READ);
dsg.add(q1);
try {
dsg.end();
fail("begin(W);end() did not throw an exception");
} catch (JenaTransactionException ex) {
}
assertCount(0, dsg);
}
use of org.apache.jena.sparql.JenaTransactionException in project jena by apache.
the class AbstractTestTransactionLifecycle method testCommitAbort.
private void testCommitAbort(ReadWrite mode) {
assumeTrue(supportsAbort());
Dataset ds = create();
ds.begin(mode);
ds.commit();
try {
ds.abort();
fail("Expected transaction exception - commit-abort(" + mode + ")");
} catch (JenaTransactionException ex) {
safeEnd(ds);
}
}
use of org.apache.jena.sparql.JenaTransactionException in project jena by apache.
the class AbstractTestTransactionLifecycle method testBeginBegin.
// Error conditions that should be detected.
private void testBeginBegin(ReadWrite mode1, ReadWrite mode2) {
Dataset ds = create();
ds.begin(mode1);
try {
ds.begin(mode2);
fail("Expected transaction exception - begin-begin (" + mode1 + ", " + mode2 + ")");
} catch (JenaTransactionException ex) {
safeEnd(ds);
}
}
Aggregations