Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.9.4. Demarcation by Declarative Transactions
Overview Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
You can also demarcate transactions by declaring transaction policies in your blueprint XML file. By applying the appropriate transaction policy to a bean or bean method (for example, the
Required policy), you can ensure that a transaction is started whenever that particular bean or bean method is invoked. At the end of the bean method, the transaction will be committed. (This approach is analogous to the way that transactions are dealt with in Enterprise Java Beans).
OSGi declarative transactions enable you to define transaction policies at the following scopes in your blueprint file:
Bean-level declaration Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
To declare transaction policies at the bean level, insert a
tx:transaction element as a child of the bean element, as follows:
In the preceding example, the
Required transaction policy is applied to all methods of the accountFoo bean and the accountBar bean (where the method attribute specifies the wildcard, *, to match all bean methods).
Top-level declaration Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
To declare transaction policies at the top level, insert a
tx:transaction element as a child of the blueprint element, as follows:
In the preceding example, the
Required transaction policy is applied to all methods of every bean whose ID matches the pattern, account*.
tx:transaction attributes Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
The
tx:transaction element supports the following attributes:
bean- (Top-level only) Specifies a list of bean IDs (comma or space separated) to which the transaction policy applies. For example:
<blueprint ...> <tx:transaction bean="accountFoo,accountBar" value="..."/> </blueprint><blueprint ...> <tx:transaction bean="accountFoo,accountBar" value="..."/> </blueprint>Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can also use the wildcard character, *, which may appear at most once in each list entry. For example:<blueprint ...> <tx:transaction bean="account*,jms*" value="..."/> </blueprint><blueprint ...> <tx:transaction bean="account*,jms*" value="..."/> </blueprint>Copy to Clipboard Copied! Toggle word wrap Toggle overflow If thebeanattribute is omitted, it defaults to*(matching all non-synthetic beans in the blueprint file). method- (Top-level and bean-level) Specifies a list of method names (comma or space separated) to which the transaction policy applies. For example:
<bean id="accountFoo" class="org.fusesource.example.Account"> <tx:transaction method="debit,credit,transfer" value="Required"/> <property name="accountName" value="Foo"/> </bean><bean id="accountFoo" class="org.fusesource.example.Account"> <tx:transaction method="debit,credit,transfer" value="Required"/> <property name="accountName" value="Foo"/> </bean>Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can also use the wildcard character, *, which may appear at most once in each list entry.If themethodattribute is omitted, it defaults to*(matching all methods in the applicable beans). value- (Top-level and bean-level) Specifies the transaction policy. The policy values have the same semantics as the policies defined in the EJB 3.0 specification, as follows:
Required—support a current transaction; create a new one if none exists.Mandatory—support a current transaction; throw an exception if no current transaction exists.RequiresNew—create a new transaction, suspending the current transaction if one exists.Supports—support a current transaction; execute non-transactionally if none exists.NotSupported—do not support a current transaction; rather always execute non-transactionally.Never—do not support a current transaction; throw an exception if a current transaction exists.