use of javax.transaction.TransactionManager in project spring-framework by spring-projects.
the class JtaTransactionManagerTests method jtaTransactionManagerWithPropagationRequiresNewAndAdapter.
@Test
public void jtaTransactionManagerWithPropagationRequiresNewAndAdapter() throws Exception {
TransactionManager tm = mock(TransactionManager.class);
Transaction tx = mock(Transaction.class);
given(tm.getStatus()).willReturn(Status.STATUS_ACTIVE);
given(tm.suspend()).willReturn(tx);
JtaTransactionManager ptm = newJtaTransactionManager(tm);
TransactionTemplate tt = new TransactionTemplate(ptm);
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
}
});
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
verify(tm).begin();
verify(tm).commit();
verify(tm).resume(tx);
}
use of javax.transaction.TransactionManager in project spring-framework by spring-projects.
the class JtaTransactionManagerTests method jtaTransactionManagerWithPropagationRequiresNewAndExistingWithSuspendException.
@Test
public void jtaTransactionManagerWithPropagationRequiresNewAndExistingWithSuspendException() throws Exception {
UserTransaction ut = mock(UserTransaction.class);
TransactionManager tm = mock(TransactionManager.class);
given(ut.getStatus()).willReturn(Status.STATUS_ACTIVE);
willThrow(new SystemException()).given(tm).suspend();
JtaTransactionManager ptm = newJtaTransactionManager(ut, tm);
TransactionTemplate tt = new TransactionTemplate(ptm);
tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
try {
tt.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
assertTrue(TransactionSynchronizationManager.isSynchronizationActive());
}
});
fail("Should have thrown TransactionSystemException");
} catch (TransactionSystemException ex) {
// expected
}
assertFalse(TransactionSynchronizationManager.isSynchronizationActive());
}
use of javax.transaction.TransactionManager in project wildfly by wildfly.
the class TransactionBuilder method getValue.
@Override
public TransactionConfiguration getValue() {
TransactionManager tm = this.tm.getOptionalValue();
this.builder.transactionManagerLookup((tm != null) ? new TransactionManagerProvider(tm) : null);
TransactionSynchronizationRegistry tsr = this.tsr.getOptionalValue();
this.builder.transactionSynchronizationRegistryLookup((tsr != null) ? new TransactionSynchronizationRegistryProvider(tsr) : null);
return this.builder.create();
}
use of javax.transaction.TransactionManager in project wildfly by wildfly.
the class MessageEndpointInvocationHandler method beforeDelivery.
@Override
public void beforeDelivery(Method method) throws NoSuchMethodException, ResourceException {
// JCA 1.6 FR 13.5.6
// The application server must set the thread context class loader to the endpoint
// application class loader during the beforeDelivery call.
previousClassLoader = WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(getApplicationClassLoader());
try {
final TransactionManager tm = getTransactionManager();
// TODO: in violation of JCA 1.6 FR 13.5.9?
previousTx = tm.suspend();
boolean isTransacted = service.isDeliveryTransacted(method);
if (isTransacted) {
tm.begin();
currentTx = tm.getTransaction();
if (xaRes != null)
currentTx.enlistResource(xaRes);
}
} catch (Throwable t) {
throw new ApplicationServerInternalException(t);
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(previousClassLoader);
}
}
use of javax.transaction.TransactionManager in project wildfly by wildfly.
the class BMTInterceptor method processInvocation.
@Override
public Object processInvocation(final InterceptorContext context) throws Exception {
TransactionManager tm = component.getTransactionManager();
int oldTimeout = getCurrentTransactionTimeout(component);
try {
Transaction oldTx = tm.suspend();
try {
return handleInvocation(context);
} finally {
if (oldTx != null)
tm.resume(oldTx);
}
} finally {
tm.setTransactionTimeout(oldTimeout == -1 ? 0 : oldTimeout);
}
}
Aggregations