use of org.eclipse.scout.rt.platform.transaction.ITransactionMember in project scout.rt by eclipse.
the class RunContextTest method testTransactionMember_TxRequired_TxPresent.
@Test(expected = AssertionException.class)
public void testTransactionMember_TxRequired_TxPresent() {
final ITransactionMember txMember = mock(ITransactionMember.class);
RunContexts.empty().withTransactionScope(TransactionScope.REQUIRES_NEW).run(new IRunnable() {
@Override
public void run() throws Exception {
RunContexts.copyCurrent().withTransactionScope(TransactionScope.REQUIRED).withTransactionMember(txMember).run(mock(IRunnable.class));
}
});
}
use of org.eclipse.scout.rt.platform.transaction.ITransactionMember in project scout.rt by eclipse.
the class StatementProcessor method registerActiveStatement.
protected void registerActiveStatement(Statement s) throws SQLException {
ITransaction tx = ITransaction.CURRENT.get();
if (tx == null) {
return;
}
ITransactionMember member = tx.getMember(getCallerService().getTransactionMemberId());
if (member instanceof AbstractSqlTransactionMember) {
((AbstractSqlTransactionMember) member).registerActiveStatement(s);
}
}
use of org.eclipse.scout.rt.platform.transaction.ITransactionMember in project scout.rt by eclipse.
the class StatementProcessor method unregisterActiveStatement.
protected void unregisterActiveStatement(Statement s) {
ITransaction tx = ITransaction.CURRENT.get();
if (tx == null) {
return;
}
ITransactionMember member = tx.getMember(getCallerService().getTransactionMemberId());
if (member instanceof AbstractSqlTransactionMember) {
((AbstractSqlTransactionMember) member).unregisterActiveStatement(s);
}
}
use of org.eclipse.scout.rt.platform.transaction.ITransactionMember in project scout.rt by eclipse.
the class CallsView method renderCallDetail.
private void renderCallDetail(HtmlComponent p, CallInspector call) {
SimpleDateFormat startFmt = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
CallInfo info = call.getInfo();
//
p.startTable(0);
//
p.startTableRow();
p.tableCell("Service");
p.tableCell(info.getService());
p.endTableRow();
//
p.spacingRow(2);
//
p.startTableRow();
p.tableCell("Operation");
p.tableCell(info.getOperation());
p.endTableRow();
//
p.spacingRow(2);
//
p.startTableRow();
p.tableCell("Start");
p.tableCell(startFmt.format(new Date(info.getStartTime())));
p.endTableRow();
//
p.spacingRow(2);
//
p.startTableRow();
p.tableCell("End");
if (info.isActive()) {
p.tableCell("PENDING");
} else {
p.tableCell(startFmt.format(new Date(info.getEndTime())));
}
p.endTableRow();
//
p.spacingRow(2);
//
p.startTableRow();
p.tableCell("Duration");
p.tableCell(info.getDuration() + " ms");
p.endTableRow();
//
p.spacingRow(2);
//
p.startTableRow();
p.tableCell("XA resources");
p.startTableCell();
ITransactionMember[] xaresources = info.getXaResources();
renderValueTable(p, xaresources);
p.endTableCell();
p.endTableRow();
//
if (!info.isActive()) {
//
p.spacingRow(2);
//
p.startTableRow();
p.tableCell("Arguments");
p.startTableCell();
renderValueTable(p, info.getArguments());
p.endTableCell();
p.endTableRow();
if (info.getReturnException() == null) {
//
p.spacingRow(2);
//
p.startTableRow();
p.tableCell("Out variables");
p.startTableCell();
renderValueTable(p, info.getOutVariables());
p.endTableCell();
p.endTableRow();
//
p.spacingRow(2);
//
p.startTableRow();
p.tableCell("Return data");
p.startTableCell();
renderValueTable(p, new Object[] { info.getReturnData() });
p.endTableCell();
p.endTableRow();
} else {
StringWriter sw = new StringWriter();
info.getReturnException().printStackTrace(new PrintWriter(sw, true));
//
p.spacingRow(2);
//
p.startTableRow();
p.tableCell("Return exception");
p.tableCell(sw.toString());
p.endTableRow();
}
}
p.endTable();
}
use of org.eclipse.scout.rt.platform.transaction.ITransactionMember in project scout.rt by eclipse.
the class RunContextTest method testCopy.
@Test
public void testCopy() {
final Subject subject = newSubject("john");
final ITransaction tx = mock(ITransaction.class);
final ITransactionMember txMember1 = mock(ITransactionMember.class);
when(txMember1.getMemberId()).thenReturn("txMember1");
final ITransactionMember txMember2 = mock(ITransactionMember.class);
when(txMember2.getMemberId()).thenReturn("txMember2");
final RunMonitor monitor = new RunMonitor();
// prepare the RunContext to be copied
RunContext runContext = RunContexts.empty().withProperty("key", "value").withSubject(subject).withLocale(Locale.CANADA_FRENCH).withRunMonitor(monitor).withCorrelationId("cid").withTransaction(tx).withTransactionScope(TransactionScope.MANDATORY).withThreadLocal(THREAD_LOCAL, "thread-local");
// test
RunContext copy = runContext.copy();
// verify
assertEquals(toSet(runContext.getPropertyMap().iterator()), toSet(copy.getPropertyMap().iterator()));
assertSame(runContext.getSubject(), copy.getSubject());
assertSame(runContext.getLocale(), copy.getLocale());
assertSame(runContext.getRunMonitor(), copy.getRunMonitor());
assertEquals("cid", runContext.getCorrelationId());
assertSame(tx, runContext.getTransaction());
assertEquals("thread-local", runContext.getThreadLocal(THREAD_LOCAL));
// test running on the copy
copy.withTransactionScope(TransactionScope.REQUIRED).run(new IRunnable() {
@Override
public void run() throws Exception {
assertEquals("value", PropertyMap.CURRENT.get().get("key"));
assertSame(subject, Subject.getSubject(AccessController.getContext()));
assertEquals(Locale.CANADA_FRENCH, NlsLocale.CURRENT.get());
assertSame(monitor, RunMonitor.CURRENT.get());
assertEquals("cid", CorrelationId.CURRENT.get());
assertSame(tx, ITransaction.CURRENT.get());
assertEquals("thread-local", THREAD_LOCAL.get());
RunContexts.copyCurrent().run(new IRunnable() {
@Override
public void run() throws Exception {
assertEquals("value", PropertyMap.CURRENT.get().get("key"));
assertSame(subject, Subject.getSubject(AccessController.getContext()));
assertEquals(Locale.CANADA_FRENCH, NlsLocale.CURRENT.get());
assertNotSame(monitor, RunMonitor.CURRENT.get());
assertEquals("cid", CorrelationId.CURRENT.get());
assertSame(tx, ITransaction.CURRENT.get());
assertEquals("thread-local", THREAD_LOCAL.get());
}
});
RunContexts.empty().run(new IRunnable() {
@Override
public void run() throws Exception {
assertNull(PropertyMap.CURRENT.get().get("key"));
assertNull(Subject.getSubject(AccessController.getContext()));
assertNull(NlsLocale.CURRENT.get());
assertNotSame(monitor, RunMonitor.CURRENT.get());
assertNull(CorrelationId.CURRENT.get());
assertNotSame(tx, ITransaction.CURRENT.get());
assertEquals("thread-local", THREAD_LOCAL.get());
}
});
}
});
// test copy of transaction members
runContext.withTransactionScope(TransactionScope.REQUIRES_NEW).withTransactionMember(txMember1).withTransactionMember(txMember2).copy().run(new IRunnable() {
@Override
public void run() throws Exception {
assertSame(txMember1, ITransaction.CURRENT.get().getMember("txMember1"));
assertSame(txMember2, ITransaction.CURRENT.get().getMember("txMember2"));
}
});
}
Aggregations