org.springframework.samples.petclinic.jdbc
Class SimpleJdbcClinic

java.lang.Object
  extended by org.springframework.samples.petclinic.jdbc.SimpleJdbcClinic
All Implemented Interfaces:
Clinic, SimpleJdbcClinicMBean

@Service
@ManagedResource(value="petclinic:type=Clinic")
public class SimpleJdbcClinic
extends java.lang.Object
implements Clinic, SimpleJdbcClinicMBean

A simple JDBC-based implementation of the Clinic interface.

This class uses Java 5 language features and the SimpleJdbcTemplate plus SimpleJdbcInsert. It also takes advantage of classes like BeanPropertySqlParameterSource and ParameterizedBeanPropertyRowMapper which provide automatic mapping between JavaBean properties and JDBC parameters or query results.

SimpleJdbcClinic is a rewrite of the AbstractJdbcClinic which was the base class for JDBC implementations of the Clinic interface for Spring 2.0.

Author:
Ken Krebs, Juergen Hoeller, Rob Harrop, Sam Brannen, Thomas Risberg, Mark Fisher

Constructor Summary
SimpleJdbcClinic()
           
 
Method Summary
 void deletePet(int id)
          Deletes a Pet from the data store.
 java.util.Collection<Owner> findOwners(java.lang.String lastName)
          Loads Owners from the data store by last name, returning all owners whose last name starts with the given name; also loads the Pets and Visits for the corresponding owners, if not already loaded.
 java.util.Collection<PetType> getPetTypes()
          Retrieve all PetTypes from the data store.
 java.util.Collection<Vet> getVets()
          Retrieve all Vets from the data store.
 void init(javax.sql.DataSource dataSource)
           
 Owner loadOwner(int id)
          Loads the Owner with the supplied id; also loads the Pets and Visits for the corresponding owner, if not already loaded.
 Pet loadPet(int id)
          Retrieve a Pet from the data store by id.
 void refreshVetsCache()
          Refresh the cache of Vets that the Clinic is holding.
 void storeOwner(Owner owner)
          Save an Owner to the data store, either inserting or updating it.
 void storePet(Pet pet)
          Save a Pet to the data store, either inserting or updating it.
 void storeVisit(Visit visit)
          Save a Visit to the data store, either inserting or updating it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleJdbcClinic

public SimpleJdbcClinic()
Method Detail

init

public void init(javax.sql.DataSource dataSource)

refreshVetsCache

@ManagedOperation
@Transactional(readOnly=true)
public void refreshVetsCache()
                      throws org.springframework.dao.DataAccessException
Refresh the cache of Vets that the Clinic is holding.

Specified by:
refreshVetsCache in interface SimpleJdbcClinicMBean
Throws:
org.springframework.dao.DataAccessException
See Also:
Clinic.getVets()

getVets

@Transactional(readOnly=true)
public java.util.Collection<Vet> getVets()
                                  throws org.springframework.dao.DataAccessException
Description copied from interface: Clinic
Retrieve all Vets from the data store.

Specified by:
getVets in interface Clinic
Returns:
a Collection of Vets
Throws:
org.springframework.dao.DataAccessException

getPetTypes

@Transactional(readOnly=true)
public java.util.Collection<PetType> getPetTypes()
                                          throws org.springframework.dao.DataAccessException
Description copied from interface: Clinic
Retrieve all PetTypes from the data store.

Specified by:
getPetTypes in interface Clinic
Returns:
a Collection of PetTypes
Throws:
org.springframework.dao.DataAccessException

findOwners

@Transactional(readOnly=true)
public java.util.Collection<Owner> findOwners(java.lang.String lastName)
                                       throws org.springframework.dao.DataAccessException
Loads Owners from the data store by last name, returning all owners whose last name starts with the given name; also loads the Pets and Visits for the corresponding owners, if not already loaded.

Specified by:
findOwners in interface Clinic
Parameters:
lastName - Value to search for
Returns:
a Collection of matching Owners (or an empty Collection if none found)
Throws:
org.springframework.dao.DataAccessException

loadOwner

@Transactional(readOnly=true)
public Owner loadOwner(int id)
                throws org.springframework.dao.DataAccessException
Loads the Owner with the supplied id; also loads the Pets and Visits for the corresponding owner, if not already loaded.

Specified by:
loadOwner in interface Clinic
Parameters:
id - the id to search for
Returns:
the Owner if found
Throws:
org.springframework.dao.DataRetrievalFailureException - if not found
org.springframework.dao.DataAccessException

loadPet

@Transactional(readOnly=true)
public Pet loadPet(int id)
            throws org.springframework.dao.DataAccessException
Description copied from interface: Clinic
Retrieve a Pet from the data store by id.

Specified by:
loadPet in interface Clinic
Parameters:
id - the id to search for
Returns:
the Pet if found
Throws:
org.springframework.dao.DataRetrievalFailureException - if not found
org.springframework.dao.DataAccessException

storeOwner

@Transactional
public void storeOwner(Owner owner)
                throws org.springframework.dao.DataAccessException
Description copied from interface: Clinic
Save an Owner to the data store, either inserting or updating it.

Specified by:
storeOwner in interface Clinic
Parameters:
owner - the Owner to save
Throws:
org.springframework.dao.DataAccessException
See Also:
BaseEntity.isNew()

storePet

@Transactional
public void storePet(Pet pet)
              throws org.springframework.dao.DataAccessException
Description copied from interface: Clinic
Save a Pet to the data store, either inserting or updating it.

Specified by:
storePet in interface Clinic
Parameters:
pet - the Pet to save
Throws:
org.springframework.dao.DataAccessException
See Also:
BaseEntity.isNew()

storeVisit

@Transactional
public void storeVisit(Visit visit)
                throws org.springframework.dao.DataAccessException
Description copied from interface: Clinic
Save a Visit to the data store, either inserting or updating it.

Specified by:
storeVisit in interface Clinic
Parameters:
visit - the Visit to save
Throws:
org.springframework.dao.DataAccessException
See Also:
BaseEntity.isNew()

deletePet

public void deletePet(int id)
               throws org.springframework.dao.DataAccessException
Description copied from interface: Clinic
Deletes a Pet from the data store.

Specified by:
deletePet in interface Clinic
Throws:
org.springframework.dao.DataAccessException


Copyright © 2010. All Rights Reserved.