@RequiresTransaction
The @RequiresTransaction annotation marks a method as requiring an
existing transaction. Unlike @Action, the annotation does not create, wrap or
rename a transaction. Instead it fails fast in development mode if the method is invoked without the required
transaction characteristics.
Use the annotation on helper methods that are only valid when called from an existing action, observer or
computable value. The @RequiresTransaction.mode parameter can
constrain the required transaction mode and the
@RequiresTransaction.tracking parameter can constrain
whether the existing transaction is tracking or non-tracking.
An example:
@ArezComponent
abstract class Wallet
{
private int _balance;
@Observable
int getBalance()
{
return _balance;
}
void setBalance( final int balance )
{
_balance = balance;
}
@Action
void deposit( final int amount )
{
currentBalance();
applyDelta( amount );
}
@RequiresTransaction
int currentBalance()
{
return getBalance();
}
@RequiresTransaction( mode = TransactionMode.READ_WRITE )
void applyDelta( final int delta )
{
setBalance( getBalance() + delta );
}
}