Transactional Capabilities
in Oracle9iAS Containers for J2EE (OC4J)
Date: 22-Jul-2002
1. Declarative Transaction - Sample
Code Snippet
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>HotelInformationHome</ejb-name>
<home>HotelInformationHome</home>
<remote>HotelInformation</remote>
<ejb-class>HotelInformationBean</ejb-class>
<session-type>Stateless</session-type>
transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
transaction-type = Specify who will take care of transaction. Value
may be either Container or Bean.
2. Programmatic Transaction -
Sample Code Snippet
javax.transaction.UserTransaction userTransaction=m_ctx.getUserTransaction();
try{
userTransaction.begin();
...........................
......................... // Bussiness Logic
userTransaction.commit();
}catch(Exception e){
if(userTransaction!=null) userTransaction.rollback();
throw e;
}
m_ctx = javax.ejb.SessionContext
3. Transactional Attribute - Sample
Code Snippet
<ejb-jar>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>ReservationAgentHome</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Supports</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
ejb-name = JNDI name of the ejb
method-name = Business method which is to be under transaction. Here "*"
means all methods in ReservationAgentHome bean are
under transaction with Supports attribute.