Skip to content
Snippets Groups Projects
Commit cc4ae966 authored by michaelisvy's avatar michaelisvy
Browse files

removed deprecated Mapper in Jdbc

parent d8a2b5c7
No related branches found
No related tags found
No related merge requests found
...@@ -25,9 +25,9 @@ import javax.sql.DataSource; ...@@ -25,9 +25,9 @@ import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert; import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
import org.springframework.orm.ObjectRetrievalFailureException; import org.springframework.orm.ObjectRetrievalFailureException;
import org.springframework.samples.petclinic.model.Owner; import org.springframework.samples.petclinic.model.Owner;
...@@ -84,7 +84,7 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository { ...@@ -84,7 +84,7 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
List<Owner> owners = this.namedParameterJdbcTemplate.query( List<Owner> owners = this.namedParameterJdbcTemplate.query(
"SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE last_name like :lastName", "SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE last_name like :lastName",
params, params,
ParameterizedBeanPropertyRowMapper.newInstance(Owner.class) BeanPropertyRowMapper.newInstance(Owner.class)
); );
loadOwnersPetsAndVisits(owners); loadOwnersPetsAndVisits(owners);
return owners; return owners;
...@@ -103,7 +103,7 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository { ...@@ -103,7 +103,7 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
owner = this.namedParameterJdbcTemplate.queryForObject( owner = this.namedParameterJdbcTemplate.queryForObject(
"SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id= :id", "SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id= :id",
params, params,
ParameterizedBeanPropertyRowMapper.newInstance(Owner.class) BeanPropertyRowMapper.newInstance(Owner.class)
); );
} catch (EmptyResultDataAccessException ex) { } catch (EmptyResultDataAccessException ex) {
throw new ObjectRetrievalFailureException(Owner.class, id); throw new ObjectRetrievalFailureException(Owner.class, id);
...@@ -147,7 +147,7 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository { ...@@ -147,7 +147,7 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
public Collection<PetType> getPetTypes() throws DataAccessException { public Collection<PetType> getPetTypes() throws DataAccessException {
return this.namedParameterJdbcTemplate.query( return this.namedParameterJdbcTemplate.query(
"SELECT id, name FROM types ORDER BY name", new HashMap<String, Object>(), "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; ...@@ -24,9 +24,9 @@ import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert; import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
import org.springframework.orm.ObjectRetrievalFailureException; import org.springframework.orm.ObjectRetrievalFailureException;
import org.springframework.samples.petclinic.model.Owner; import org.springframework.samples.petclinic.model.Owner;
...@@ -77,7 +77,7 @@ public class JdbcPetRepositoryImpl implements PetRepository { ...@@ -77,7 +77,7 @@ public class JdbcPetRepositoryImpl implements PetRepository {
return this.namedParameterJdbcTemplate.query( return this.namedParameterJdbcTemplate.query(
"SELECT id, name FROM types ORDER BY name", "SELECT id, name FROM types ORDER BY name",
params, params,
ParameterizedBeanPropertyRowMapper.newInstance(PetType.class)); BeanPropertyRowMapper.newInstance(PetType.class));
} }
@Override @Override
......
...@@ -20,13 +20,13 @@ import java.sql.SQLException; ...@@ -20,13 +20,13 @@ import java.sql.SQLException;
import java.util.Date; import java.util.Date;
import org.joda.time.DateTime; 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. * of the {@link JdbcPet} class.
*/ */
class JdbcPetRowMapper implements ParameterizedRowMapper<JdbcPet> { class JdbcPetRowMapper extends BeanPropertyRowMapper<JdbcPet> {
@Override @Override
public JdbcPet mapRow(ResultSet rs, int rownum) throws SQLException { public JdbcPet mapRow(ResultSet rs, int rownum) throws SQLException {
......
...@@ -23,9 +23,8 @@ import java.util.List; ...@@ -23,9 +23,8 @@ import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate; 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.Specialty;
import org.springframework.samples.petclinic.model.Vet; import org.springframework.samples.petclinic.model.Vet;
import org.springframework.samples.petclinic.repository.VetRepository; import org.springframework.samples.petclinic.repository.VetRepository;
...@@ -65,18 +64,18 @@ public class JdbcVetRepositoryImpl implements VetRepository { ...@@ -65,18 +64,18 @@ public class JdbcVetRepositoryImpl implements VetRepository {
// Retrieve the list of all vets. // Retrieve the list of all vets.
vets.addAll(this.jdbcTemplate.query( vets.addAll(this.jdbcTemplate.query(
"SELECT id, first_name, last_name FROM vets ORDER BY last_name,first_name", "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. // Retrieve the list of all possible specialties.
final List<Specialty> specialties = this.jdbcTemplate.query( final List<Specialty> specialties = this.jdbcTemplate.query(
"SELECT id, name FROM specialties", "SELECT id, name FROM specialties",
ParameterizedBeanPropertyRowMapper.newInstance(Specialty.class)); BeanPropertyRowMapper.newInstance(Specialty.class));
// Build each vet's list of specialties. // Build each vet's list of specialties.
for (Vet vet : vets) { for (Vet vet : vets) {
final List<Integer> vetSpecialtiesIds = this.jdbcTemplate.query( final List<Integer> vetSpecialtiesIds = this.jdbcTemplate.query(
"SELECT specialty_id FROM vet_specialties WHERE vet_id=?", "SELECT specialty_id FROM vet_specialties WHERE vet_id=?",
new ParameterizedRowMapper<Integer>() { new BeanPropertyRowMapper<Integer>() {
@Override @Override
public Integer mapRow(ResultSet rs, int row) throws SQLException { public Integer mapRow(ResultSet rs, int row) throws SQLException {
return Integer.valueOf(rs.getInt(1)); return Integer.valueOf(rs.getInt(1));
......
...@@ -25,9 +25,9 @@ import javax.sql.DataSource; ...@@ -25,9 +25,9 @@ import javax.sql.DataSource;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert; import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
import org.springframework.samples.petclinic.model.Visit; import org.springframework.samples.petclinic.model.Visit;
import org.springframework.samples.petclinic.repository.VisitRepository; import org.springframework.samples.petclinic.repository.VisitRepository;
...@@ -92,7 +92,7 @@ public class JdbcVisitRepositoryImpl implements VisitRepository { ...@@ -92,7 +92,7 @@ public class JdbcVisitRepositoryImpl implements VisitRepository {
public List<Visit> findByPetId(Integer petId) { public List<Visit> findByPetId(Integer petId) {
final List<Visit> visits = this.jdbcTemplate.query( final List<Visit> visits = this.jdbcTemplate.query(
"SELECT id, visit_date, description FROM visits WHERE pet_id=?", "SELECT id, visit_date, description FROM visits WHERE pet_id=?",
new ParameterizedRowMapper<Visit>() { new BeanPropertyRowMapper<Visit>() {
@Override @Override
public Visit mapRow(ResultSet rs, int row) throws SQLException { public Visit mapRow(ResultSet rs, int row) throws SQLException {
Visit visit = new Visit(); Visit visit = new Visit();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment