01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.sample.petclinic.ojb;
18:
19: import java.util.Collection;
20:
21: import org.apache.ojb.broker.query.Criteria;
22: import org.apache.ojb.broker.query.Query;
23: import org.apache.ojb.broker.query.QueryByCriteria;
24: import org.compass.sample.petclinic.Clinic;
25: import org.compass.sample.petclinic.Owner;
26: import org.compass.sample.petclinic.Pet;
27: import org.compass.sample.petclinic.PetType;
28: import org.compass.sample.petclinic.Vet;
29: import org.compass.sample.petclinic.Visit;
30: import org.springframework.dao.DataAccessException;
31: import org.springframework.orm.ojb.support.PersistenceBrokerDaoSupport;
32:
33: /**
34: * OJB PersistenceBroker implementation of the Clinic interface.
35: *
36: * <p>The mappings are defined in "OJB-repository.xml",
37: * located in the root of the class path.
38: *
39: * @author Juergen Hoeller
40: * @since 04.07.2004
41: */
42: public class PersistenceBrokerClinic extends
43: PersistenceBrokerDaoSupport implements Clinic {
44:
45: public Collection getPets() throws DataAccessException {
46: QueryByCriteria query = new QueryByCriteria(Pet.class);
47: query.addOrderByAscending("name");
48: return getPersistenceBrokerTemplate().getCollectionByQuery(
49: query);
50: }
51:
52: public Collection getVets() throws DataAccessException {
53: QueryByCriteria query = new QueryByCriteria(Vet.class);
54: query.addOrderByAscending("lastName");
55: query.addOrderByAscending("firstName");
56: return getPersistenceBrokerTemplate().getCollectionByQuery(
57: query);
58: }
59:
60: public Collection getPetTypes() throws DataAccessException {
61: QueryByCriteria query = new QueryByCriteria(PetType.class);
62: query.addOrderByAscending("name");
63: return getPersistenceBrokerTemplate().getCollectionByQuery(
64: query);
65: }
66:
67: public Collection findOwners(String lastName)
68: throws DataAccessException {
69: Criteria criteria = new Criteria();
70: criteria.addLike("lastName", lastName + "%");
71: Query query = new QueryByCriteria(Owner.class, criteria);
72: return getPersistenceBrokerTemplate().getCollectionByQuery(
73: query);
74: }
75:
76: public Owner loadOwner(int id) throws DataAccessException {
77: return (Owner) getPersistenceBrokerTemplate().getObjectById(
78: Owner.class, new Integer(id));
79: }
80:
81: public Pet loadPet(int id) throws DataAccessException {
82: return (Pet) getPersistenceBrokerTemplate().getObjectById(
83: Pet.class, new Integer(id));
84: }
85:
86: public void storeOwner(Owner owner) throws DataAccessException {
87: getPersistenceBrokerTemplate().store(owner);
88: }
89:
90: public void storePet(Pet pet) throws DataAccessException {
91: getPersistenceBrokerTemplate().store(pet);
92: }
93:
94: public void storeVisit(Visit visit) {
95: getPersistenceBrokerTemplate().store(visit);
96: }
97:
98: }
|