001: package org.apache.ojb.ejb.pb;
002:
003: /* Copyright 2004-2005 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: import javax.ejb.SessionBean;
019: import java.util.Collection;
020:
021: import org.apache.ojb.broker.PersistenceBroker;
022: import org.apache.ojb.broker.query.Criteria;
023: import org.apache.ojb.broker.query.Query;
024: import org.apache.ojb.broker.query.QueryByCriteria;
025: import org.apache.ojb.ejb.PersonVO;
026:
027: /**
028: * Simple example bean for manage persons using the PB-api
029: * by subclassing {@link org.apache.ojb.ejb.pb.PBBaseBeanImpl}
030: *
031: * @ejb:bean
032: * type="Stateless"
033: * name="PersonManagerPBBean"
034: * jndi-name="org.apache.ojb.ejb.pb.pb.PersonManagerPBBean"
035: * local-jndi-name="org.apache.ojb.ejb.pb.PersonManagerPBBeanLocal"
036: * view-type="both"
037: * transaction-type="Container"
038: *
039: * @ejb:interface
040: * remote-class="org.apache.ojb.ejb.pb.PersonManagerPBRemote"
041: * local-class="org.apache.ojb.ejb.pb.PersonManagerPBLocal"
042: * extends="javax.ejb.EJBObject"
043: *
044: * @ejb:home
045: * remote-class="org.apache.ojb.ejb.pb.PersonManagerPBHome"
046: * local-class="org.apache.ojb.ejb.pb.PersonManagerPBLocalHome"
047: * extends="javax.ejb.EJBHome"
048: *
049: * @ejb:transaction
050: * type="Required"
051: *
052: *
053: * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
054: * @version $Id: PersonManagerPBBean.java,v 1.4.2.2 2005/12/21 22:21:38 tomdz Exp $
055: */
056: public class PersonManagerPBBean extends PBBaseBeanImpl implements
057: SessionBean {
058: /**
059: * @ejb:interface-method
060: */
061: public PersonVO storePerson(PersonVO person) {
062: return (PersonVO) this .storeObject(person);
063: }
064:
065: /**
066: * @ejb:interface-method
067: */
068: public Collection storePersons(Collection persons) {
069: return this .storeObjects(persons);
070: }
071:
072: /**
073: * @ejb:interface-method
074: */
075: public void deletePerson(PersonVO person) {
076: this .deleteObject(person);
077: }
078:
079: /**
080: * @ejb:interface-method
081: */
082: public void deletePersons(Collection persons) {
083: this .deleteObjects(persons);
084: }
085:
086: /**
087: * @ejb:interface-method
088: */
089: public int countPersons() {
090: return this .getCount(PersonVO.class);
091: }
092:
093: /**
094: * @ejb:interface-method
095: */
096: public Collection getAllPersons() {
097: return this .getAllObjects(PersonVO.class);
098: }
099:
100: /**
101: * @ejb:interface-method
102: */
103: public Collection getPersons(String firstname, String lastname) {
104: PersistenceBroker broker = getBroker();
105: Criteria criteria = new Criteria();
106: if (firstname != null)
107: criteria.addEqualTo("firstname", firstname);
108: if (lastname != null)
109: criteria.addEqualTo("firstname", lastname);
110: Query q = new QueryByCriteria(PersonVO.class);
111: Collection result = broker.getCollectionByQuery(q);
112: broker.close();
113: return result;
114: }
115: }
|