Search in sources :

Example 21 with JenaTransactionException

use of org.apache.jena.sparql.JenaTransactionException in project jena by apache.

the class AbstractTestTransactionLifecycle method testAbortAbort.

private void testAbortAbort(ReadWrite mode) {
    assumeTrue(supportsAbort());
    Dataset ds = create();
    ds.begin(mode);
    ds.abort();
    try {
        ds.abort();
        fail("Expected transaction exception - abort-abort(" + mode + ")");
    } catch (JenaTransactionException ex) {
        ds.end();
    }
}
Also used : Dataset(org.apache.jena.query.Dataset) JenaTransactionException(org.apache.jena.sparql.JenaTransactionException)

Example 22 with JenaTransactionException

use of org.apache.jena.sparql.JenaTransactionException in project jena by apache.

the class Transaction method close.

/**
 * transaction close happens after commit/abort
 *  read transactions "auto commit" on close().
 *  write transactions must call abort or commit.
 */
public void close() {
    // Log.info(this, "Peek = "+peekCount+"; count = "+count);
    JenaTransactionException throwThis = null;
    synchronized (this) {
        switch(state) {
            case CLOSED:
                // Can call close() repeatedly.
                return;
            case ACTIVE:
                if (mode == ReadWrite.READ) {
                    commit();
                    outcome = TxnOutcome.R_CLOSED;
                } else {
                    // Application error: begin(WRITE)...end() with no commit() or abort().
                    abort();
                    String msg = "end() called for WRITE transaction without commit or abort having been called. This causes a forced abort.";
                    throwThis = new JenaTransactionException(msg);
                // Keep going to clear up.
                }
                break;
            default:
        }
        state = TxnState.CLOSED;
        // Clear per-transaction temporary state.
        if (iterators != null)
            iterators.clear();
    }
    // Called once.
    txnMgr.notifyClose(this);
    if (throwThis != null)
        throw throwThis;
}
Also used : JenaTransactionException(org.apache.jena.sparql.JenaTransactionException)

Example 23 with JenaTransactionException

use of org.apache.jena.sparql.JenaTransactionException in project jena by apache.

the class TransactionalNull method begin.

@Override
public void begin(TxnType type) {
    if (inTransaction.get())
        throw new JenaTransactionException("Already in transaction");
    inTransaction.set(true);
    txnType.set(type);
    txnMode.set(TxnType.initial(type));
}
Also used : 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