Search in sources :

Example 1 with TxnType

use of org.apache.jena.query.TxnType 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)

Example 2 with TxnType

use of org.apache.jena.query.TxnType 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 3 with TxnType

use of org.apache.jena.query.TxnType in project jena by apache.

the class DatasetGraphTransaction method promote.

@Override
public boolean promote() {
    Promote promoteMode = Promote.ISOLATED;
    TxnType txnType = transactionType();
    if (txnType == TxnType.READ_COMMITTED_PROMOTE)
        promoteMode = Promote.READ_COMMITTED;
    return promote(promoteMode);
}
Also used : TxnType(org.apache.jena.query.TxnType)

Aggregations

TxnType (org.apache.jena.query.TxnType)3 JenaTransactionException (org.apache.jena.sparql.JenaTransactionException)2 TDBException (org.apache.jena.tdb.TDBException)1