Search in sources :

Example 1 with JenaTransactionException

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

Example 2 with JenaTransactionException

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

Example 3 with JenaTransactionException

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

Example 4 with JenaTransactionException

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

Example 5 with JenaTransactionException

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