Remove dependency with joda time to simplify the project dependencies

This commit is contained in:
Dapeng 2016-09-19 15:03:53 +08:00 committed by Antoine Rey
parent 9e6a8caf31
commit 17b6636b50
10 changed files with 42 additions and 74 deletions

26
pom.xml
View file

@ -27,11 +27,6 @@
<!-- Test -->
<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 -->
<mysql-driver.version>5.1.36</mysql-driver.version>
@ -63,11 +58,6 @@
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>${jadira-usertype-core.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
@ -168,22 +158,6 @@
<scope>runtime</scope>
</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 -->
<dependency>
<groupId>org.hsqldb</groupId>

View file

@ -15,11 +15,9 @@
*/
package org.springframework.samples.petclinic.model;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.springframework.beans.support.MutableSortDefinition;
import org.springframework.beans.support.PropertyComparator;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.CascadeType;
import javax.persistence.Column;
@ -30,12 +28,14 @@ import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.springframework.beans.support.MutableSortDefinition;
import org.springframework.beans.support.PropertyComparator;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Simple business object representing a pet.
@ -49,9 +49,9 @@ import org.springframework.format.annotation.DateTimeFormat;
public class Pet extends NamedEntity {
@Column(name = "birth_date")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
@Temporal(TemporalType.DATE)
@DateTimeFormat(pattern = "yyyy/MM/dd")
private LocalDate birthDate;
private Date birthDate;
@ManyToOne
@JoinColumn(name = "type_id")
@ -64,12 +64,13 @@ public class Pet extends NamedEntity {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "pet", fetch = FetchType.EAGER)
private Set<Visit> visits;
public LocalDate getBirthDate() {
return this.birthDate;
public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
public void setBirthDate(LocalDate birthDate) {
this.birthDate = birthDate;
public Date getBirthDate() {
return this.birthDate;
}
public PetType getType() {

View file

@ -15,16 +15,17 @@
*/
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.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.hibernate.annotations.Type;
import org.hibernate.validator.constraints.NotEmpty;
import org.joda.time.LocalDate;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import java.util.Date;
/**
* Simple JavaBean domain object representing a visit.
@ -39,9 +40,9 @@ public class Visit extends BaseEntity {
* Holds value of property date.
*/
@Column(name = "visit_date")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
@Temporal(TemporalType.TIMESTAMP)
@DateTimeFormat(pattern = "yyyy/MM/dd")
private LocalDate date;
private Date date;
/**
* Holds value of property description.
@ -62,7 +63,7 @@ public class Visit extends BaseEntity {
* Creates a new instance of Visit for the current date
*/
public Visit() {
this.date = new LocalDate();
this.date = new Date();
}
@ -71,7 +72,7 @@ public class Visit extends BaseEntity {
*
* @return Value of property date.
*/
public LocalDate getDate() {
public Date getDate() {
return this.date;
}
@ -80,7 +81,7 @@ public class Visit extends BaseEntity {
*
* @param date New value of property date.
*/
public void setDate(LocalDate date) {
public void setDate(Date date) {
this.date = date;
}

View file

@ -32,7 +32,6 @@ import org.springframework.orm.ObjectRetrievalFailureException;
import org.springframework.samples.petclinic.model.Owner;
import org.springframework.samples.petclinic.model.Pet;
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.PetRepository;
import org.springframework.samples.petclinic.repository.VisitRepository;
@ -115,7 +114,7 @@ public class JdbcPetRepositoryImpl implements PetRepository {
return new MapSqlParameterSource()
.addValue("id", pet.getId())
.addValue("name", pet.getName())
.addValue("birth_date", pet.getBirthDate().toDate())
.addValue("birth_date", pet.getBirthDate())
.addValue("type_id", pet.getType().getId())
.addValue("owner_id", pet.getOwner().getId());
}

View file

@ -19,8 +19,6 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.springframework.jdbc.core.RowMapper;
/**
@ -35,7 +33,7 @@ class JdbcPetRowMapper implements RowMapper<JdbcPet> {
pet.setId(rs.getInt("pets.id"));
pet.setName(rs.getString("name"));
Date birthDate = rs.getDate("birth_date");
pet.setBirthDate(new LocalDate(birthDate));
pet.setBirthDate(new Date(birthDate.getTime()));
pet.setTypeId(rs.getInt("type_id"));
pet.setOwnerId(rs.getInt("owner_id"));
return pet;

View file

@ -17,7 +17,6 @@ package org.springframework.samples.petclinic.repository.jdbc;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
@ -77,7 +76,7 @@ public class JdbcVisitRepositoryImpl implements VisitRepository {
private MapSqlParameterSource createVisitParameterSource(Visit visit) {
return new MapSqlParameterSource()
.addValue("id", visit.getId())
.addValue("visit_date", visit.getDate().toDate())
.addValue("visit_date", visit.getDate())
.addValue("description", visit.getDescription())
.addValue("pet_id", visit.getPet().getId());
}

View file

@ -16,7 +16,6 @@
package org.springframework.samples.petclinic.repository.jdbc;
import org.joda.time.LocalDate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.samples.petclinic.model.Visit;
@ -35,7 +34,7 @@ class JdbcVisitRowMapper implements RowMapper<Visit> {
Visit visit = new Visit();
visit.setId(rs.getInt("visit_id"));
Date visitDate = rs.getDate("visit_date");
visit.setDate(new LocalDate(visitDate));
visit.setDate(new Date(visitDate.getTime()));
visit.setDescription(rs.getString("description"));
return visit;
}

View file

@ -3,7 +3,6 @@
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ 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" %>
<petclinic:layout pageName="owners">
@ -54,7 +53,7 @@
<dt>Name</dt>
<dd><c:out value="${pet.name}"/></dd>
<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>
<dd><c:out value="${pet.type.name}"/></dd>
</dl>
@ -69,7 +68,7 @@
</thead>
<c:forEach var="visit" items="${pet.visits}">
<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>
</tr>
</c:forEach>

View file

@ -3,7 +3,6 @@
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ 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" %>
@ -30,7 +29,7 @@
</thead>
<tr>
<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.owner.firstName} ${visit.pet.owner.lastName}"/></td>
</tr>
@ -60,7 +59,7 @@
<c:forEach var="visit" items="${visit.pet.visits}">
<c:if test="${!visit['new']}">
<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>
</tr>
</c:if>

View file

@ -18,9 +18,8 @@ package org.springframework.samples.petclinic.service;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collection;
import java.util.Date;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.samples.petclinic.model.Owner;
@ -136,7 +135,7 @@ public abstract class AbstractClinicServiceTests {
pet.setName("bowser");
Collection<PetType> types = this.clinicService.findPetTypes();
pet.setType(EntityUtils.getById(types, PetType.class, 2));
pet.setBirthDate(new LocalDate());
pet.setBirthDate(new Date());
owner6.addPet(pet);
assertThat(owner6.getPets().size()).isEqualTo(found + 1);