Skip to content
Snippets Groups Projects
Commit 92de6557 authored by Antoine Rey's avatar Antoine Rey
Browse files

Fix #111 For pet's birthday we are now using jodatime LocalDate instead of DateTime

parent 4aa89ae4
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,7 @@ import javax.persistence.Table; ...@@ -32,6 +32,7 @@ import javax.persistence.Table;
import org.hibernate.annotations.Type; import org.hibernate.annotations.Type;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.springframework.beans.support.MutableSortDefinition; import org.springframework.beans.support.MutableSortDefinition;
import org.springframework.beans.support.PropertyComparator; import org.springframework.beans.support.PropertyComparator;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
...@@ -48,9 +49,9 @@ import org.springframework.format.annotation.DateTimeFormat; ...@@ -48,9 +49,9 @@ import org.springframework.format.annotation.DateTimeFormat;
public class Pet extends NamedEntity { public class Pet extends NamedEntity {
@Column(name = "birth_date") @Column(name = "birth_date")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime") @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
@DateTimeFormat(pattern = "yyyy/MM/dd") @DateTimeFormat(pattern = "yyyy/MM/dd")
private DateTime birthDate; private LocalDate birthDate;
@ManyToOne @ManyToOne
@JoinColumn(name = "type_id") @JoinColumn(name = "type_id")
...@@ -63,11 +64,11 @@ public class Pet extends NamedEntity { ...@@ -63,11 +64,11 @@ public class Pet extends NamedEntity {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "pet", fetch = FetchType.EAGER) @OneToMany(cascade = CascadeType.ALL, mappedBy = "pet", fetch = FetchType.EAGER)
private Set<Visit> visits; private Set<Visit> visits;
public DateTime getBirthDate() { public LocalDate getBirthDate() {
return this.birthDate; return this.birthDate;
} }
public void setBirthDate(DateTime birthDate) { public void setBirthDate(LocalDate birthDate) {
this.birthDate = birthDate; this.birthDate = birthDate;
} }
......
...@@ -20,6 +20,7 @@ import java.sql.SQLException; ...@@ -20,6 +20,7 @@ import java.sql.SQLException;
import java.util.Date; import java.util.Date;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.RowMapper;
/** /**
...@@ -34,7 +35,7 @@ class JdbcPetRowMapper implements RowMapper<JdbcPet> { ...@@ -34,7 +35,7 @@ class JdbcPetRowMapper implements RowMapper<JdbcPet> {
pet.setId(rs.getInt("pets.id")); pet.setId(rs.getInt("pets.id"));
pet.setName(rs.getString("name")); pet.setName(rs.getString("name"));
Date birthDate = rs.getDate("birth_date"); Date birthDate = rs.getDate("birth_date");
pet.setBirthDate(new DateTime(birthDate)); pet.setBirthDate(new LocalDate(birthDate));
pet.setTypeId(rs.getInt("type_id")); pet.setTypeId(rs.getInt("type_id"));
pet.setOwnerId(rs.getInt("owner_id")); pet.setOwnerId(rs.getInt("owner_id"));
return pet; return pet;
......
...@@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat; ...@@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collection; import java.util.Collection;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.samples.petclinic.model.Owner; import org.springframework.samples.petclinic.model.Owner;
...@@ -135,7 +136,7 @@ public abstract class AbstractClinicServiceTests { ...@@ -135,7 +136,7 @@ public abstract class AbstractClinicServiceTests {
pet.setName("bowser"); pet.setName("bowser");
Collection<PetType> types = this.clinicService.findPetTypes(); Collection<PetType> types = this.clinicService.findPetTypes();
pet.setType(EntityUtils.getById(types, PetType.class, 2)); pet.setType(EntityUtils.getById(types, PetType.class, 2));
pet.setBirthDate(new DateTime()); pet.setBirthDate(new LocalDate());
owner6.addPet(pet); owner6.addPet(pet);
assertThat(owner6.getPets().size()).isEqualTo(found + 1); assertThat(owner6.getPets().size()).isEqualTo(found + 1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment