Search in sources :

Example 16 with JenaTransactionException

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");
    }
}
Also used : TxnType(org.apache.jena.query.TxnType) TDBException(org.apache.jena.tdb.TDBException) JenaTransactionException(org.apache.jena.sparql.JenaTransactionException)

Example 17 with JenaTransactionException

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;
        }
    });
}
Also used : PrefixMap(org.apache.jena.riot.system.PrefixMap) JenaTransactionException(org.apache.jena.sparql.JenaTransactionException) TDBTransactionException(org.apache.jena.tdb.transaction.TDBTransactionException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 18 with JenaTransactionException

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);
}
Also used : JenaTransactionException(org.apache.jena.sparql.JenaTransactionException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 19 with JenaTransactionException

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);
    }
}
Also used : Dataset(org.apache.jena.query.Dataset) JenaTransactionException(org.apache.jena.sparql.JenaTransactionException)

Example 20 with JenaTransactionException

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);
    }
}
Also used : Dataset(org.apache.jena.query.Dataset) JenaTransactionException(org.apache.jena.sparql.JenaTransactionException)

Aggregations

JenaTransactionException (org.apache.jena.sparql.JenaTransactionException)23 Dataset (org.apache.jena.query.Dataset)10 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)3 TxnType (org.apache.jena.query.TxnType)2 PrefixMap (org.apache.jena.riot.system.PrefixMap)1 TDBException (org.apache.jena.tdb.TDBException)1 TDBTransactionException (org.apache.jena.tdb.transaction.TDBTransactionException)1 Test (org.junit.Test)1