mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 13:05:49 +00:00
Remove dependency with joda time to simplify the project dependencies
This commit is contained in:
parent
9e6a8caf31
commit
17b6636b50
10 changed files with 42 additions and 74 deletions
26
pom.xml
26
pom.xml
|
@ -27,11 +27,6 @@
|
||||||
<!-- Test -->
|
<!-- Test -->
|
||||||
<assertj.version>2.2.0</assertj.version>
|
<assertj.version>2.2.0</assertj.version>
|
||||||
|
|
||||||
<!-- Dates -->
|
|
||||||
<jodatime-hibernate.version>1.3</jodatime-hibernate.version>
|
|
||||||
<jodatime-jsptags.version>1.1.1</jodatime-jsptags.version>
|
|
||||||
<jadira-usertype-core.version>3.2.0.GA</jadira-usertype-core.version>
|
|
||||||
|
|
||||||
<!-- Others -->
|
<!-- Others -->
|
||||||
<mysql-driver.version>5.1.36</mysql-driver.version>
|
<mysql-driver.version>5.1.36</mysql-driver.version>
|
||||||
|
|
||||||
|
@ -63,11 +58,6 @@
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>org.jadira.usertype</groupId>
|
|
||||||
<artifactId>usertype.core</artifactId>
|
|
||||||
<version>${jadira-usertype-core.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.tomcat</groupId>
|
<groupId>org.apache.tomcat</groupId>
|
||||||
<artifactId>tomcat-servlet-api</artifactId>
|
<artifactId>tomcat-servlet-api</artifactId>
|
||||||
|
@ -168,22 +158,6 @@
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Date and Time -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>joda-time</groupId>
|
|
||||||
<artifactId>joda-time</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>joda-time</groupId>
|
|
||||||
<artifactId>joda-time-hibernate</artifactId>
|
|
||||||
<version>${jodatime-hibernate.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>joda-time</groupId>
|
|
||||||
<artifactId>joda-time-jsptags</artifactId>
|
|
||||||
<version>${jodatime-jsptags.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Databases - Uses HSQL by default -->
|
<!-- Databases - Uses HSQL by default -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hsqldb</groupId>
|
<groupId>org.hsqldb</groupId>
|
||||||
|
|
|
@ -15,11 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.samples.petclinic.model;
|
package org.springframework.samples.petclinic.model;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import org.springframework.beans.support.MutableSortDefinition;
|
||||||
import java.util.Collections;
|
import org.springframework.beans.support.PropertyComparator;
|
||||||
import java.util.HashSet;
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
|
@ -30,12 +28,14 @@ import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
|
||||||
import org.hibernate.annotations.Type;
|
import javax.persistence.Temporal;
|
||||||
import org.joda.time.DateTime;
|
import javax.persistence.TemporalType;
|
||||||
import org.joda.time.LocalDate;
|
import java.util.ArrayList;
|
||||||
import org.springframework.beans.support.MutableSortDefinition;
|
import java.util.Collections;
|
||||||
import org.springframework.beans.support.PropertyComparator;
|
import java.util.Date;
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple business object representing a pet.
|
* Simple business object representing a pet.
|
||||||
|
@ -49,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.PersistentLocalDate")
|
@Temporal(TemporalType.DATE)
|
||||||
@DateTimeFormat(pattern = "yyyy/MM/dd")
|
@DateTimeFormat(pattern = "yyyy/MM/dd")
|
||||||
private LocalDate birthDate;
|
private Date birthDate;
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "type_id")
|
@JoinColumn(name = "type_id")
|
||||||
|
@ -64,12 +64,13 @@ 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 LocalDate getBirthDate() {
|
|
||||||
return this.birthDate;
|
public void setBirthDate(Date birthDate) {
|
||||||
|
this.birthDate = birthDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBirthDate(LocalDate birthDate) {
|
public Date getBirthDate() {
|
||||||
this.birthDate = birthDate;
|
return this.birthDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PetType getType() {
|
public PetType getType() {
|
||||||
|
|
|
@ -15,16 +15,17 @@
|
||||||
*/
|
*/
|
||||||
package org.springframework.samples.petclinic.model;
|
package org.springframework.samples.petclinic.model;
|
||||||
|
|
||||||
|
import org.hibernate.validator.constraints.NotEmpty;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.ManyToOne;
|
import javax.persistence.ManyToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
import org.hibernate.annotations.Type;
|
import javax.persistence.TemporalType;
|
||||||
import org.hibernate.validator.constraints.NotEmpty;
|
import java.util.Date;
|
||||||
import org.joda.time.LocalDate;
|
|
||||||
import org.springframework.format.annotation.DateTimeFormat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple JavaBean domain object representing a visit.
|
* Simple JavaBean domain object representing a visit.
|
||||||
|
@ -39,9 +40,9 @@ public class Visit extends BaseEntity {
|
||||||
* Holds value of property date.
|
* Holds value of property date.
|
||||||
*/
|
*/
|
||||||
@Column(name = "visit_date")
|
@Column(name = "visit_date")
|
||||||
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
@DateTimeFormat(pattern = "yyyy/MM/dd")
|
@DateTimeFormat(pattern = "yyyy/MM/dd")
|
||||||
private LocalDate date;
|
private Date date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds value of property description.
|
* Holds value of property description.
|
||||||
|
@ -62,7 +63,7 @@ public class Visit extends BaseEntity {
|
||||||
* Creates a new instance of Visit for the current date
|
* Creates a new instance of Visit for the current date
|
||||||
*/
|
*/
|
||||||
public Visit() {
|
public Visit() {
|
||||||
this.date = new LocalDate();
|
this.date = new Date();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,7 +72,7 @@ public class Visit extends BaseEntity {
|
||||||
*
|
*
|
||||||
* @return Value of property date.
|
* @return Value of property date.
|
||||||
*/
|
*/
|
||||||
public LocalDate getDate() {
|
public Date getDate() {
|
||||||
return this.date;
|
return this.date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +81,7 @@ public class Visit extends BaseEntity {
|
||||||
*
|
*
|
||||||
* @param date New value of property date.
|
* @param date New value of property date.
|
||||||
*/
|
*/
|
||||||
public void setDate(LocalDate date) {
|
public void setDate(Date date) {
|
||||||
this.date = date;
|
this.date = date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ import org.springframework.orm.ObjectRetrievalFailureException;
|
||||||
import org.springframework.samples.petclinic.model.Owner;
|
import org.springframework.samples.petclinic.model.Owner;
|
||||||
import org.springframework.samples.petclinic.model.Pet;
|
import org.springframework.samples.petclinic.model.Pet;
|
||||||
import org.springframework.samples.petclinic.model.PetType;
|
import org.springframework.samples.petclinic.model.PetType;
|
||||||
import org.springframework.samples.petclinic.model.Visit;
|
|
||||||
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
import org.springframework.samples.petclinic.repository.OwnerRepository;
|
||||||
import org.springframework.samples.petclinic.repository.PetRepository;
|
import org.springframework.samples.petclinic.repository.PetRepository;
|
||||||
import org.springframework.samples.petclinic.repository.VisitRepository;
|
import org.springframework.samples.petclinic.repository.VisitRepository;
|
||||||
|
@ -115,7 +114,7 @@ public class JdbcPetRepositoryImpl implements PetRepository {
|
||||||
return new MapSqlParameterSource()
|
return new MapSqlParameterSource()
|
||||||
.addValue("id", pet.getId())
|
.addValue("id", pet.getId())
|
||||||
.addValue("name", pet.getName())
|
.addValue("name", pet.getName())
|
||||||
.addValue("birth_date", pet.getBirthDate().toDate())
|
.addValue("birth_date", pet.getBirthDate())
|
||||||
.addValue("type_id", pet.getType().getId())
|
.addValue("type_id", pet.getType().getId())
|
||||||
.addValue("owner_id", pet.getOwner().getId());
|
.addValue("owner_id", pet.getOwner().getId());
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,8 +19,6 @@ import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import org.joda.time.DateTime;
|
|
||||||
import org.joda.time.LocalDate;
|
|
||||||
import org.springframework.jdbc.core.RowMapper;
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,7 +33,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 LocalDate(birthDate));
|
pet.setBirthDate(new Date(birthDate.getTime()));
|
||||||
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;
|
||||||
|
|
|
@ -17,7 +17,6 @@ package org.springframework.samples.petclinic.repository.jdbc;
|
||||||
|
|
||||||
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.JdbcTemplate;
|
|
||||||
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.SimpleJdbcInsert;
|
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
|
||||||
|
@ -77,7 +76,7 @@ public class JdbcVisitRepositoryImpl implements VisitRepository {
|
||||||
private MapSqlParameterSource createVisitParameterSource(Visit visit) {
|
private MapSqlParameterSource createVisitParameterSource(Visit visit) {
|
||||||
return new MapSqlParameterSource()
|
return new MapSqlParameterSource()
|
||||||
.addValue("id", visit.getId())
|
.addValue("id", visit.getId())
|
||||||
.addValue("visit_date", visit.getDate().toDate())
|
.addValue("visit_date", visit.getDate())
|
||||||
.addValue("description", visit.getDescription())
|
.addValue("description", visit.getDescription())
|
||||||
.addValue("pet_id", visit.getPet().getId());
|
.addValue("pet_id", visit.getPet().getId());
|
||||||
}
|
}
|
||||||
|
@ -92,13 +91,13 @@ public class JdbcVisitRepositoryImpl implements VisitRepository {
|
||||||
new JdbcPetRowMapper());
|
new JdbcPetRowMapper());
|
||||||
|
|
||||||
List<Visit> visits = this.jdbcTemplate.query(
|
List<Visit> visits = this.jdbcTemplate.query(
|
||||||
"SELECT id as visit_id, visit_date, description FROM visits WHERE pet_id=:id",
|
"SELECT id as visit_id, visit_date, description FROM visits WHERE pet_id=:id",
|
||||||
params, new JdbcVisitRowMapper());
|
params, new JdbcVisitRowMapper());
|
||||||
|
|
||||||
for (Visit visit: visits) {
|
for (Visit visit: visits) {
|
||||||
visit.setPet(pet);
|
visit.setPet(pet);
|
||||||
}
|
}
|
||||||
|
|
||||||
return visits;
|
return visits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
package org.springframework.samples.petclinic.repository.jdbc;
|
package org.springframework.samples.petclinic.repository.jdbc;
|
||||||
|
|
||||||
|
|
||||||
import org.joda.time.LocalDate;
|
|
||||||
import org.springframework.jdbc.core.RowMapper;
|
import org.springframework.jdbc.core.RowMapper;
|
||||||
import org.springframework.samples.petclinic.model.Visit;
|
import org.springframework.samples.petclinic.model.Visit;
|
||||||
|
|
||||||
|
@ -35,7 +34,7 @@ class JdbcVisitRowMapper implements RowMapper<Visit> {
|
||||||
Visit visit = new Visit();
|
Visit visit = new Visit();
|
||||||
visit.setId(rs.getInt("visit_id"));
|
visit.setId(rs.getInt("visit_id"));
|
||||||
Date visitDate = rs.getDate("visit_date");
|
Date visitDate = rs.getDate("visit_date");
|
||||||
visit.setDate(new LocalDate(visitDate));
|
visit.setDate(new Date(visitDate.getTime()));
|
||||||
visit.setDescription(rs.getString("description"));
|
visit.setDescription(rs.getString("description"));
|
||||||
return visit;
|
return visit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
|
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
|
||||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||||
<%@ taglib prefix="joda" uri="http://www.joda.org/joda/time/tags" %>
|
|
||||||
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
|
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
|
||||||
|
|
||||||
<petclinic:layout pageName="owners">
|
<petclinic:layout pageName="owners">
|
||||||
|
@ -54,7 +53,7 @@
|
||||||
<dt>Name</dt>
|
<dt>Name</dt>
|
||||||
<dd><c:out value="${pet.name}"/></dd>
|
<dd><c:out value="${pet.name}"/></dd>
|
||||||
<dt>Birth Date</dt>
|
<dt>Birth Date</dt>
|
||||||
<dd><joda:format value="${pet.birthDate}" pattern="yyyy-MM-dd"/></dd>
|
<dd><fmt:formatDate value="${pet.birthDate}" pattern="yyyy-MM-dd"/></dd>
|
||||||
<dt>Type</dt>
|
<dt>Type</dt>
|
||||||
<dd><c:out value="${pet.type.name}"/></dd>
|
<dd><c:out value="${pet.type.name}"/></dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
@ -69,7 +68,7 @@
|
||||||
</thead>
|
</thead>
|
||||||
<c:forEach var="visit" items="${pet.visits}">
|
<c:forEach var="visit" items="${pet.visits}">
|
||||||
<tr>
|
<tr>
|
||||||
<td><joda:format value="${visit.date}" pattern="yyyy-MM-dd"/></td>
|
<td><fmt:formatDate value="${visit.date}" pattern="yyyy-MM-dd"/></td>
|
||||||
<td><c:out value="${visit.description}"/></td>
|
<td><c:out value="${visit.description}"/></td>
|
||||||
</tr>
|
</tr>
|
||||||
</c:forEach>
|
</c:forEach>
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||||
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
|
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
|
||||||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
|
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
|
||||||
<%@ taglib prefix="joda" uri="http://www.joda.org/joda/time/tags" %>
|
|
||||||
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
|
<%@ taglib prefix="petclinic" tagdir="/WEB-INF/tags" %>
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,7 +29,7 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tr>
|
<tr>
|
||||||
<td><c:out value="${visit.pet.name}"/></td>
|
<td><c:out value="${visit.pet.name}"/></td>
|
||||||
<td><joda:format value="${visit.pet.birthDate}" pattern="yyyy/MM/dd"/></td>
|
<td><fmt:formatDate value="${visit.pet.birthDate}" pattern="yyyy/MM/dd"/></td>
|
||||||
<td><c:out value="${visit.pet.type.name}"/></td>
|
<td><c:out value="${visit.pet.type.name}"/></td>
|
||||||
<td><c:out value="${visit.pet.owner.firstName} ${visit.pet.owner.lastName}"/></td>
|
<td><c:out value="${visit.pet.owner.firstName} ${visit.pet.owner.lastName}"/></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -60,7 +59,7 @@
|
||||||
<c:forEach var="visit" items="${visit.pet.visits}">
|
<c:forEach var="visit" items="${visit.pet.visits}">
|
||||||
<c:if test="${!visit['new']}">
|
<c:if test="${!visit['new']}">
|
||||||
<tr>
|
<tr>
|
||||||
<td><joda:format value="${visit.date}" pattern="yyyy/MM/dd"/></td>
|
<td><fmt:formatDate value="${visit.date}" pattern="yyyy/MM/dd"/></td>
|
||||||
<td><c:out value="${visit.description}"/></td>
|
<td><c:out value="${visit.description}"/></td>
|
||||||
</tr>
|
</tr>
|
||||||
</c:if>
|
</c:if>
|
||||||
|
|
|
@ -18,9 +18,8 @@ package org.springframework.samples.petclinic.service;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
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;
|
||||||
|
@ -136,7 +135,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 LocalDate());
|
pet.setBirthDate(new Date());
|
||||||
owner6.addPet(pet);
|
owner6.addPet(pet);
|
||||||
assertThat(owner6.getPets().size()).isEqualTo(found + 1);
|
assertThat(owner6.getPets().size()).isEqualTo(found + 1);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue