|
Page 1 of 3
SCBCD Study Notes : Chapter 3 : Session Bean Component Contract (Part 1)
Please find the Study Notes and resources which covers the 1st Part of Chapter 3 : Session Bean Component Contract, as part of the Sun Certified Business Component Developer exam CX-310-090.
- Identify correct and incorrect statements or examples about session beans, including conversational state, the SessionBean interface, and create methods.
.
- Identify the use and the behavior of the ejbPassivate method in a session bean, including the responsibilities of both the container and the bean provider.
.
- Identify the interface and method for each of the following: retrieve the session bean's remote home interface, retrieve the session bean's local component interface, determine if the session bean's caller has a particular role, allow the instance to mark the current transaction as a rollback, retrieve the UserTransaction interface, prepare the instance for reuse following passivation, release resources prior to removal, identify the invoker of the bean instance's component interface, be notified that a new transaction has begun, and be notified that the current transaction has completed.
Chapter 3 : Session Bean Component Contract (Part 1)
Identify correct and incorrect statements or examples about session beans, including conversational state, the SessionBean interface, and create methods.
Session bean is specified at deployment as having one of the following state management modes:
- STATELESS — the session bean instances contain no conversational state between methods; any instance can be used for any client.
.
- STATEFUL — the session bean instances contain conversational state which must be retained across methods and transactions.
The conversational state of a STATEFUL session object is defined as the session bean instance’s field values.
In advanced cases, a session object’s conversational state may contain open resources, such as open sockets and open database cursors. A container cannot retain such open resources when a session bean instance is passivated. A developer of such a session bean must close and open the resources in the ejbPassivate and ejbActivate notifications.
All session beans must implement the SessionBean interface.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
public interface SessionBean extends EnterpriseBean { ;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;void ejbActivate() throws EJBException, RemoteException; ;;;;;;;;;;;;;;
;;;;;;;void ejbPassivate() throws EJBException, RemoteException; ;;;;;;;;;;;;;
;;;;;;;void ejbRemove() throws EJBException, RemoteException; ;;;;;;;;;;;;;;;;
;;;;;;;void setSessionContext(SessionContext ctx) throws EJBException, ;;;;;;;
;;;;;;;RemoteException; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
};;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
public interface EnterpriseBean extends Serializable { ;;;;;;;;;;;;;;;;;;;;;;;
};;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
A client creates a session bean instance using one of the create methods defined in the session bean’s home interface:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
public interface CartHome extends javax.ejb.EJBHome {;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;CartRemote create(String customerName, String account);;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;throws RemoteException, BadAccountException,;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;CreateException;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;CartRemote createLargeCart(String customerName, String account);;;;;;;;
;;;;;;;;;;;;;;throws RemoteException, BadAccountException,;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;CreateException;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
};;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.....;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CartRemote cart = cartHome.create(“John”, “7506”);;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
or for LOCAL view:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
public interface CartHome extends javax.ejb.EJBLocalHome {;;;;;;;;;;;;;;;;;;;;
;;;;;;;CartLocal create(String customerName, String account);;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;throws BadAccountException, CreateException;;;;;;;;;;;;;;;;;;;;;
;;;;;;;CartLocal createLargeCart(String customerName, String account);;;;;;;;;
;;;;;;;;;;;;;;throws BadAccountException, CreateException;;;;;;;;;;;;;;;;;;;;;
};;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
..... ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CartLocal cart = cartHome.create(“John”, “7506”); ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
The container creates an instance of a session bean in three steps:
- The container calls the bean class’ newInstance() method to create a new session bean instance.
.
- The container calls the setSessionContext(context) method to pass the context object to the instance.
.
- The container calls the instance’s ejbCreate< METHOD >() method whose signature matches the signature of the create< METHOD >() method invoked by the client.
Each session bean class must have at LEAST one ejbCreate< METHOD >() method (NOTE: for Entity Beans create methods are optional).
Invoking create() method by client on home interface of STATELESS session bean will NOT invoke ejbCreate() method on bean object. It only creates new EJB(Local)Object. ejbCreate() on STATELESS session bean is invoked by EJB container when it decides to put object in method-ready pool. For STATELESS session beans container handles creating of instances.
Invoking remove() method by client on home interface of STATELESS session bean will NOT invoke ejbRemove() method on bean object. It does nothing. ejbRemove() on STATELESS session bean is invoked by EJB container when it decides to remove object from method-ready pool. For STATELESS session beans container handles removing of instances.
Invoking create< METHOD >() method by client on home interface of STATEFUL session bean will invoke ejbCreate< METHOD >() method on bean object. More precisely: newInstance(), setSessionContext(context), ejbCreate< METHOD >([ARGS]).
Invoking remove() method by client on home interface of STATEFUL session bean will invoke ejbRemove() method on bean object.
The home interface of a STATELESS session bean must have one (and ONLY one) create() method that takes NO arguments.
The create() method of the remote home interface must return the session bean’s remote interface. The create method of the local home interface must return the session bean’s local interface.
STATELESS session bean CAN have instance variables, but there is no guarantee, that these variables will be accessed by the same client. However, the instance variables of the instance can contain the state across client-invoked method calls. Examples of such states include an open database connection and an object reference to an EJB object.
A STATELESS session bean MUST NOT implement the javax.ejb.SessionSynchronization interface.
|