01: package org.mockejb.test.entity;
02:
03: import java.util.Collection;
04: import java.util.Iterator;
05:
06: import javax.ejb.*;
07:
08: public abstract class PersonBean implements EntityBean {
09:
10: private EntityContext context = null;
11:
12: public Object ejbCreate(String firstName, String lastName) {
13: setFirstName(firstName);
14: setLastName(lastName);
15:
16: return null;
17: }
18:
19: public void ejbPostCreate(String firstName, String lastName) {
20: }
21:
22: public abstract String getFirstName();
23:
24: public abstract void setFirstName(String firstName);
25:
26: public abstract String getLastName();
27:
28: public abstract void setLastName(String lastName);
29:
30: // CMR
31:
32: public abstract Collection getAddresses();
33:
34: public abstract void setAddresses(Collection addresses);
35:
36: /**
37: * Returns the PK of this bean.
38: * @return the unique id of the Person bean
39: */
40: public abstract long getId();
41:
42: /**
43: * Sets the id of this bean. Container generates and sets it for us,
44: * so this method is not exposed on the business interface.
45: */
46: public abstract void setId(long id);
47:
48: /**
49: * Example of the ejbSelect method
50: * @return all person beans in the database
51: */
52: public abstract Collection ejbSelectAll() throws FinderException;
53:
54: /**
55: * Example of the ejbHome method.
56: * It iterates through all persons and changes "Smit" to "Smith".
57: * If calls ejbSelectAll to get all records from the database.
58: */
59: public void ejbHomeUpdateNames() throws FinderException {
60:
61: // get all people
62: Collection people = ejbSelectAll();
63: Iterator i = people.iterator();
64: // Change Smit to Smith
65: while (i.hasNext()) {
66: Person person = (Person) i.next();
67: if (person.getLastName().equals("Smit")) {
68: person.setLastName("Smith");
69: }
70: }
71:
72: }
73:
74: // Lifecycle Methods
75: public void setEntityContext(EntityContext c) {
76: context = c;
77: }
78:
79: public void unsetEntityContext() {
80: context = null;
81: }
82:
83: public void ejbRemove() throws RemoveException {
84: }
85:
86: public void ejbActivate() {
87: }
88:
89: public void ejbPassivate() {
90: }
91:
92: public void ejbStore() {
93: }
94:
95: public void ejbLoad() {
96: }
97:
98: }
|