One of the first AOP services ever implemented for JBoss AOP was transaction demarcation. Modelled directly after EJB, transaction demarcation allows you to delineate at the method level when a transactions should start or stop.. You can define transaction demarcation using the standard J2EE keywords on a plain java class: Required , RequiresNew, Supports, NotSupported, Never. There are two different ways to define it. One is through XML metadata, the other is through annotations. The transaction demarcation aspect is trigger by applying XML to a class or by annotating a method or constructor.
NOTE. Any exception that propagates through a transaction boundary will cause the transaction to become rolledback.
<aop> ... <metadata tag="transaction" class="com.acme.POJO"> <default> <trans-attribute>Required</trans-attribute> </default> <method name="get.*"> <trans-attribute>RequiresNew</trans-attribute> </method> <method name="someMethod3"> <trans-attribute>Supports</trans-attribute> </method> <method name="stuff"> <trans-attribute>Never</trans-attribute> </field> </metadata> </aop>
The default <trans-attribute> defines the default transaction attribute for the entire class. All get methods will use RequiresNew. The method someMethod3 will use Supports. The method stuff will Never start a transaction. So you see, its the same as J2EE EJB transactions except you're apply transaction demarcation to plain old Java Classes.
Tx Annotations with JDK 1.4
public class POJO { /** * @@org.jboss.aspects.tx.Tx (org.jboss.aspects.tx.TxType.REQUIRED) */ public POJO() {} /** * @@org.jboss.aspects.tx.Tx (org.jboss.aspects.tx.TxType.NEVER) */ public static void staticMethod() {} }
Tx Annotations with JDK 5.0
import org.jboss.aspects.tx.*; public class POJO { @Tx(TxType.REQUIRED) public POJO() {} @Tx(TxType.NEVER) public static void staticMethod() {} }