KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > ejb > odmg > PersonManagerODMGBean


1 package org.apache.ojb.ejb.odmg;
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.OJBRuntimeException;
22 import org.apache.ojb.broker.util.logging.Logger;
23 import org.apache.ojb.broker.util.logging.LoggerFactory;
24 import org.apache.ojb.ejb.PersonVO;
25 import org.odmg.OQLQuery;
26
27 /**
28  * Simple example bean for manage persons using the ODMG-api
29  * by subclassing {@link org.apache.ojb.ejb.odmg.ODMGBaseBeanImpl}
30  *
31  * @ejb:bean
32  * type="Stateless"
33  * name="PersonManagerODMGBean"
34  * jndi-name="org.apache.ojb.ejb.odmg.PersonManagerODMGBean"
35  * local-jndi-name="org.apache.ojb.ejb.odmg.PersonManagerODMGBeanLocal"
36  * view-type="both"
37  * transaction-type="Container"
38  *
39  * @ejb:interface
40  * remote-class="org.apache.ojb.ejb.odmg.PersonManagerODMGRemote"
41  * local-class="org.apache.ojb.ejb.odmg.PersonManagerODMGLocal"
42  * extends="javax.ejb.EJBObject"
43  *
44  * @ejb:home
45  * remote-class="org.apache.ojb.ejb.odmg.PersonManagerODMGHome"
46  * local-class="org.apache.ojb.ejb.odmg.PersonManagerODMGLocalHome"
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: PersonManagerODMGBean.java,v 1.4.2.1 2005/12/21 22:21:39 tomdz Exp $
55  */

56 public class PersonManagerODMGBean extends ODMGBaseBeanImpl implements SessionBean JavaDoc
57 {
58     private Logger log = LoggerFactory.getLogger(PersonManagerODMGBean.class);
59
60     public PersonManagerODMGBean()
61     {
62     }
63
64     /**
65      * @ejb:interface-method
66      */

67     public PersonVO storePerson(PersonVO person)
68     {
69         return (PersonVO) this.storeObject(person);
70     }
71
72     /**
73      * @ejb:interface-method
74      */

75     public Collection JavaDoc storePersons(Collection JavaDoc persons)
76     {
77         return this.storeObjects(persons);
78     }
79
80     /**
81      * @ejb:interface-method
82      */

83     public void deletePerson(PersonVO person)
84     {
85         this.deleteObject(person);
86     }
87
88     /**
89      * @ejb:interface-method
90      */

91     public void deletePersons(Collection JavaDoc persons)
92     {
93         this.deleteObjects(persons);
94     }
95
96     /**
97      * @ejb:interface-method
98      */

99     public int countPersons()
100     {
101         return this.getCount(PersonVO.class);
102     }
103
104     /**
105      * @ejb:interface-method
106      */

107     public Collection JavaDoc getAllPersons()
108     {
109         return this.getAllObjects(PersonVO.class);
110     }
111
112     /**
113      * @ejb:interface-method
114      */

115     public Collection JavaDoc getPersons(String JavaDoc firstname, String JavaDoc lastname)
116     {
117         OQLQuery query = getImplementation().newOQLQuery();
118         try
119         {
120             StringBuffer JavaDoc buf = new StringBuffer JavaDoc("select allObjects from " + PersonVO.class.getName());
121             buf.append(" where id not null");
122             if (firstname != null) buf.append(" and firstname = " + firstname);
123             if (lastname != null) buf.append(" and lastname = " + lastname);
124             query.create(buf.toString());
125             return (Collection JavaDoc) query.execute();
126         }
127         catch (Exception JavaDoc e)
128         {
129             log.error("OQLQuery failed", e);
130             throw new OJBRuntimeException("OQLQuery failed", e);
131         }
132     }
133 }
134
Popular Tags