KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > ejb > pb > PersonManagerPBBean


1 package org.apache.ojb.ejb.pb;
2
3 /* Copyright 2004-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import javax.ejb.SessionBean JavaDoc;
19 import java.util.Collection JavaDoc;
20
21 import org.apache.ojb.broker.PersistenceBroker;
22 import org.apache.ojb.broker.query.Criteria;
23 import org.apache.ojb.broker.query.Query;
24 import org.apache.ojb.broker.query.QueryByCriteria;
25 import org.apache.ojb.ejb.PersonVO;
26
27 /**
28  * Simple example bean for manage persons using the PB-api
29  * by subclassing {@link org.apache.ojb.ejb.pb.PBBaseBeanImpl}
30  *
31  * @ejb:bean
32  * type="Stateless"
33  * name="PersonManagerPBBean"
34  * jndi-name="org.apache.ojb.ejb.pb.pb.PersonManagerPBBean"
35  * local-jndi-name="org.apache.ojb.ejb.pb.PersonManagerPBBeanLocal"
36  * view-type="both"
37  * transaction-type="Container"
38  *
39  * @ejb:interface
40  * remote-class="org.apache.ojb.ejb.pb.PersonManagerPBRemote"
41  * local-class="org.apache.ojb.ejb.pb.PersonManagerPBLocal"
42  * extends="javax.ejb.EJBObject"
43  *
44  * @ejb:home
45  * remote-class="org.apache.ojb.ejb.pb.PersonManagerPBHome"
46  * local-class="org.apache.ojb.ejb.pb.PersonManagerPBLocalHome"
47  * extends="javax.ejb.EJBHome"
48  *
49  * @ejb:transaction
50  * type="Required"
51  *
52  *
53  * @author <a HREF="mailto:armin@codeAuLait.de">Armin Waibel</a>
54  * @version $Id: PersonManagerPBBean.java,v 1.4.2.2 2005/12/21 22:21:38 tomdz Exp $
55  */

56 public class PersonManagerPBBean extends PBBaseBeanImpl implements SessionBean JavaDoc
57 {
58     /**
59      * @ejb:interface-method
60      */

61     public PersonVO storePerson(PersonVO person)
62     {
63         return (PersonVO) this.storeObject(person);
64     }
65
66     /**
67      * @ejb:interface-method
68      */

69     public Collection JavaDoc storePersons(Collection JavaDoc persons)
70     {
71         return this.storeObjects(persons);
72     }
73
74     /**
75      * @ejb:interface-method
76      */

77     public void deletePerson(PersonVO person)
78     {
79         this.deleteObject(person);
80     }
81
82     /**
83      * @ejb:interface-method
84      */

85     public void deletePersons(Collection JavaDoc persons)
86     {
87         this.deleteObjects(persons);
88     }
89
90     /**
91      * @ejb:interface-method
92      */

93     public int countPersons()
94     {
95         return this.getCount(PersonVO.class);
96     }
97
98     /**
99      * @ejb:interface-method
100      */

101     public Collection JavaDoc getAllPersons()
102     {
103         return this.getAllObjects(PersonVO.class);
104     }
105
106     /**
107      * @ejb:interface-method
108      */

109     public Collection JavaDoc getPersons(String JavaDoc firstname, String JavaDoc lastname)
110     {
111         PersistenceBroker broker = getBroker();
112         Criteria criteria = new Criteria();
113         if (firstname != null) criteria.addEqualTo("firstname", firstname);
114         if (lastname != null) criteria.addEqualTo("firstname", lastname);
115         Query q = new QueryByCriteria(PersonVO.class);
116         Collection JavaDoc result = broker.getCollectionByQuery(q);
117         broker.close();
118         return result;
119     }
120 }
121
Popular Tags