use of org.teiid.dqp.service.TransactionContext in project teiid by teiid.
the class TestTransactionServer method testRequestCancel.
@Test
public void testRequestCancel() throws Exception {
TransactionContext tc = server.getOrCreateTransactionContext(THREAD1);
server.begin(tc);
server.cancelTransactions(THREAD1, true);
Mockito.verify(txn).setRollbackOnly();
}
use of org.teiid.dqp.service.TransactionContext in project teiid by teiid.
the class ForEachRowPlan method nextBatch.
@Override
public TupleBatch nextBatch() throws BlockedException, TeiidComponentException, TeiidProcessingException {
if (planContext != null) {
this.getContext().getTransactionServer().resume(planContext);
}
try {
while (true) {
if (currentTuple == null) {
if (nextTuple != null) {
currentTuple = nextTuple;
} else if (!nextNull) {
currentTuple = tupleSource.nextTuple();
}
if (currentTuple == null) {
if (this.planContext != null) {
TransactionService ts = this.getContext().getTransactionServer();
ts.commit(this.planContext);
this.planContext = null;
}
TupleBatch result = new TupleBatch(1, new List[] { Arrays.asList((int) Math.min(Integer.MAX_VALUE, updateCount)) });
result.setTerminationFlag(true);
return result;
}
}
if (first) {
TransactionContext tc = this.getContext().getTransactionContext();
if (this.planContext == null && tc != null && tc.getTransactionType() == Scope.NONE) {
Boolean txnRequired = rowProcedure.requiresTransaction(false);
boolean start = false;
if (txnRequired == null) {
nextTuple = tupleSource.nextTuple();
if (nextTuple != null) {
start = true;
} else {
nextNull = true;
}
} else if (Boolean.TRUE.equals(txnRequired)) {
start = true;
}
if (start) {
this.getContext().getTransactionServer().begin(tc);
this.planContext = tc;
}
}
first = false;
}
if (this.rowProcessor == null) {
rowProcedure.reset();
CommandContext context = getContext().clone();
this.rowProcessor = new QueryProcessor(rowProcedure, context, this.bufferMgr, this.dataMgr);
Evaluator eval = new Evaluator(lookupMap, dataMgr, context);
for (Map.Entry<ElementSymbol, Expression> entry : this.params.entrySet()) {
Integer index = this.lookupMap.get(entry.getValue());
if (index != null) {
rowProcedure.getCurrentVariableContext().setValue(entry.getKey(), this.currentTuple.get(index));
} else {
rowProcedure.getCurrentVariableContext().setValue(entry.getKey(), eval.evaluate(entry.getValue(), this.currentTuple));
}
}
}
// save the variable context to get the key information
VariableContext vc = rowProcedure.getCurrentVariableContext();
// just getting the next batch is enough
this.rowProcessor.nextBatch();
if (insert) {
assignGeneratedKey(vc);
}
this.rowProcessor.closeProcessing();
this.rowProcessor = null;
this.currentTuple = null;
this.updateCount++;
}
} finally {
if (planContext != null) {
this.getContext().getTransactionServer().suspend(planContext);
}
}
}
use of org.teiid.dqp.service.TransactionContext in project teiid by teiid.
the class ProcedurePlan method push.
public void push(Program program) throws XATransactionException {
this.evaluator.close();
program.reset(this.getContext().getConnectionId());
program.setTrappingExceptions(program.getExceptionGroup() != null || (!this.programs.isEmpty() && this.programs.peek().isTrappingExceptions()));
TempTableStore tts = getTempTableStore();
getContext().setTempTableStore(program.getTempTableStore());
program.getTempTableStore().setParentTempTableStore(tts);
this.programs.push(program);
VariableContext context = new VariableContext(true);
context.setParentContext(this.currentVarContext);
this.currentVarContext = context;
VariableContext cc = new VariableContext(true);
cc.setParentContext(this.cursorStates);
this.cursorStates = cc;
if (program.isAtomic() && this.blockContext == null) {
TransactionContext tc = this.getContext().getTransactionContext();
if (tc != null && tc.getTransactionType() == Scope.NONE && Boolean.TRUE.equals(program.instructionsRequireTransaction(false))) {
// start a transaction
this.getContext().getTransactionServer().begin(tc);
this.blockContext = tc;
program.setStartedTxn(true);
}
}
}
use of org.teiid.dqp.service.TransactionContext in project teiid by teiid.
the class BatchedUpdatePlan method openPlan.
private void openPlan() throws TeiidComponentException, TeiidProcessingException {
// reset prior to updating the context
updatePlans[planIndex].reset();
if (this.contexts != null && !this.contexts.isEmpty()) {
CommandContext context = updatePlans[planIndex].getContext();
VariableContext vc = context.getVariableContext();
// this is just a safe guard against the plan not correctly resetting the context
while (vc.getParentContext() != null) {
vc = vc.getParentContext();
}
vc.clear();
VariableContext currentValues = this.contexts.get(planIndex);
vc.putAll(currentValues);
}
TransactionContext tc = this.getContext().getTransactionContext();
if (startTxn[planIndex] && tc != null && tc.getTransactionType() == Scope.NONE) {
this.getContext().getTransactionServer().begin(tc);
this.planContexts[planIndex] = tc;
}
updatePlans[planIndex].open();
planOpened[planIndex] = true;
}
use of org.teiid.dqp.service.TransactionContext in project teiid by teiid.
the class TransactionServerImpl method end.
/**
* Global Transaction
*/
public void end(final String threadId, XidImpl xid, int flags, boolean singleTM) throws XATransactionException {
TransactionContext tc = checkXAState(threadId, xid, true, true);
try {
switch(flags) {
case XAResource.TMSUSPEND:
{
tc.getSuspendedBy().add(threadId);
break;
}
case XAResource.TMSUCCESS:
{
// TODO: should close all statements
break;
}
case XAResource.TMFAIL:
{
cancelTransactions(threadId, false);
break;
}
default:
throw new XATransactionException(QueryPlugin.Event.TEIID30520, XAException.XAER_INVAL, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30520));
}
} finally {
tc.setThreadId(null);
transactions.removeTransactionContext(threadId);
}
}
Aggregations