use of javax.transaction.TransactionManager in project wildfly by wildfly.
the class TransactionSubsystemAdd method performBoottime.
@Override
protected void performBoottime(OperationContext context, ModelNode operation, ModelNode model) throws OperationFailedException {
checkIfNodeIdentifierIsDefault(context, model);
boolean jts = model.hasDefined(JTS) && model.get(JTS).asBoolean();
final Resource subsystemResource = context.readResourceFromRoot(PathAddress.pathAddress(TransactionExtension.SUBSYSTEM_PATH));
final List<ServiceName> deps = new LinkedList<>();
for (Resource.ResourceEntry re : subsystemResource.getChildren(CM_RESOURCE)) {
deps.add(TxnServices.JBOSS_TXN_CMR.append(re.getName()));
}
//recovery environment
performRecoveryEnvBoottime(context, model, jts, deps);
//core environment
performCoreEnvironmentBootTime(context, model);
//coordinator environment
performCoordinatorEnvBoottime(context, model, jts);
//object store
performObjectStoreBoottime(context, model);
//always propagate the transaction context
//TODO: need a better way to do this, but this value gets cached in a static
//so we need to make sure we set it before anything tries to read it
jtsPropertyManager.getJTSEnvironmentBean().setAlwaysPropagateContext(true);
context.addStep(new AbstractDeploymentChainStep() {
protected void execute(final DeploymentProcessorTarget processorTarget) {
processorTarget.addDeploymentProcessor(TransactionExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_TRANSACTION_ROLLBACK_ACTION, new TransactionLeakRollbackProcessor());
processorTarget.addDeploymentProcessor(TransactionExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_TRANSACTIONS_EE_CONCURRENCY, new EEConcurrencyContextHandleFactoryProcessor());
processorTarget.addDeploymentProcessor(TransactionExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_TRANSACTION_BINDINGS, new TransactionJndiBindingProcessor());
processorTarget.addDeploymentProcessor(TransactionExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_TRANSACTIONS, new TransactionDependenciesProcessor());
processorTarget.addDeploymentProcessor(TransactionExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_TRANSACTIONS, new CompensationsDependenciesDeploymentProcessor());
}
}, OperationContext.Stage.RUNTIME);
//bind the TransactionManger and the TSR into JNDI
final BinderService tmBinderService = new BinderService("TransactionManager");
final ServiceBuilder<ManagedReferenceFactory> tmBuilder = context.getServiceTarget().addService(ContextNames.JBOSS_CONTEXT_SERVICE_NAME.append("TransactionManager"), tmBinderService);
tmBuilder.addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, ServiceBasedNamingStore.class, tmBinderService.getNamingStoreInjector());
tmBuilder.addDependency(TransactionManagerService.SERVICE_NAME, javax.transaction.TransactionManager.class, new Injector<javax.transaction.TransactionManager>() {
@Override
public void inject(final javax.transaction.TransactionManager value) throws InjectionException {
tmBinderService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new ImmediateValue<Object>(value)));
}
@Override
public void uninject() {
tmBinderService.getManagedObjectInjector().uninject();
}
});
tmBuilder.install();
final BinderService tmLegacyBinderService = new BinderService("TransactionManager");
final ServiceBuilder<ManagedReferenceFactory> tmLegacyBuilder = context.getServiceTarget().addService(ContextNames.JAVA_CONTEXT_SERVICE_NAME.append("TransactionManager"), tmLegacyBinderService);
tmLegacyBuilder.addDependency(ContextNames.JAVA_CONTEXT_SERVICE_NAME, ServiceBasedNamingStore.class, tmLegacyBinderService.getNamingStoreInjector());
tmLegacyBuilder.addDependency(TransactionManagerService.SERVICE_NAME, javax.transaction.TransactionManager.class, new Injector<javax.transaction.TransactionManager>() {
@Override
public void inject(final javax.transaction.TransactionManager value) throws InjectionException {
tmLegacyBinderService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new ImmediateValue<Object>(value)));
}
@Override
public void uninject() {
tmLegacyBinderService.getManagedObjectInjector().uninject();
}
});
tmLegacyBuilder.install();
final BinderService tsrBinderService = new BinderService("TransactionSynchronizationRegistry");
final ServiceBuilder<ManagedReferenceFactory> tsrBuilder = context.getServiceTarget().addService(ContextNames.JBOSS_CONTEXT_SERVICE_NAME.append("TransactionSynchronizationRegistry"), tsrBinderService);
tsrBuilder.addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, ServiceBasedNamingStore.class, tsrBinderService.getNamingStoreInjector());
tsrBuilder.addDependency(TransactionSynchronizationRegistryService.SERVICE_NAME, TransactionSynchronizationRegistry.class, new Injector<TransactionSynchronizationRegistry>() {
@Override
public void inject(final TransactionSynchronizationRegistry value) throws InjectionException {
tsrBinderService.getManagedObjectInjector().inject(new ValueManagedReferenceFactory(new ImmediateValue<Object>(value)));
}
@Override
public void uninject() {
tsrBinderService.getManagedObjectInjector().uninject();
}
});
tsrBuilder.install();
// Install the UserTransactionAccessControlService
final UserTransactionAccessControlService lookupControlService = new UserTransactionAccessControlService();
context.getServiceTarget().addService(UserTransactionAccessControlService.SERVICE_NAME, lookupControlService).install();
// Bind the UserTransaction into JNDI
final UserTransactionBindingService userTransactionBindingService = new UserTransactionBindingService("UserTransaction");
final ServiceBuilder<ManagedReferenceFactory> utBuilder = context.getServiceTarget().addService(ContextNames.JBOSS_CONTEXT_SERVICE_NAME.append("UserTransaction"), userTransactionBindingService);
utBuilder.addDependency(ContextNames.JBOSS_CONTEXT_SERVICE_NAME, ServiceBasedNamingStore.class, userTransactionBindingService.getNamingStoreInjector()).addDependency(UserTransactionAccessControlService.SERVICE_NAME, UserTransactionAccessControlService.class, userTransactionBindingService.getUserTransactionAccessControlServiceInjector()).addDependency(UserTransactionService.SERVICE_NAME, UserTransaction.class, new ManagedReferenceInjector<UserTransaction>(userTransactionBindingService.getManagedObjectInjector()));
utBuilder.install();
// install the EE Concurrency transaction setup provider's service
final TransactionSetupProviderService transactionSetupProviderService = new TransactionSetupProviderService();
context.getServiceTarget().addService(ConcurrentServiceNames.TRANSACTION_SETUP_PROVIDER_SERVICE_NAME, transactionSetupProviderService).addDependency(TransactionManagerService.SERVICE_NAME, TransactionManager.class, transactionSetupProviderService.getTransactionManagerInjectedValue()).install();
}
use of javax.transaction.TransactionManager in project wildfly by wildfly.
the class TransactionRollbackSetupAction method changeDepth.
private boolean changeDepth(int increment) {
Holder holder = depth.get();
if (holder == null) {
//if there is a transaction active initially we just track the depth
//and don't actually close it, because we don't 'own' the transaction
//this can happen when running async listeners outside the context of a request
holder = new Holder();
try {
final TransactionManager tm = transactionManager.getOptionalValue();
if (tm != null) {
holder.actuallyCleanUp = !isTransactionActive(tm, tm.getStatus());
}
depth.set(holder);
} catch (Exception e) {
TransactionLogger.ROOT_LOGGER.unableToGetTransactionStatus(e);
}
}
holder.depth += increment;
if (holder.depth == 0) {
depth.set(null);
return holder.actuallyCleanUp;
}
return false;
}
use of javax.transaction.TransactionManager in project aries by apache.
the class TxDBServlet method doGet.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
pw = response.getWriter();
pw.write(LOGO_HEADER);
// Get the bundle context from ServletContext attributes
BundleContext ctx = (BundleContext) getServletContext().getAttribute(OSGI_BUNDLECONTEXT_ATTRIBUTE);
pw.println("<html>");
pw.println("<head>");
pw.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"tableTemplate.css\"/>");
pw.println("<body>");
pw.println("<h2 align=center><p><font face=\"Tahoma\">Sample Application for JDBC usage in JTA Transactions.</font></h2>");
pw.println("<p><p>");
ServiceReference tmServiceRef = ctx.getServiceReference("javax.transaction.TransactionManager");
ServiceReference derbyServiceRef = ctx.getServiceReference(DataSourceFactory.class.getName());
if (tmServiceRef == null || derbyServiceRef == null) {
pw.println("<font face=\"Tahoma\">TransactionManager or Derby driver are not available in the OSGI registry.</font><br>");
} else {
TransactionManager tm = (TransactionManager) ctx.getService(tmServiceRef);
DataSourceFactory derbyRegistry = (DataSourceFactory) ctx.getService(derbyServiceRef);
try {
// Set the needed properties for the database connection
Properties props = new Properties();
props.put(DataSourceFactory.JDBC_URL, "jdbc:derby:txDemo");
props.put(DataSourceFactory.JDBC_DATABASE_NAME, "txDemo");
props.put(DataSourceFactory.JDBC_USER, "");
props.put(DataSourceFactory.JDBC_PASSWORD, "");
XADataSource xaDataSource = derbyRegistry.createXADataSource(props);
pw.println("<center><form><table><tr><td align='right'>Value: </td><td align=left><input type='text' name='value' value='' size='12'/><input type='submit' name='action' value='InsertAndCommit' size='100'/></td></tr>");
pw.println("<tr><td align='right'>Value: </td><td align=left><input type='text' name='value' value='' size='12'/><input type='submit' name='action' value='InsertAndRollback' size='100'/></center></td></tr>");
pw.println("<tr colspan='2' align='center'><td> </td><td><input type='submit' name='action' value='cleanTable' size='100' /> <input type='submit' name='action' value='printTable' size='100'/></td><tr></table></form></center>");
String value = request.getParameter("value");
String action = request.getParameter("action");
if (action != null && action.equals("InsertAndCommit")) {
insertIntoTransaction(xaDataSource, tm, value, true);
} else if (action != null && action.equals("InsertAndRollback")) {
insertIntoTransaction(xaDataSource, tm, value, false);
} else if (action != null && action.equals("cleanTable")) {
cleanTable(xaDataSource);
}
printTable(xaDataSource);
} catch (Exception e) {
pw.println("<font face=\"Tahoma\">Unexpected exception occurred " + e.toString() + ".</font><br>");
e.printStackTrace(pw);
}
}
pw.println("</body>");
pw.println("</html>");
pw.flush();
}
use of javax.transaction.TransactionManager in project aries by apache.
the class BaseNameSpaceHandlerSetup method setUp.
@Before
public void setUp() throws InvalidSyntaxException {
control = EasyMock.createControl();
b = control.createMock(Bundle.class);
TransactionManager tm = control.createMock(TransactionManager.class);
Coordinator coordinator = control.createMock(Coordinator.class);
control.replay();
namespaceHandler = new TxNamespaceHandler();
namespaceHandler.setTm(tm);
namespaceHandler.setCoordinator(coordinator);
String[] namespaces = new String[] { "http://aries.apache.org/xmlns/transactions/v2.0.0" };
nhri = new DummyNamespaceHandlerRegistry();
nhri.addNamespaceHandlers(namespaces, namespaceHandler);
}
use of javax.transaction.TransactionManager in project aries by apache.
the class InterceptorTest method postCallWithTransaction.
private void postCallWithTransaction(Throwable th, boolean expectRollback, boolean failCoordination) throws Throwable {
IMocksControl c = EasyMock.createControl();
TransactionManager tm = c.createMock(TransactionManager.class);
Coordinator coordinator = c.createMock(Coordinator.class);
ComponentTxData txData = new ComponentTxData(AnnotatedPojo.class);
TxInterceptorImpl sut = new TxInterceptorImpl(tm, coordinator, txData);
Transaction tran = c.createMock(Transaction.class);
if (expectRollback) {
tran.setRollbackOnly();
EasyMock.expectLastCall();
}
Coordination coordination = c.createMock(Coordination.class);
coordination.end();
if (failCoordination) {
EasyMock.expectLastCall().andThrow(coordinationException(th));
} else {
EasyMock.expectLastCall();
}
c.replay();
TransactionToken tt = new TransactionToken(tran, null, TransactionAttribute.REQUIRED);
tt.setCoordination(coordination);
sut.postCallWithException(null, this.getClass().getMethods()[0], th, tt);
c.verify();
}
Aggregations