01: package com.mockrunner.example.ejb;
02:
03: import java.rmi.RemoteException;
04: import java.util.Collection;
05: import java.util.Iterator;
06:
07: import javax.ejb.CreateException;
08: import javax.ejb.EJBException;
09: import javax.ejb.SessionBean;
10: import javax.ejb.SessionContext;
11: import javax.naming.InitialContext;
12:
13: import com.mockrunner.example.ejb.interfaces.BillEntity;
14: import com.mockrunner.example.ejb.interfaces.BillEntityHome;
15:
16: /*
17: * @ejb:bean name="BillManagerSession"
18: * display-name="BillManagerSessionBean"
19: * type="Stateless"
20: * transaction-type="Container"
21: * jndi-name="de/test/BillManagerSession"
22: *
23: * @ejb:ejb-ref ejb-name="BillEntity" view-type="remote" ref-name="ejb/BillEntity"
24: **/
25: /**
26: * This simple EJB finds all {@link BillEntityBean} objects
27: * which are not paid and marks them as paid.
28: */
29: public class BillManagerSessionBean implements SessionBean {
30: private SessionContext sessionContext;
31:
32: /*
33: * @ejb:interface-method
34: * @ejb:transaction type="Required"
35: **/
36: public void markAsPaid() {
37: try {
38: InitialContext context = new InitialContext();
39: BillEntityHome home = (BillEntityHome) context
40: .lookup("java:comp/env/ejb/BillEntity");
41: Collection unpaid = home.findUnpaid();
42: Iterator unpaidIterator = unpaid.iterator();
43: while (unpaidIterator.hasNext()) {
44: BillEntity next = (BillEntity) unpaidIterator.next();
45: next.setPaid(true);
46: }
47: } catch (Exception exc) {
48: sessionContext.setRollbackOnly();
49: throw new EJBException(exc.getMessage());
50: }
51: }
52:
53: /*
54: * @ejb:create-method
55: **/
56: public void ejbCreate() throws CreateException {
57:
58: }
59:
60: public void ejbActivate() throws EJBException, RemoteException {
61:
62: }
63:
64: public void ejbPassivate() throws EJBException, RemoteException {
65:
66: }
67:
68: public void ejbRemove() throws EJBException, RemoteException {
69:
70: }
71:
72: public void setSessionContext(SessionContext sessionContext)
73: throws EJBException, RemoteException {
74: this.sessionContext = sessionContext;
75: }
76: }
|