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));
}
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);
}
}
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;
}
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();
}
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);
}
Aggregations