1 package org.apache.ojb.ejb.odmg; 2 3 17 18 import javax.ejb.SessionBean ; 19 import java.util.Collection ; 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 56 public class PersonManagerODMGBean extends ODMGBaseBeanImpl implements SessionBean 57 { 58 private Logger log = LoggerFactory.getLogger(PersonManagerODMGBean.class); 59 60 public PersonManagerODMGBean() 61 { 62 } 63 64 67 public PersonVO storePerson(PersonVO person) 68 { 69 return (PersonVO) this.storeObject(person); 70 } 71 72 75 public Collection storePersons(Collection persons) 76 { 77 return this.storeObjects(persons); 78 } 79 80 83 public void deletePerson(PersonVO person) 84 { 85 this.deleteObject(person); 86 } 87 88 91 public void deletePersons(Collection persons) 92 { 93 this.deleteObjects(persons); 94 } 95 96 99 public int countPersons() 100 { 101 return this.getCount(PersonVO.class); 102 } 103 104 107 public Collection getAllPersons() 108 { 109 return this.getAllObjects(PersonVO.class); 110 } 111 112 115 public Collection getPersons(String firstname, String lastname) 116 { 117 OQLQuery query = getImplementation().newOQLQuery(); 118 try 119 { 120 StringBuffer buf = new StringBuffer ("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 ) query.execute(); 126 } 127 catch (Exception e) 128 { 129 log.error("OQLQuery failed", e); 130 throw new OJBRuntimeException("OQLQuery failed", e); 131 } 132 } 133 } 134 | Popular Tags |