Previous Next vertical dots separating previous/next from contents/index/pdf

Control Transactions

Ordinary control methods, event set methods, and web service control callback methods are transaction-enabled. This topic provides an overview of transaction support in controls.

Transaction Behavior

The transaction behavior of a method, event set method, or callback method is specified by the @TransactionAttribute annotation. The following example shows a web service callback decorated with @TransactionAttribute.

public interface MyServiceControl extends ServiceControl

    @ServiceControl.SOAPBinding(style = ServiceControl.SOAPBinding.Style.RPC, use = ServiceControl.SOAPBinding.Use.ENCODED)
    public interface Callback    {
        public void onCallback(java.lang.String message);
    public void requestCallback(); 

In the above example, TransactionAttributeType.REQUIRES means that if a transaction was already started in the callback thread, that transaction will be used; otherwise a new transaction will be started just before the callback method is called. Depending on the result of the operation, the transaction could either be committed, rolled-back, or marked as rollback (if started elsewhere).

The @TransactionAttribute has 6 legal settings:

Exception Handling

Checked exceptions (those exceptions that are a sub-class of Exception, not RuntimeException) are handled differently from other exceptions.

You can control the response to checked exceptions with the annotation attribute rollbackOnCheckedException:

    @TransactionAttribute( rollbackOnCheckedException=<boolean> )

If rollbackOnCheckedException is true, then the transaction will be rolled back (or be marked for rollback) when a control method or callback method results in a checked exception. By default, rollbackOnCheckedException is set to false. The default behavior is that a transaction will not be automatically rolled back, even if the method/callback invocation results in a checked exception being thrown. If invoking a control method/callback results in a system exception (exceptions that are a sub-class of java.lang.RuntimeException and java.lang.Error), the transaction will be rolled back (or marked for rollback) automatically.

Related Topics



Skip navigation bar   Back to Top