Search in sources :

Example 6 with JenaTransactionException

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

the class DatasetGraphInMemory method begin.

@Override
public void begin(TxnType txnType) {
    if (isInTransaction())
        throw new JenaTransactionException("Transactions cannot be nested!");
    transactionType.set(txnType);
    _begin(txnType, TxnType.initial(txnType));
}
Also used : JenaTransactionException(org.apache.jena.sparql.JenaTransactionException)

Example 7 with JenaTransactionException

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

the class TxnCounter method begin.

private void begin(TxnType txnType, boolean canBlock) {
    // (Readers never block at this point.)
    if (txnType == TxnType.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 (transactionMode.get() != null)
            throw new JenaTransactionException("Already in a transaction");
        // Set transaction to current epoch - writes advance this in commit().
        transactionEpoch.set(epoch.get());
        IntegerState state = new IntegerState(value.get());
        transactionValue.set(state);
        transactionMode.set(TxnType.initial(txnType));
        transactionType.set(txnType);
    }
}
Also used : JenaTransactionException(org.apache.jena.sparql.JenaTransactionException)

Example 8 with JenaTransactionException

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

the class TxnCounter method promote.

@Override
public boolean promote(Promote promoteMode) {
    checkTxn();
    if (transactionMode.get() == ReadWrite.WRITE)
        return true;
    if (transactionType.get() == TxnType.READ)
        throw new JenaTransactionException("Attempt to promote a READ transsction");
    if (promoteMode == Promote.READ_COMMITTED) {
        // READ_COMMITTED_PROMOTE
        acquireWriterLock(true);
        transactionMode.set(ReadWrite.WRITE);
        IntegerState state = new IntegerState(value.get());
        transactionValue.set(state);
        return true;
    }
    // READ_PROMOTE
    acquireWriterLock(true);
    synchronized (txnLifecycleLock) {
        long nowEpoch = epoch.get();
        if (transactionEpoch.get() != nowEpoch) {
            // Can't.
            releaseWriterLock();
            return false;
        }
        // Can.
        transactionMode.set(ReadWrite.WRITE);
    }
    return true;
}
Also used : JenaTransactionException(org.apache.jena.sparql.JenaTransactionException)

Example 9 with JenaTransactionException

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

the class TxnCounter method releaseWriterLock.

private void releaseWriterLock() {
    int x = writersWaiting.availablePermits();
    if (x != 0)
        throw new JenaTransactionException("TransactionCoordinator: Probably mismatch of enable/disableWriter calls");
    writersWaiting.release();
}
Also used : JenaTransactionException(org.apache.jena.sparql.JenaTransactionException)

Example 10 with JenaTransactionException

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

the class AbstractTestTransPromote method run_05.

private void run_05(TxnType txnType) {
    DatasetGraph dsg = create();
    dsg.begin(txnType);
    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)

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