use of org.teiid.dqp.service.TransactionContext in project teiid by teiid.
the class TransactionServerImpl method commit.
/**
* Local Transaction
*/
public void commit(String threadId) throws XATransactionException {
TransactionContext tc = checkLocalTransactionState(threadId, true);
commitDirect(tc);
}
use of org.teiid.dqp.service.TransactionContext in project teiid by teiid.
the class TransactionServerImpl method start.
/**
* Global Transaction
*/
public void start(final String threadId, final XidImpl xid, int flags, int timeout, boolean singleTM) throws XATransactionException {
TransactionContext tc = null;
switch(flags) {
case XAResource.TMNOFLAGS:
{
try {
checkXAState(threadId, xid, false, false);
tc = transactions.getOrCreateTransactionContext(threadId);
if (tc.getTransactionType() != TransactionContext.Scope.NONE) {
throw new XATransactionException(QueryPlugin.Event.TEIID30517, XAException.XAER_PROTO, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30517));
}
tc.setTransactionTimeout(timeout);
tc.setXid(xid);
tc.setTransactionType(TransactionContext.Scope.GLOBAL);
if (singleTM) {
tc.setTransaction(transactionManager.getTransaction());
if (tc.getTransaction() == null) {
// in theory we could inflow the txn and then change all of the methods to check singleTM off of the context
throw new XATransactionException(QueryPlugin.Event.TEIID30590, XAException.XAER_INVAL, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30590));
}
} else {
FutureWork<Transaction> work = new FutureWork<Transaction>(new Callable<Transaction>() {
@Override
public Transaction call() throws Exception {
return transactionManager.getTransaction();
}
}, 0);
workManager.doWork(work, WorkManager.INDEFINITE, tc, null);
tc.setTransaction(work.get());
}
} catch (NotSupportedException e) {
throw new XATransactionException(QueryPlugin.Event.TEIID30512, XAException.XAER_INVAL, e);
} catch (WorkException e) {
throw new XATransactionException(QueryPlugin.Event.TEIID30512, XAException.XAER_INVAL, e);
} catch (InterruptedException e) {
throw new XATransactionException(QueryPlugin.Event.TEIID30512, XAException.XAER_INVAL, e);
} catch (ExecutionException e) {
throw new XATransactionException(QueryPlugin.Event.TEIID30512, XAException.XAER_INVAL, e);
} catch (SystemException e) {
throw new XATransactionException(QueryPlugin.Event.TEIID30512, XAException.XAER_INVAL, e);
}
break;
}
case XAResource.TMJOIN:
case XAResource.TMRESUME:
{
tc = checkXAState(threadId, xid, true, false);
TransactionContext threadContext = transactions.getOrCreateTransactionContext(threadId);
if (threadContext.getTransactionType() != TransactionContext.Scope.NONE) {
throw new XATransactionException(QueryPlugin.Event.TEIID30517, XAException.XAER_PROTO, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30517));
}
if (flags == XAResource.TMRESUME && !tc.getSuspendedBy().remove(threadId)) {
throw new XATransactionException(QueryPlugin.Event.TEIID30518, XAException.XAER_PROTO, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30518, new Object[] { xid, threadId }));
}
break;
}
default:
throw new XATransactionException(QueryPlugin.Event.TEIID30519, XAException.XAER_INVAL, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30519));
}
tc.setThreadId(threadId);
transactions.addTransactionContext(tc);
}
use of org.teiid.dqp.service.TransactionContext in project teiid by teiid.
the class DQPCore method logMMCommand.
void logMMCommand(RequestWorkItem workItem, Event status, Long rowCount, Long cpuTime) {
if ((status != Event.PLAN && !LogManager.isMessageToBeRecorded(LogConstants.CTX_COMMANDLOGGING, MessageLevel.INFO)) || (status == Event.PLAN && !LogManager.isMessageToBeRecorded(LogConstants.CTX_COMMANDLOGGING, MessageLevel.TRACE))) {
return;
}
RequestMessage msg = workItem.requestMsg;
DQPWorkContext workContext = DQPWorkContext.getWorkContext();
RequestID rID = workItem.requestID;
String txnID = null;
TransactionContext tc = workItem.getTransactionContext();
if (tc != null && tc.getTransactionType() != Scope.NONE) {
txnID = tc.getTransactionId();
}
String appName = workContext.getAppName();
// Log to request log
CommandLogMessage message = null;
if (status == Event.NEW) {
message = new CommandLogMessage(System.currentTimeMillis(), rID.toString(), txnID, workContext.getSessionId(), appName, workContext.getUserName(), workContext.getVdbName(), workContext.getVdbVersion(), msg.getCommandString(), cpuTime);
} else {
QueryProcessor qp = workItem.getProcessor();
PlanNode plan = null;
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_COMMANDLOGGING, MessageLevel.TRACE) && qp != null) {
plan = qp.getProcessorPlan().getDescriptionProperties();
}
message = new CommandLogMessage(System.currentTimeMillis(), rID.toString(), txnID, workContext.getSessionId(), workContext.getUserName(), workContext.getVdbName(), workContext.getVdbVersion(), rowCount, status, plan);
}
LogManager.log(status == Event.PLAN ? MessageLevel.TRACE : MessageLevel.INFO, LogConstants.CTX_COMMANDLOGGING, message);
}
use of org.teiid.dqp.service.TransactionContext in project teiid by teiid.
the class TestProcErrors method testNestedBeginAtomicException.
@Test
public void testNestedBeginAtomicException() throws Exception {
TransformationMetadata tm = RealMetadataFactory.example1Cached();
String query = "BEGIN atomic\n" + " declare string VARIABLES.RESULT;\n" + " begin atomic select 1/0; exception e end end";
ProcessorPlan plan = getProcedurePlan(query, tm);
// Create expected results
List<?>[] expected = new List[0];
// $NON-NLS-1$
CommandContext context = new CommandContext("pID", null, null, null, 1);
QueryMetadataInterface metadata = new TempMetadataAdapter(tm, new TempMetadataStore());
context.setMetadata(metadata);
TransactionContext tc = new TransactionContext();
Transaction txn = Mockito.mock(Transaction.class);
tc.setTransaction(txn);
tc.setTransactionType(Scope.REQUEST);
TransactionService ts = Mockito.mock(TransactionService.class);
context.setTransactionService(ts);
context.setTransactionContext(tc);
TestProcessor.helpProcess(plan, context, new HardcodedDataManager(), expected);
Mockito.verify(txn, Mockito.times(3)).setRollbackOnly();
}
use of org.teiid.dqp.service.TransactionContext in project teiid by teiid.
the class TempTableStore method getSynchronization.
private TempTableSynchronization getSynchronization(CommandContext context) throws TeiidProcessingException {
TempTableSynchronization synch = null;
if (context == null || transactionMode == TransactionMode.NONE) {
return null;
}
TransactionContext tc = context.getTransactionContext();
if (tc == null || tc.getTransactionType() == Scope.NONE) {
return null;
}
String transactionId = tc.getTransactionId();
synch = synchronizations.get(transactionId);
if (synch == null) {
boolean success = false;
try {
synch = new TempTableSynchronization(transactionId);
synchronizations.put(transactionId, synch);
tc.getTransaction().registerSynchronization(synch);
success = true;
} catch (RollbackException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30223, e);
} catch (SystemException e) {
throw new TeiidProcessingException(QueryPlugin.Event.TEIID30224, e);
} finally {
if (!success) {
synchronizations.remove(transactionId);
}
}
}
return synch;
}
Aggregations