1 package org.springframework.samples.petclinic.hibernate; 2 3 import java.util.Collection ; 4 5 import org.springframework.dao.DataAccessException; 6 import org.springframework.orm.hibernate3.support.HibernateDaoSupport; 7 import org.springframework.samples.petclinic.Clinic; 8 import org.springframework.samples.petclinic.Owner; 9 import org.springframework.samples.petclinic.Pet; 10 import org.springframework.samples.petclinic.Visit; 11 12 21 public class HibernateClinic extends HibernateDaoSupport implements Clinic { 22 23 public Collection getVets() throws DataAccessException { 24 return getHibernateTemplate().find("from Vet vet order by vet.lastName, vet.firstName"); 25 } 26 27 public Collection getPetTypes() throws DataAccessException { 28 return getHibernateTemplate().find("from PetType type order by type.name"); 29 } 30 31 public Collection findOwners(String lastName) throws DataAccessException { 32 return getHibernateTemplate().find("from Owner owner where owner.lastName like ?", lastName + "%"); 33 } 34 35 public Owner loadOwner(int id) throws DataAccessException { 36 return (Owner) getHibernateTemplate().load(Owner.class, new Integer (id)); 37 } 38 39 public Pet loadPet(int id) throws DataAccessException { 40 return (Pet) getHibernateTemplate().load(Pet.class, new Integer (id)); 41 } 42 43 public void storeOwner(Owner owner) throws DataAccessException { 44 getHibernateTemplate().merge(owner); 51 } 52 53 public void storePet(Pet pet) throws DataAccessException { 54 getHibernateTemplate().merge(pet); 55 } 56 57 public void storeVisit(Visit visit) throws DataAccessException { 58 getHibernateTemplate().merge(visit); 59 } 60 61 } 62 | Popular Tags |