001: package org.apache.ojb.ejb.odmg;
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.OJBRuntimeException;
022: import org.apache.ojb.broker.util.logging.Logger;
023: import org.apache.ojb.broker.util.logging.LoggerFactory;
024: import org.apache.ojb.ejb.PersonVO;
025: import org.odmg.OQLQuery;
026:
027: /**
028: * Simple example bean for manage persons using the ODMG-api
029: * by subclassing {@link org.apache.ojb.ejb.odmg.ODMGBaseBeanImpl}
030: *
031: * @ejb:bean
032: * type="Stateless"
033: * name="PersonManagerODMGBean"
034: * jndi-name="org.apache.ojb.ejb.odmg.PersonManagerODMGBean"
035: * local-jndi-name="org.apache.ojb.ejb.odmg.PersonManagerODMGBeanLocal"
036: * view-type="both"
037: * transaction-type="Container"
038: *
039: * @ejb:interface
040: * remote-class="org.apache.ojb.ejb.odmg.PersonManagerODMGRemote"
041: * local-class="org.apache.ojb.ejb.odmg.PersonManagerODMGLocal"
042: * extends="javax.ejb.EJBObject"
043: *
044: * @ejb:home
045: * remote-class="org.apache.ojb.ejb.odmg.PersonManagerODMGHome"
046: * local-class="org.apache.ojb.ejb.odmg.PersonManagerODMGLocalHome"
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: PersonManagerODMGBean.java,v 1.4.2.1 2005/12/21 22:21:39 tomdz Exp $
055: */
056: public class PersonManagerODMGBean extends ODMGBaseBeanImpl implements
057: SessionBean {
058: private Logger log = LoggerFactory
059: .getLogger(PersonManagerODMGBean.class);
060:
061: public PersonManagerODMGBean() {
062: }
063:
064: /**
065: * @ejb:interface-method
066: */
067: public PersonVO storePerson(PersonVO person) {
068: return (PersonVO) this .storeObject(person);
069: }
070:
071: /**
072: * @ejb:interface-method
073: */
074: public Collection storePersons(Collection persons) {
075: return this .storeObjects(persons);
076: }
077:
078: /**
079: * @ejb:interface-method
080: */
081: public void deletePerson(PersonVO person) {
082: this .deleteObject(person);
083: }
084:
085: /**
086: * @ejb:interface-method
087: */
088: public void deletePersons(Collection persons) {
089: this .deleteObjects(persons);
090: }
091:
092: /**
093: * @ejb:interface-method
094: */
095: public int countPersons() {
096: return this .getCount(PersonVO.class);
097: }
098:
099: /**
100: * @ejb:interface-method
101: */
102: public Collection getAllPersons() {
103: return this .getAllObjects(PersonVO.class);
104: }
105:
106: /**
107: * @ejb:interface-method
108: */
109: public Collection getPersons(String firstname, String lastname) {
110: OQLQuery query = getImplementation().newOQLQuery();
111: try {
112: StringBuffer buf = new StringBuffer(
113: "select allObjects from "
114: + PersonVO.class.getName());
115: buf.append(" where id not null");
116: if (firstname != null)
117: buf.append(" and firstname = " + firstname);
118: if (lastname != null)
119: buf.append(" and lastname = " + lastname);
120: query.create(buf.toString());
121: return (Collection) query.execute();
122: } catch (Exception e) {
123: log.error("OQLQuery failed", e);
124: throw new OJBRuntimeException("OQLQuery failed", e);
125: }
126: }
127: }
|