forked from DevFW-CICD/spring-petclinic
#96 Reformat code with EditorConfig
This commit is contained in:
parent
1aef94d6a8
commit
09ed33a5fc
56 changed files with 831 additions and 832 deletions
|
|
@ -32,15 +32,14 @@ public class BaseEntity {
|
|||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
protected Integer id;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean isNew() {
|
||||
return (this.id == null);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,15 +32,14 @@ public class NamedEntity extends BaseEntity {
|
|||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getName();
|
||||
|
|
|
|||
|
|
@ -85,10 +85,6 @@ public class Owner extends Person {
|
|||
this.telephone = telephone;
|
||||
}
|
||||
|
||||
protected void setPetsInternal(Set<Pet> pets) {
|
||||
this.pets = pets;
|
||||
}
|
||||
|
||||
protected Set<Pet> getPetsInternal() {
|
||||
if (this.pets == null) {
|
||||
this.pets = new HashSet<>();
|
||||
|
|
@ -96,6 +92,10 @@ public class Owner extends Person {
|
|||
return this.pets;
|
||||
}
|
||||
|
||||
protected void setPetsInternal(Set<Pet> pets) {
|
||||
this.pets = pets;
|
||||
}
|
||||
|
||||
public List<Pet> getPets() {
|
||||
List<Pet> sortedPets = new ArrayList<>(getPetsInternal());
|
||||
PropertyComparator.sort(sortedPets, new MutableSortDefinition("name", true, true));
|
||||
|
|
@ -141,13 +141,13 @@ public class Owner extends Person {
|
|||
public String toString() {
|
||||
return new ToStringCreator(this)
|
||||
|
||||
.append("id", this.getId())
|
||||
.append("new", this.isNew())
|
||||
.append("lastName", this.getLastName())
|
||||
.append("firstName", this.getFirstName())
|
||||
.append("address", this.address)
|
||||
.append("city", this.city)
|
||||
.append("telephone", this.telephone)
|
||||
.toString();
|
||||
.append("id", this.getId())
|
||||
.append("new", this.isNew())
|
||||
.append("lastName", this.getLastName())
|
||||
.append("firstName", this.getFirstName())
|
||||
.append("address", this.address)
|
||||
.append("city", this.city)
|
||||
.append("telephone", this.telephone)
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,33 +63,28 @@ public class Pet extends NamedEntity {
|
|||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "pet", fetch = FetchType.EAGER)
|
||||
private Set<Visit> visits;
|
||||
|
||||
|
||||
public void setBirthDate(DateTime birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
public DateTime getBirthDate() {
|
||||
return this.birthDate;
|
||||
}
|
||||
|
||||
public void setType(PetType type) {
|
||||
this.type = type;
|
||||
public void setBirthDate(DateTime birthDate) {
|
||||
this.birthDate = birthDate;
|
||||
}
|
||||
|
||||
public PetType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
protected void setOwner(Owner owner) {
|
||||
this.owner = owner;
|
||||
public void setType(PetType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Owner getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
protected void setVisitsInternal(Set<Visit> visits) {
|
||||
this.visits = visits;
|
||||
protected void setOwner(Owner owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
protected Set<Visit> getVisitsInternal() {
|
||||
|
|
@ -99,6 +94,10 @@ public class Pet extends NamedEntity {
|
|||
return this.visits;
|
||||
}
|
||||
|
||||
protected void setVisitsInternal(Set<Visit> visits) {
|
||||
this.visits = visits;
|
||||
}
|
||||
|
||||
public List<Visit> getVisits() {
|
||||
List<Visit> sortedVisits = new ArrayList<>(getVisitsInternal());
|
||||
PropertyComparator.sort(sortedVisits, new MutableSortDefinition("date", false, false));
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import javax.persistence.Table;
|
|||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* Can be Cat, Dog, Hamster...
|
||||
* Can be Cat, Dog, Hamster...
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "types")
|
||||
|
|
|
|||
|
|
@ -46,14 +46,9 @@ public class Vet extends Person {
|
|||
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
@JoinTable(name = "vet_specialties", joinColumns = @JoinColumn(name = "vet_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "specialty_id"))
|
||||
inverseJoinColumns = @JoinColumn(name = "specialty_id"))
|
||||
private Set<Specialty> specialties;
|
||||
|
||||
|
||||
protected void setSpecialtiesInternal(Set<Specialty> specialties) {
|
||||
this.specialties = specialties;
|
||||
}
|
||||
|
||||
protected Set<Specialty> getSpecialtiesInternal() {
|
||||
if (this.specialties == null) {
|
||||
this.specialties = new HashSet<>();
|
||||
|
|
@ -61,6 +56,10 @@ public class Vet extends Person {
|
|||
return this.specialties;
|
||||
}
|
||||
|
||||
protected void setSpecialtiesInternal(Set<Specialty> specialties) {
|
||||
this.specialties = specialties;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public List<Specialty> getSpecialties() {
|
||||
List<Specialty> sortedSpecs = new ArrayList<>(getSpecialtiesInternal());
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
|
||||
/**
|
||||
*
|
||||
* The classes in this package represent PetClinic's business layer.
|
||||
*
|
||||
*/
|
||||
package org.springframework.samples.petclinic.model;
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ public interface OwnerRepository {
|
|||
*
|
||||
* @param lastName Value to search for
|
||||
* @return a <code>Collection</code> of matching <code>Owner</code>s (or an empty <code>Collection</code> if none
|
||||
* found)
|
||||
* found)
|
||||
*/
|
||||
Collection<Owner> findByLastName(String lastName) throws DataAccessException;
|
||||
|
||||
|
|
@ -62,8 +62,7 @@ public interface OwnerRepository {
|
|||
*
|
||||
* @param id the id to search for
|
||||
* @return the <code>Owner</code> if found
|
||||
* @throws org.springframework.dao.DataRetrievalFailureException
|
||||
* if not found
|
||||
* @throws org.springframework.dao.DataRetrievalFailureException if not found
|
||||
*/
|
||||
Owner findById(int id) throws DataAccessException;
|
||||
|
||||
|
|
|
|||
|
|
@ -45,8 +45,7 @@ public interface PetRepository {
|
|||
*
|
||||
* @param id the id to search for
|
||||
* @return the <code>Pet</code> if found
|
||||
* @throws org.springframework.dao.DataRetrievalFailureException
|
||||
* if not found
|
||||
* @throws org.springframework.dao.DataRetrievalFailureException if not found
|
||||
*/
|
||||
Pet findById(int id) throws DataAccessException;
|
||||
|
||||
|
|
|
|||
|
|
@ -59,8 +59,8 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
|
|||
public JdbcOwnerRepositoryImpl(DataSource dataSource, NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
|
||||
|
||||
this.insertOwner = new SimpleJdbcInsert(dataSource)
|
||||
.withTableName("owners")
|
||||
.usingGeneratedKeyColumns("id");
|
||||
.withTableName("owners")
|
||||
.usingGeneratedKeyColumns("id");
|
||||
|
||||
this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
|
||||
|
||||
|
|
@ -77,9 +77,9 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
|
|||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("lastName", lastName + "%");
|
||||
List<Owner> owners = this.namedParameterJdbcTemplate.query(
|
||||
"SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE last_name like :lastName",
|
||||
params,
|
||||
BeanPropertyRowMapper.newInstance(Owner.class)
|
||||
"SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE last_name like :lastName",
|
||||
params,
|
||||
BeanPropertyRowMapper.newInstance(Owner.class)
|
||||
);
|
||||
loadOwnersPetsAndVisits(owners);
|
||||
return owners;
|
||||
|
|
@ -96,9 +96,9 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
|
|||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("id", id);
|
||||
owner = this.namedParameterJdbcTemplate.queryForObject(
|
||||
"SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id= :id",
|
||||
params,
|
||||
BeanPropertyRowMapper.newInstance(Owner.class)
|
||||
"SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id= :id",
|
||||
params,
|
||||
BeanPropertyRowMapper.newInstance(Owner.class)
|
||||
);
|
||||
} catch (EmptyResultDataAccessException ex) {
|
||||
throw new ObjectRetrievalFailureException(Owner.class, id);
|
||||
|
|
@ -111,9 +111,9 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
|
|||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("id", owner.getId());
|
||||
final List<JdbcPet> pets = this.namedParameterJdbcTemplate.query(
|
||||
"SELECT pets.id, name, birth_date, type_id, owner_id, visits.id as visit_id, visit_date, description, pet_id FROM pets LEFT OUTER JOIN visits ON pets.id = pet_id WHERE owner_id=:id",
|
||||
params,
|
||||
new JdbcPetVisitExtractor()
|
||||
"SELECT pets.id, name, birth_date, type_id, owner_id, visits.id as visit_id, visit_date, description, pet_id FROM pets LEFT OUTER JOIN visits ON pets.id = pet_id WHERE owner_id=:id",
|
||||
params,
|
||||
new JdbcPetVisitExtractor()
|
||||
);
|
||||
Collection<PetType> petTypes = getPetTypes();
|
||||
for (JdbcPet pet : pets) {
|
||||
|
|
@ -130,16 +130,16 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository {
|
|||
owner.setId(newKey.intValue());
|
||||
} else {
|
||||
this.namedParameterJdbcTemplate.update(
|
||||
"UPDATE owners SET first_name=:firstName, last_name=:lastName, address=:address, " +
|
||||
"city=:city, telephone=:telephone WHERE id=:id",
|
||||
parameterSource);
|
||||
"UPDATE owners SET first_name=:firstName, last_name=:lastName, address=:address, " +
|
||||
"city=:city, telephone=:telephone WHERE id=:id",
|
||||
parameterSource);
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<PetType> getPetTypes() throws DataAccessException {
|
||||
return this.namedParameterJdbcTemplate.query(
|
||||
"SELECT id, name FROM types ORDER BY name", new HashMap<String, Object>(),
|
||||
BeanPropertyRowMapper.newInstance(PetType.class));
|
||||
"SELECT id, name FROM types ORDER BY name", new HashMap<String, Object>(),
|
||||
BeanPropertyRowMapper.newInstance(PetType.class));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -29,21 +29,20 @@ class JdbcPet extends Pet {
|
|||
|
||||
private int ownerId;
|
||||
|
||||
|
||||
public void setTypeId(int typeId) {
|
||||
this.typeId = typeId;
|
||||
}
|
||||
|
||||
public int getTypeId() {
|
||||
return this.typeId;
|
||||
}
|
||||
|
||||
public void setOwnerId(int ownerId) {
|
||||
this.ownerId = ownerId;
|
||||
public void setTypeId(int typeId) {
|
||||
this.typeId = typeId;
|
||||
}
|
||||
|
||||
public int getOwnerId() {
|
||||
return this.ownerId;
|
||||
}
|
||||
|
||||
public void setOwnerId(int ownerId) {
|
||||
this.ownerId = ownerId;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,8 +64,8 @@ public class JdbcPetRepositoryImpl implements PetRepository {
|
|||
this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
|
||||
|
||||
this.insertPet = new SimpleJdbcInsert(dataSource)
|
||||
.withTableName("pets")
|
||||
.usingGeneratedKeyColumns("id");
|
||||
.withTableName("pets")
|
||||
.usingGeneratedKeyColumns("id");
|
||||
|
||||
this.ownerRepository = ownerRepository;
|
||||
this.visitRepository = visitRepository;
|
||||
|
|
@ -75,9 +75,9 @@ public class JdbcPetRepositoryImpl implements PetRepository {
|
|||
public List<PetType> findPetTypes() throws DataAccessException {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
return this.namedParameterJdbcTemplate.query(
|
||||
"SELECT id, name FROM types ORDER BY name",
|
||||
params,
|
||||
BeanPropertyRowMapper.newInstance(PetType.class));
|
||||
"SELECT id, name FROM types ORDER BY name",
|
||||
params,
|
||||
BeanPropertyRowMapper.newInstance(PetType.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -87,9 +87,9 @@ public class JdbcPetRepositoryImpl implements PetRepository {
|
|||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("id", id);
|
||||
pet = this.namedParameterJdbcTemplate.queryForObject(
|
||||
"SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id",
|
||||
params,
|
||||
new JdbcPetRowMapper());
|
||||
"SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id",
|
||||
params,
|
||||
new JdbcPetRowMapper());
|
||||
} catch (EmptyResultDataAccessException ex) {
|
||||
throw new ObjectRetrievalFailureException(Pet.class, id);
|
||||
}
|
||||
|
|
@ -108,13 +108,13 @@ public class JdbcPetRepositoryImpl implements PetRepository {
|
|||
public void save(Pet pet) throws DataAccessException {
|
||||
if (pet.isNew()) {
|
||||
Number newKey = this.insertPet.executeAndReturnKey(
|
||||
createPetParameterSource(pet));
|
||||
createPetParameterSource(pet));
|
||||
pet.setId(newKey.intValue());
|
||||
} else {
|
||||
this.namedParameterJdbcTemplate.update(
|
||||
"UPDATE pets SET name=:name, birth_date=:birth_date, type_id=:type_id, " +
|
||||
"owner_id=:owner_id WHERE id=:id",
|
||||
createPetParameterSource(pet));
|
||||
"UPDATE pets SET name=:name, birth_date=:birth_date, type_id=:type_id, " +
|
||||
"owner_id=:owner_id WHERE id=:id",
|
||||
createPetParameterSource(pet));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -123,11 +123,11 @@ public class JdbcPetRepositoryImpl implements PetRepository {
|
|||
*/
|
||||
private MapSqlParameterSource createPetParameterSource(Pet pet) {
|
||||
return new MapSqlParameterSource()
|
||||
.addValue("id", pet.getId())
|
||||
.addValue("name", pet.getName())
|
||||
.addValue("birth_date", pet.getBirthDate().toDate())
|
||||
.addValue("type_id", pet.getType().getId())
|
||||
.addValue("owner_id", pet.getOwner().getId());
|
||||
.addValue("id", pet.getId())
|
||||
.addValue("name", pet.getName())
|
||||
.addValue("birth_date", pet.getBirthDate().toDate())
|
||||
.addValue("type_id", pet.getType().getId())
|
||||
.addValue("owner_id", pet.getOwner().getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import java.sql.SQLException;
|
|||
* {@link OneToManyResultSetExtractor} of Spring Data Core JDBC Extensions.
|
||||
*/
|
||||
public class JdbcPetVisitExtractor extends
|
||||
OneToManyResultSetExtractor<JdbcPet, Visit, Integer> {
|
||||
OneToManyResultSetExtractor<JdbcPet, Visit, Integer> {
|
||||
|
||||
public JdbcPetVisitExtractor() {
|
||||
super(new JdbcPetRowMapper(), new JdbcVisitRowMapper());
|
||||
|
|
@ -51,4 +51,4 @@ public class JdbcPetVisitExtractor extends
|
|||
protected void addChild(JdbcPet root, Visit child) {
|
||||
root.addVisit(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,25 +60,25 @@ public class JdbcVetRepositoryImpl implements VetRepository {
|
|||
List<Vet> vets = new ArrayList<>();
|
||||
// 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",
|
||||
BeanPropertyRowMapper.newInstance(Vet.class)));
|
||||
"SELECT id, first_name, last_name FROM vets ORDER BY last_name,first_name",
|
||||
BeanPropertyRowMapper.newInstance(Vet.class)));
|
||||
|
||||
// Retrieve the list of all possible specialties.
|
||||
final List<Specialty> specialties = this.jdbcTemplate.query(
|
||||
"SELECT id, name FROM specialties",
|
||||
BeanPropertyRowMapper.newInstance(Specialty.class));
|
||||
"SELECT id, name FROM specialties",
|
||||
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 BeanPropertyRowMapper<Integer>() {
|
||||
@Override
|
||||
public Integer mapRow(ResultSet rs, int row) throws SQLException {
|
||||
return rs.getInt(1);
|
||||
}
|
||||
},
|
||||
vet.getId());
|
||||
"SELECT specialty_id FROM vet_specialties WHERE vet_id=?",
|
||||
new BeanPropertyRowMapper<Integer>() {
|
||||
@Override
|
||||
public Integer mapRow(ResultSet rs, int row) throws SQLException {
|
||||
return rs.getInt(1);
|
||||
}
|
||||
},
|
||||
vet.getId());
|
||||
for (int specialtyId : vetSpecialtiesIds) {
|
||||
Specialty specialty = EntityUtils.getById(specialties, Specialty.class, specialtyId);
|
||||
vet.addSpecialty(specialty);
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ public class JdbcVisitRepositoryImpl implements VisitRepository {
|
|||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
|
||||
this.insertVisit = new SimpleJdbcInsert(dataSource)
|
||||
.withTableName("visits")
|
||||
.usingGeneratedKeyColumns("id");
|
||||
.withTableName("visits")
|
||||
.usingGeneratedKeyColumns("id");
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ public class JdbcVisitRepositoryImpl implements VisitRepository {
|
|||
public void save(Visit visit) throws DataAccessException {
|
||||
if (visit.isNew()) {
|
||||
Number newKey = this.insertVisit.executeAndReturnKey(
|
||||
createVisitParameterSource(visit));
|
||||
createVisitParameterSource(visit));
|
||||
visit.setId(newKey.intValue());
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Visit update not supported");
|
||||
|
|
@ -72,17 +72,17 @@ public class JdbcVisitRepositoryImpl implements VisitRepository {
|
|||
*/
|
||||
private MapSqlParameterSource createVisitParameterSource(Visit visit) {
|
||||
return new MapSqlParameterSource()
|
||||
.addValue("id", visit.getId())
|
||||
.addValue("visit_date", visit.getDate().toDate())
|
||||
.addValue("description", visit.getDescription())
|
||||
.addValue("pet_id", visit.getPet().getId());
|
||||
.addValue("id", visit.getId())
|
||||
.addValue("visit_date", visit.getDate().toDate())
|
||||
.addValue("description", visit.getDescription())
|
||||
.addValue("pet_id", visit.getPet().getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Visit> findByPetId(Integer petId) {
|
||||
return this.jdbcTemplate.query(
|
||||
"SELECT id as visit_id, visit_date, description FROM visits WHERE pet_id=?",
|
||||
new JdbcVisitRowMapper(), petId);
|
||||
"SELECT id as visit_id, visit_date, description FROM visits WHERE pet_id=?",
|
||||
new JdbcVisitRowMapper(), petId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
|
||||
/**
|
||||
*
|
||||
* The classes in this package represent the JDBC implementation
|
||||
* of PetClinic's persistence layer.
|
||||
*
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.jdbc;
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ public class JpaOwnerRepositoryImpl implements OwnerRepository {
|
|||
|
||||
|
||||
/**
|
||||
* Important: in the current version of this method, we load Owners with all their Pets and Visits while
|
||||
* Important: in the current version of this method, we load Owners with all their Pets and Visits while
|
||||
* we do not need Visits at all and we only need one property from the Pet objects (the 'name' property).
|
||||
* There are some ways to improve it such as:
|
||||
* - creating a Ligtweight class (example here: https://community.jboss.org/wiki/LightweightClass)
|
||||
|
|
@ -70,12 +70,11 @@ public class JpaOwnerRepositoryImpl implements OwnerRepository {
|
|||
|
||||
@Override
|
||||
public void save(Owner owner) {
|
||||
if (owner.getId() == null) {
|
||||
this.em.persist(owner);
|
||||
}
|
||||
else {
|
||||
this.em.merge(owner);
|
||||
}
|
||||
if (owner.getId() == null) {
|
||||
this.em.persist(owner);
|
||||
} else {
|
||||
this.em.merge(owner);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,12 +53,11 @@ public class JpaPetRepositoryImpl implements PetRepository {
|
|||
|
||||
@Override
|
||||
public void save(Pet pet) {
|
||||
if (pet.getId() == null) {
|
||||
this.em.persist(pet);
|
||||
}
|
||||
else {
|
||||
this.em.merge(pet);
|
||||
}
|
||||
if (pet.getId() == null) {
|
||||
this.em.persist(pet);
|
||||
} else {
|
||||
this.em.merge(pet);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,12 +45,11 @@ public class JpaVisitRepositoryImpl implements VisitRepository {
|
|||
|
||||
@Override
|
||||
public void save(Visit visit) {
|
||||
if (visit.getId() == null) {
|
||||
this.em.persist(visit);
|
||||
}
|
||||
else {
|
||||
this.em.merge(visit);
|
||||
}
|
||||
if (visit.getId() == null) {
|
||||
this.em.persist(visit);
|
||||
} else {
|
||||
this.em.merge(visit);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
|
||||
/**
|
||||
*
|
||||
* The classes in this package represent the JPA implementation
|
||||
* of PetClinic's persistence layer.
|
||||
*
|
||||
*/
|
||||
package org.springframework.samples.petclinic.repository.jpa;
|
||||
|
||||
|
|
|
|||
|
|
@ -30,12 +30,12 @@ import org.springframework.samples.petclinic.repository.OwnerRepository;
|
|||
* @since 15.1.2013
|
||||
*/
|
||||
public interface SpringDataOwnerRepository extends OwnerRepository, Repository<Owner, Integer> {
|
||||
|
||||
@Override
|
||||
@Query("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName%")
|
||||
public Collection<Owner> findByLastName(@Param("lastName") String lastName);
|
||||
|
||||
@Override
|
||||
@Query("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id")
|
||||
public Owner findById(@Param("id") int id);
|
||||
|
||||
@Override
|
||||
@Query("SELECT DISTINCT owner FROM Owner owner left join fetch owner.pets WHERE owner.lastName LIKE :lastName%")
|
||||
public Collection<Owner> findByLastName(@Param("lastName") String lastName);
|
||||
|
||||
@Override
|
||||
@Query("SELECT owner FROM Owner owner left join fetch owner.pets WHERE owner.id =:id")
|
||||
public Owner findById(@Param("id") int id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ import org.springframework.util.StopWatch;
|
|||
/**
|
||||
* Simple aspect that monitors call count and call invocation time. It uses JMX annotations and therefore can be
|
||||
* monitored using any JMX console such as the jConsole
|
||||
*
|
||||
* This is only useful if you use JPA or JDBC. Spring-data-jpa doesn't have any correctly annotated classes to join on
|
||||
* <p/>
|
||||
* This is only useful if you use JPA or JDBC. Spring-data-jpa doesn't have any correctly annotated classes to join on
|
||||
*
|
||||
* @author Rob Harrop
|
||||
* @author Juergen Hoeller
|
||||
|
|
@ -44,17 +44,16 @@ public class CallMonitoringAspect {
|
|||
|
||||
private long accumulatedCallTime = 0;
|
||||
|
||||
|
||||
@ManagedAttribute
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@ManagedAttribute
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
@ManagedAttribute
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
@ManagedOperation
|
||||
public void reset() {
|
||||
this.callCount = 0;
|
||||
|
|
@ -68,10 +67,10 @@ public class CallMonitoringAspect {
|
|||
|
||||
@ManagedAttribute
|
||||
public long getCallTime() {
|
||||
if (this.callCount > 0)
|
||||
return this.accumulatedCallTime / this.callCount;
|
||||
else
|
||||
return 0;
|
||||
if (this.callCount > 0)
|
||||
return this.accumulatedCallTime / this.callCount;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -39,11 +39,10 @@ public abstract class EntityUtils {
|
|||
* @param entityClass the entity class to look up
|
||||
* @param entityId the entity id to look up
|
||||
* @return the found entity
|
||||
* @throws ObjectRetrievalFailureException
|
||||
* if the entity was not found
|
||||
* @throws ObjectRetrievalFailureException if the entity was not found
|
||||
*/
|
||||
public static <T extends BaseEntity> T getById(Collection<T> entities, Class<T> entityClass, int entityId)
|
||||
throws ObjectRetrievalFailureException {
|
||||
throws ObjectRetrievalFailureException {
|
||||
for (T entity : entities) {
|
||||
if (entity.getId() == entityId && entityClass.isInstance(entity)) {
|
||||
return entity;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ public class CrashController {
|
|||
@RequestMapping(value = "/oups", method = RequestMethod.GET)
|
||||
public String triggerException() {
|
||||
throw new RuntimeException("Expected: controller used to showcase what " +
|
||||
"happens when an exception is thrown");
|
||||
"happens when an exception is thrown");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -96,19 +96,17 @@ public class OwnerController {
|
|||
// no owners found
|
||||
result.rejectValue("lastName", "notFound", "not found");
|
||||
return "owners/findOwners";
|
||||
}
|
||||
else if (results.size() == 1) {
|
||||
// 1 owner found
|
||||
owner = results.iterator().next();
|
||||
return "redirect:/owners/" + owner.getId();
|
||||
}
|
||||
else {
|
||||
} else if (results.size() == 1) {
|
||||
// 1 owner found
|
||||
owner = results.iterator().next();
|
||||
return "redirect:/owners/" + owner.getId();
|
||||
} else {
|
||||
// multiple owners found
|
||||
model.put("selections", results);
|
||||
return "owners/ownersList";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/owners/{ownerId}/edit", method = RequestMethod.GET)
|
||||
public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) {
|
||||
Owner owner = this.clinicService.findOwnerById(ownerId);
|
||||
|
|
|
|||
|
|
@ -41,14 +41,14 @@ public class PetValidator implements Validator {
|
|||
} else if (pet.isNew() && pet.getOwner().getPet(name, true) != null) {
|
||||
errors.rejectValue("name", "duplicate", "already exists");
|
||||
}
|
||||
|
||||
|
||||
// type validation
|
||||
if (pet.isNew() && pet.getType() == null) {
|
||||
errors.rejectValue("type", "required", "required");
|
||||
}
|
||||
|
||||
|
||||
// birth date validation
|
||||
if (pet.getBirthDate()==null) {
|
||||
if (pet.getBirthDate() == null) {
|
||||
errors.rejectValue("birthDate", "required", "required");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,19 +41,21 @@ public class VetController {
|
|||
this.clinicService = clinicService;
|
||||
}
|
||||
|
||||
@RequestMapping(value={"/vets.xml","/vets.html"})
|
||||
@RequestMapping(value = {"/vets.xml", "/vets.html"})
|
||||
public String showVetList(Map<String, Object> model) {
|
||||
// Here we are returning an object of type 'Vets' rather than a collection of Vet objects
|
||||
// Here we are returning an object of type 'Vets' rather than a collection of Vet objects
|
||||
// so it is simpler for Object-Xml mapping
|
||||
Vets vets = new Vets();
|
||||
vets.getVetList().addAll(this.clinicService.findVets());
|
||||
model.put("vets", vets);
|
||||
return "vets/vetList";
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping("/vets.json")
|
||||
public @ResponseBody Vets showResourcesVetList() {
|
||||
// Here we are returning an object of type 'Vets' rather than a collection of Vet objects
|
||||
public
|
||||
@ResponseBody
|
||||
Vets showResourcesVetList() {
|
||||
// Here we are returning an object of type 'Vets' rather than a collection of Vet objects
|
||||
// so it is simpler for JSon/Object mapping
|
||||
Vets vets = new Vets();
|
||||
vets.getVetList().addAll(this.clinicService.findVets());
|
||||
|
|
|
|||
|
|
@ -53,13 +53,14 @@ public class VisitController {
|
|||
public void setAllowedFields(WebDataBinder dataBinder) {
|
||||
dataBinder.setDisallowedFields("id");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called before each and every @RequestMapping annotated method.
|
||||
* 2 goals:
|
||||
* - Make sure we always have fresh data
|
||||
* - Since we do not use the session scope, make sure that Pet object always has an id
|
||||
* (Even though id is not part of the form fields)
|
||||
* Called before each and every @RequestMapping annotated method.
|
||||
* 2 goals:
|
||||
* - Make sure we always have fresh data
|
||||
* - Since we do not use the session scope, make sure that Pet object always has an id
|
||||
* (Even though id is not part of the form fields)
|
||||
*
|
||||
* @param petId
|
||||
* @return Pet
|
||||
*/
|
||||
|
|
@ -67,17 +68,17 @@ public class VisitController {
|
|||
public Visit loadPetWithVisit(@PathVariable("petId") int petId) {
|
||||
Pet pet = this.clinicService.findPetById(petId);
|
||||
Visit visit = new Visit();
|
||||
pet.addVisit(visit);
|
||||
pet.addVisit(visit);
|
||||
return visit;
|
||||
}
|
||||
|
||||
// Spring MVC calls method loadPetWithVisit(...) before initNewVisitForm is called
|
||||
// Spring MVC calls method loadPetWithVisit(...) before initNewVisitForm is called
|
||||
@RequestMapping(value = "/owners/*/pets/{petId}/visits/new", method = RequestMethod.GET)
|
||||
public String initNewVisitForm(@PathVariable("petId") int petId, Map<String, Object> model) {
|
||||
return "pets/createOrUpdateVisitForm";
|
||||
}
|
||||
|
||||
// Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is called
|
||||
// Spring MVC calls method loadPetWithVisit(...) before processNewVisitForm is called
|
||||
@RequestMapping(value = "/owners/{ownerId}/pets/{petId}/visits/new", method = RequestMethod.POST)
|
||||
public String processNewVisitForm(@Valid Visit visit, BindingResult result) {
|
||||
if (result.hasErrors()) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
|
||||
/**
|
||||
*
|
||||
* The classes in this package represent PetClinic's web presentation layer.
|
||||
*
|
||||
*/
|
||||
package org.springframework.samples.petclinic.web;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,39 +1,53 @@
|
|||
<head>
|
||||
<style type="text/css">
|
||||
table.speakersTable {
|
||||
width: 70%;
|
||||
padding: 10;
|
||||
spacing: 10;
|
||||
}
|
||||
|
||||
img.speakerPic {
|
||||
float: right;
|
||||
padding:10;
|
||||
width: 90;
|
||||
}
|
||||
</style>
|
||||
<style type="text/css">
|
||||
table.speakersTable {
|
||||
width: 70%;
|
||||
padding: 10;
|
||||
spacing: 10;
|
||||
}
|
||||
|
||||
img.speakerPic {
|
||||
float: right;
|
||||
padding: 10;
|
||||
width: 90;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<h1>Organisation</h1>
|
||||
|
||||
<h1>Speakers</h1>
|
||||
<table class="speakersTable">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<img class="speakerPic" alt="Sergiu Bodiu" src="http://m.c.lnkd.licdn.com/mpr/mpr/shrink_200_200/p/4/000/16a/2ba/0ba653e.jpg" />
|
||||
<h2>Sergiu Bodiu </h2>
|
||||
<h3> Java Consultant at Bank of America </h3>
|
||||
<font size="5">S</font>easoned consultant experienced in large-scale e-commerce projects, passionate about providing innovative technology solutions to solve complex business problems, have extensive knowledge and experience delivering enterprise wide applications. He is skilled in software design, data modeling, stakeholder management, IT strategic planning, technical know-how and security. Able to design, implement, test and maintain software product components with strong focus on design elegance and software reuse.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<img alt="Sergiu Bodiu" src="http://m.c.lnkd.licdn.com/mpr/mpr/shrink_200_200/p/4/000/16a/2ba/0ba653e.jpg" width="84" height="84" align="right" hspace="10"/>
|
||||
<h2>Sergiu Bodiu </h2>
|
||||
<h3> Java Consultant at Bank of America </h3>
|
||||
<font size="5">S</font>easoned consultant experienced in large-scale e-commerce projects, passionate about providing innovative technology solutions to solve complex business problems, have extensive knowledge and experience delivering enterprise wide applications. He is skilled in software design, data modeling, stakeholder management, IT strategic planning, technical know-how and security. Able to design, implement, test and maintain software product components with strong focus on design elegance and software reuse.
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<img class="speakerPic" alt="Sergiu Bodiu"
|
||||
src="http://m.c.lnkd.licdn.com/mpr/mpr/shrink_200_200/p/4/000/16a/2ba/0ba653e.jpg"/>
|
||||
|
||||
<h2>Sergiu Bodiu </h2>
|
||||
|
||||
<h3> Java Consultant at Bank of America </h3>
|
||||
<font size="5">S</font>easoned consultant experienced in large-scale e-commerce projects, passionate about
|
||||
providing innovative technology solutions to solve complex business problems, have extensive knowledge and
|
||||
experience delivering enterprise wide applications. He is skilled in software design, data modeling,
|
||||
stakeholder management, IT strategic planning, technical know-how and security. Able to design, implement,
|
||||
test and maintain software product components with strong focus on design elegance and software reuse.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<img alt="Sergiu Bodiu" src="http://m.c.lnkd.licdn.com/mpr/mpr/shrink_200_200/p/4/000/16a/2ba/0ba653e.jpg"
|
||||
width="84" height="84" align="right" hspace="10"/>
|
||||
|
||||
<h2>Sergiu Bodiu </h2>
|
||||
|
||||
<h3> Java Consultant at Bank of America </h3>
|
||||
<font size="5">S</font>easoned consultant experienced in large-scale e-commerce projects, passionate about
|
||||
providing innovative technology solutions to solve complex business problems, have extensive knowledge and
|
||||
experience delivering enterprise wide applications. He is skilled in software design, data modeling,
|
||||
stakeholder management, IT strategic planning, technical know-how and security. Able to design, implement,
|
||||
test and maintain software product components with strong focus on design elegance and software reuse.
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue