mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-15 12:25:50 +00:00
removed deprecated Mapper in Jdbc
This commit is contained in:
parent
d8a2b5c737
commit
cc4ae966c6
5 changed files with 15 additions and 16 deletions
|
@ -25,9 +25,9 @@ import javax.sql.DataSource;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
|
||||
import org.springframework.orm.ObjectRetrievalFailureException;
|
||||
import org.springframework.samples.petclinic.model.Owner;
|
||||
|
@ -84,7 +84,7 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
|
|||
List<Owner> owners = this.namedParameterJdbcTemplate.query(
|
||||
"SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE last_name like :lastName",
|
||||
params,
|
||||
ParameterizedBeanPropertyRowMapper.newInstance(Owner.class)
|
||||
BeanPropertyRowMapper.newInstance(Owner.class)
|
||||
);
|
||||
loadOwnersPetsAndVisits(owners);
|
||||
return owners;
|
||||
|
@ -103,7 +103,7 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
|
|||
owner = this.namedParameterJdbcTemplate.queryForObject(
|
||||
"SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id= :id",
|
||||
params,
|
||||
ParameterizedBeanPropertyRowMapper.newInstance(Owner.class)
|
||||
BeanPropertyRowMapper.newInstance(Owner.class)
|
||||
);
|
||||
} catch (EmptyResultDataAccessException ex) {
|
||||
throw new ObjectRetrievalFailureException(Owner.class, id);
|
||||
|
@ -147,7 +147,7 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
|
|||
public Collection<PetType> getPetTypes() throws DataAccessException {
|
||||
return this.namedParameterJdbcTemplate.query(
|
||||
"SELECT id, name FROM types ORDER BY name", new HashMap<String, Object>(),
|
||||
ParameterizedBeanPropertyRowMapper.newInstance(PetType.class));
|
||||
BeanPropertyRowMapper.newInstance(PetType.class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,9 +24,9 @@ import javax.sql.DataSource;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
|
||||
import org.springframework.orm.ObjectRetrievalFailureException;
|
||||
import org.springframework.samples.petclinic.model.Owner;
|
||||
|
@ -77,7 +77,7 @@ public class JdbcPetRepositoryImpl implements PetRepository {
|
|||
return this.namedParameterJdbcTemplate.query(
|
||||
"SELECT id, name FROM types ORDER BY name",
|
||||
params,
|
||||
ParameterizedBeanPropertyRowMapper.newInstance(PetType.class));
|
||||
BeanPropertyRowMapper.newInstance(PetType.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,13 +20,13 @@ import java.sql.SQLException;
|
|||
import java.util.Date;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
|
||||
/**
|
||||
* {@link ParameterizedRowMapper} implementation mapping data from a {@link ResultSet} to the corresponding properties
|
||||
* {@link BeanPropertyRowMapper} implementation mapping data from a {@link ResultSet} to the corresponding properties
|
||||
* of the {@link JdbcPet} class.
|
||||
*/
|
||||
class JdbcPetRowMapper implements ParameterizedRowMapper<JdbcPet> {
|
||||
class JdbcPetRowMapper extends BeanPropertyRowMapper<JdbcPet> {
|
||||
|
||||
@Override
|
||||
public JdbcPet mapRow(ResultSet rs, int rownum) throws SQLException {
|
||||
|
|
|
@ -23,9 +23,8 @@ import java.util.List;
|
|||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
||||
import org.springframework.samples.petclinic.model.Specialty;
|
||||
import org.springframework.samples.petclinic.model.Vet;
|
||||
import org.springframework.samples.petclinic.repository.VetRepository;
|
||||
|
@ -65,18 +64,18 @@ public class JdbcVetRepositoryImpl implements VetRepository {
|
|||
// Retrieve the list of all vets.
|
||||
vets.addAll(this.jdbcTemplate.query(
|
||||
"SELECT id, first_name, last_name FROM vets ORDER BY last_name,first_name",
|
||||
ParameterizedBeanPropertyRowMapper.newInstance(Vet.class)));
|
||||
BeanPropertyRowMapper.newInstance(Vet.class)));
|
||||
|
||||
// Retrieve the list of all possible specialties.
|
||||
final List<Specialty> specialties = this.jdbcTemplate.query(
|
||||
"SELECT id, name FROM specialties",
|
||||
ParameterizedBeanPropertyRowMapper.newInstance(Specialty.class));
|
||||
BeanPropertyRowMapper.newInstance(Specialty.class));
|
||||
|
||||
// Build each vet's list of specialties.
|
||||
for (Vet vet : vets) {
|
||||
final List<Integer> vetSpecialtiesIds = this.jdbcTemplate.query(
|
||||
"SELECT specialty_id FROM vet_specialties WHERE vet_id=?",
|
||||
new ParameterizedRowMapper<Integer>() {
|
||||
new BeanPropertyRowMapper<Integer>() {
|
||||
@Override
|
||||
public Integer mapRow(ResultSet rs, int row) throws SQLException {
|
||||
return Integer.valueOf(rs.getInt(1));
|
||||
|
|
|
@ -25,9 +25,9 @@ import javax.sql.DataSource;
|
|||
import org.joda.time.DateTime;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
|
||||
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
|
||||
import org.springframework.samples.petclinic.model.Visit;
|
||||
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||
|
@ -92,7 +92,7 @@ public class JdbcVisitRepositoryImpl implements VisitRepository {
|
|||
public List<Visit> findByPetId(Integer petId) {
|
||||
final List<Visit> visits = this.jdbcTemplate.query(
|
||||
"SELECT id, visit_date, description FROM visits WHERE pet_id=?",
|
||||
new ParameterizedRowMapper<Visit>() {
|
||||
new BeanPropertyRowMapper<Visit>() {
|
||||
@Override
|
||||
public Visit mapRow(ResultSet rs, int row) throws SQLException {
|
||||
Visit visit = new Visit();
|
||||
|
|
Loading…
Reference in a new issue