Service Component Architecture (SCA) provides declarative mechanisms in the form of intents for describing the transactional environment required by components.
<component name="DataAccessComponent"> <implementation.java class="example.DataAccessImpl" requires="managedTransaction.global"/> </component>
For implementation.spring components, specify the transaction attribute in the Spring application context file. For implementation.jee components, specify the transaction attribute in the Enterprise JavaBeans (EJB) deployment descriptor.
Specify the propagatesTransaction or suspendsTransaction intent on the component's <service> element only for services in implementation.java components. For implementation.spring components, specify the transaction attribute in the Spring application context file. For implementation.jee components, specify the transaction attribute in the EJB deployment descriptor.
You can specify the propagatesTransaction or suspendsTransaction intent on the component's <reference> element for references in all implementation types.
Transaction context is never propagated on @OneWay methods. The SCA run time ignores propagatesTransaction for OneWay methods.
Further, the product does not support propagatesTransaction intent on the binding.atom or binding.jsonrpc elements.
<component name="DataUpdateComponent"> <implementation.java class="example.DataUpdateImpl" requires="managedTransaction.global"/> <service name="DataUpdateService" requires="suspendsTransaction"/> <reference name="myDataAccess" target="DataAccessComponent" requires="propagatesTransaction"/> </component>
<composite name="WSDataUpdateComposite" xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:ws="http://www.ibm.com/xmlns/prod/websphere/sca/1.0/2007/06"> <component name="WSDataUpdateComponent"> <implementation.java class="example.DataUpdateImpl" requires="managedTransaction.global"/> <service name="DataUpdateService" requires="propagatesTransaction"> <binding.ws ws:wsPolicySet="WSTransaction"/> </service> <reference name="myDataBuddy" target="DataBuddyComponent" requires="propagatesTransaction"> <binding.ws ws:wsPolicySet="WSTransaction"/> </reference> </component> </composite>
Business logic might have to access transactional resource managers without the presence of a global transaction. A component can be configured to run under local transaction containment (LTC). The SCA runtime starts an LTC before dispatching a method on the component and completes the LTC at the end of the method dispatch. The component's interactions with resource providers (such as databases) are managed within resource manager local transactions (RMLTs). A resource manager local transaction (RMLT) represents a unit of recovery on a single connection that is managed by the resource manager.
<component name="DataAccessLocalComponent"> <implementation.java class="example.DataAccessImpl" requires="managedTransaction.local"/> </component>
A local transaction cannot be propagated from one component to another. It is an error to specify propagatesTransaction on a component's <service> if the component uses the managedTransaction.local or noManagedTransaction intent.
Rollback
com.ibm.websphere.uow.UOWSynchronizationRegistry uowSyncRegistry = com.ibm.wsspi.uow.UOWManagerFactory.getUOWManager(); uowSyncRegistry.setRollbackOnly();
If transactional intents are not specified, the default behavior is vendor-specific. If a transactional intent in not specified for the implementation, the default is managedTransaction.global. If a transactional intent is not specified for a service or reference, the default is suspendsTransaction. It is recommended to specify the required intents rather than to rely on default behavior so that the application is portable.
You can also specify transaction intents in the implementation class by using the @Requires annotation. The general form of the annotation is:
@Requires("{http://www.osoa.org/xmlns/sca/1.0}intent")
@Requires("{http://www.osoa.org/xmlns/sca/1.0}managedTransaction.global")
You can specify required intents on various elements, including the composite, component, implementation, service and reference elements. An element inherits the required intents of its parent element except when they conflict. For example, if a composite element requires managedTranaction.global and a component element requires managedTransaction.local, then the component uses managedTransaction.local.
You cannot use the @Requires annotation for implementation.spring components.
The following table contains information from Section 5.3 of the SCA Java EE Integration specification and lists the mapping of SCA intents on services to EJB or Spring transaction attributes.
EJB transaction attribute | SCA Transaction Policy required intents on services | SCA Transaction Policy required intents on implementations |
---|---|---|
NOT_SUPPORTED | suspendsTransaction | |
REQUIRED | propagatesTransaction | managedTransaction.global |
SUPPORTS | propagatesTransaction | managedTransaction.global |
REQUIRES_NEW | suspendsTransaction | managedTransaction.global |
MANDATORY | propagatesTransaction | managedTransaction.global |
NEVER | suspendsTransaction |
For MANDATORY and NEVER attributes, policy mapping might not be accurate. These attributes express responsibilities of the EJB container as well as the EJB implementer rather then express a requirement on the service consumer.
The product does not support local JNDI lookups in Spring applications that are referenced from SCA components. Thus, you cannot use <tx:jta-transaction-manager/> in the Spring application context file to obtain the WebSphere transaction manager.
To obtain the WebSphere transaction manager, add the following definition explicitly to the Spring application-context.xml file:
<bean id="WASTranMgr" class="com.ibm.wsspi.uow.UOWManagerFactory" factory-method="getUOWManager"/> <bean id="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager"> <property name="uowManager" ref="WASTranMgr"/> <property name="autodetectUserTransaction" value="false"/> </bean>