...
| Code Block | ||
|---|---|---|
| ||
UnitOrWork unitOfWork = UnitOfWork.begin();
try {
AddressBook book = new AddressBook(...);
unitOfWork.registerNew(book);
book.addContact(contact);
unitOfWork.registerDirty(book);
unitOfWork.commit();
}
catch(Exception e) {
unitOfWork.rollback();
}
finally {
unitOfWork.dispose();
}
|
and still all the transaction and persistence management will take place.
...
The UnitOfWorkProtocol aspect has four abstract pointcuts that you have to define in your XML definition aop.xml file (a "transactional object" is an object that is set to participate in the Unit Of Work transaction, meaning that the Unit Of Work will keep track of its state):
txRequires- picks out all points in the code where you want a TX REQUIRES transaction to begin, commit and rollbacktxRequiresNew- picks out all points in the code where you want a TX REQUIRES_NEW transaction to begin, commit and rollbacktxSupports- picks out all points in the code where you want a TX SUPPORTS transaction to begin, commit and rollbacktxMandatory- picks out all points in the code where you want a TX MANDATORY transaction to begin, commit and rollbacktxNever- picks out all points in the code where you want a TX NEVER transaction to begin, commit and rollbacktransactionalObjects- picks out all transactional object, this pointcut is used by the Transactional MixintransactionalObjectCreationPoints- picks out all points in the code where a transactional object is createdtransactionalObjectModificationPoints- picks out all points in the code where a transactional object is being modified (best done with aset(...)pointcut)
...
| Code Block | ||
|---|---|---|
| ||
<aspect class="org.codehaus.aware.unitofwork.UnitOfWorkProtocol">
<pointcut name="txSupports" expression="execution(* org.codehaus.aware.app.service.*.*(..))"/>
<pointcut name="txMandatorytxRequires" expression="execution(* org.codehaus.aware.app.domain.*.*(..))"/>
<pointcut name="transactionalObjects" expression="class(org.codehaus.aware.app.domain.*)"/>
<pointcut name="transactionalObjectCreationPoints" expression="call(org.codehaus.aware.app.domain.*.new(..))"/>
<pointcut name="transactionalObjectModificationPoints" expression="set(* org.codehaus.aware.app.domain.*.*)"/>
</aspect>
|
