use of org.teiid.client.xa.XATransactionException in project teiid by teiid.
the class Request method getTransactionContext.
TransactionContext getTransactionContext(boolean startAutoWrap) throws TeiidComponentException {
if (this.transactionContext != null) {
return this.transactionContext;
}
TransactionContext tc = transactionService.getOrCreateTransactionContext(workContext.getSessionId());
if (tc.getTransactionType() == TransactionContext.Scope.REQUEST && this.workContext.isDerived()) {
// to a sub-request, request scope should appear as global - which means associated and non-suspendable
tc = tc.clone();
tc.setTransactionType(TransactionContext.Scope.INHERITED);
}
// $NON-NLS-1$
Assertion.assertTrue(tc.getTransactionType() != TransactionContext.Scope.REQUEST, "Transaction already associated with request.");
// If local or global transaction is not started.
if (tc.getTransactionType() == Scope.NONE && !requestMsg.isNoExec()) {
if (!startAutoWrap) {
return null;
}
Boolean startAutoWrapTxn = false;
if (RequestMessage.TXN_WRAP_ON.equals(requestMsg.getTxnAutoWrapMode())) {
startAutoWrapTxn = true;
} else if (RequestMessage.TXN_WRAP_DETECT.equals(requestMsg.getTxnAutoWrapMode())) {
boolean transactionalRead = requestMsg.getTransactionIsolation() == Connection.TRANSACTION_REPEATABLE_READ || requestMsg.getTransactionIsolation() == Connection.TRANSACTION_SERIALIZABLE;
startAutoWrapTxn = processPlan.requiresTransaction(transactionalRead);
if (startAutoWrapTxn == null) {
startAutoWrapTxn = false;
}
}
if (startAutoWrapTxn) {
try {
transactionService.begin(tc);
} catch (XATransactionException err) {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30493, err);
}
}
}
tc.setIsolationLevel(requestMsg.getTransactionIsolation());
this.transactionContext = tc;
return this.transactionContext;
}
use of org.teiid.client.xa.XATransactionException in project teiid by teiid.
the class RequestWorkItem method close.
/**
* Client close is currently implemented as asynch.
* Any errors that occur will not make it to the client, instead we just log them here.
*/
protected void close() {
long rowcount = -1;
try {
cancelCancelTask();
if (moreWorkTask != null) {
moreWorkTask.cancel(false);
moreWorkTask = null;
}
if (this.resultsBuffer != null) {
if (this.processor != null) {
try {
CommandContext.pushThreadLocalContext(this.processor.getContext());
this.processor.closeProcessing();
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_DQP, MessageLevel.DETAIL)) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_DQP, "Removing tuplesource for the request " + requestID);
}
rowcount = resultsBuffer.getRowCount();
if (this.cid == null || !this.doneProducingBatches) {
resultsBuffer.remove();
}
for (DataTierTupleSource connectorRequest : getConnectorRequests()) {
connectorRequest.fullyCloseSource();
}
CommandContext cc = this.processor.getContext();
cc.close();
} catch (Throwable t) {
// guard against unexpected exceptions in close
handleThrowable(t);
} finally {
CommandContext.popThreadLocalContext();
}
}
this.resultsBuffer = null;
if (!this.lobStreams.isEmpty()) {
List<LobWorkItem> lobs = null;
synchronized (lobStreams) {
lobs = new ArrayList<LobWorkItem>(this.lobStreams.values());
}
for (LobWorkItem lobWorkItem : lobs) {
lobWorkItem.close();
}
}
}
boolean isActive = false;
if (this.transactionState == TransactionState.ACTIVE) {
isActive = true;
this.transactionState = TransactionState.DONE;
}
if (transactionContext != null) {
if (transactionContext.getTransactionType() == TransactionContext.Scope.REQUEST) {
if (!isActive) {
LogManager.logWarning(LogConstants.CTX_DQP, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31200, transactionContext.getTransactionId()));
}
try {
this.transactionService.rollback(transactionContext);
} catch (XATransactionException e1) {
LogManager.logWarning(LogConstants.CTX_DQP, e1, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30028));
}
} else if (transactionContext.getTransactionType() != TransactionContext.Scope.NONE) {
suspend();
}
}
synchronized (this) {
if (this.processingException == null && this.resultsReceiver != null) {
// sanity check to ensure that something will be sent to the client
setCanceledException();
}
}
} catch (Throwable t) {
handleThrowable(t);
} finally {
isClosed = true;
dqpCore.removeRequest(this);
if (this.processingException != null) {
sendError();
}
dqpCore.logMMCommand(this, Event.END, rowcount, this.timer.stop());
}
}
use of org.teiid.client.xa.XATransactionException in project teiid by teiid.
the class ForEachRowPlan method close.
@Override
public void close() throws TeiidComponentException {
if (this.queryProcessor != null) {
this.queryProcessor.closeProcessing();
if (this.rowProcessor != null) {
this.rowProcessor.closeProcessing();
}
}
if (this.planContext != null) {
TransactionService ts = this.getContext().getTransactionServer();
try {
ts.resume(planContext);
ts.rollback(planContext);
this.planContext = null;
} catch (XATransactionException e) {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30165, e);
}
}
}
use of org.teiid.client.xa.XATransactionException in project teiid by teiid.
the class ProcedurePlan method pop.
/**
* @param success
* @throws TeiidComponentException
* @throws XATransactionException
*/
public void pop(boolean success) throws TeiidComponentException {
this.evaluator.close();
Program program = this.programs.pop();
VariableContext vc = this.currentVarContext;
VariableContext cs = this.cursorStates;
try {
this.currentVarContext = this.currentVarContext.getParentContext();
this.cursorStates = this.cursorStates.getParentContext();
TempTableStore tempTableStore = program.getTempTableStore();
this.getContext().setTempTableStore(tempTableStore.getParentTempTableStore());
tempTableStore.removeTempTables();
if (program.startedTxn()) {
TransactionService ts = this.getContext().getTransactionServer();
TransactionContext tc = this.blockContext;
this.blockContext = null;
try {
ts.resume(tc);
for (WeakReference<DataTierTupleSource> ref : txnTupleSources) {
DataTierTupleSource dtts = ref.get();
if (dtts != null) {
dtts.fullyCloseSource();
}
}
this.txnTupleSources.clear();
if (success) {
ts.commit(tc);
} else {
ts.rollback(tc);
}
} catch (XATransactionException e) {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30165, e);
}
}
} finally {
removeAllCursors(cs);
}
}
use of org.teiid.client.xa.XATransactionException in project teiid by teiid.
the class BatchedUpdatePlan method close.
/**
* @see org.teiid.query.processor.ProcessorPlan#close()
* @since 4.2
*/
public void close() throws TeiidComponentException {
// if the plan opened but the atomic request got cancelled then close the last plan node.
TransactionService ts = this.getContext().getTransactionServer();
if (planIndex < updatePlans.length && planOpened[planIndex]) {
try {
updatePlans[planIndex].close();
} catch (TeiidComponentException e) {
LogManager.logWarning(LogConstants.CTX_DQP, e, e.getMessage());
}
if (this.planContexts[planIndex] != null) {
try {
ts.resume(this.planContexts[planIndex]);
ts.rollback(this.planContexts[planIndex]);
} catch (XATransactionException e) {
LogManager.logWarning(LogConstants.CTX_DQP, e, e.getMessage());
}
this.planContexts[planIndex] = null;
}
}
}
Aggregations