From ad423f575084c9d21d202cbd6ade260156ffbada Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Fri, 29 May 2015 08:07:39 +0200 Subject: [PATCH 01/30] Change javaconfig branch URL to spring-projects --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 039eaff2f..8a90f8981 100644 --- a/readme.md +++ b/readme.md @@ -48,7 +48,7 @@ File -> Import -> Maven -> Existing Maven project Java Config branch - Petclinic uses XML configuration by default. In case you'd like to use Java Config instead, there is a Java Config branch available here. Thanks to Antoine Rey for his contribution. + Petclinic uses XML configuration by default. In case you'd like to use Java Config instead, there is a Java Config branch available here. Thanks to Antoine Rey for his contribution. From b265fc802d33b465dc6597fb0e763270a415b709 Mon Sep 17 00:00:00 2001 From: michaelisvy Date: Fri, 29 May 2015 15:16:12 +0800 Subject: [PATCH 02/30] Adding instruction to fix build on Maven 3.2.x --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index e9e79c708..b929a6447 100644 --- a/pom.xml +++ b/pom.xml @@ -408,6 +408,7 @@ cobertura-maven-plugin ${cobertura.version} + From cb6bd875dedbd7e8e4d666fd211a623c1b04f72c Mon Sep 17 00:00:00 2001 From: michaelisvy Date: Fri, 29 May 2015 15:20:10 +0800 Subject: [PATCH 03/30] Putting encoding filter first per #80 --- src/main/webapp/WEB-INF/web.xml | 38 ++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 360e3698a..2bb1d5f84 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -68,6 +68,25 @@ http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" dandelionServlet /dandelion-assets/* + + + + encodingFilter + org.springframework.web.filter.CharacterEncodingFilter + + encoding + UTF-8 + + + forceEncoding + true + + + + + encodingFilter + /* + @@ -91,25 +110,6 @@ see here: http://static.springsource.org/spring/docs/current/spring-framework-re httpMethodFilter petclinic - - - - encodingFilter - org.springframework.web.filter.CharacterEncodingFilter - - encoding - UTF-8 - - - forceEncoding - true - - - - - encodingFilter - /* - From ae15df1b61877acd2b904f53d360523a2a574010 Mon Sep 17 00:00:00 2001 From: srenkens Date: Fri, 5 Jun 2015 12:37:46 +0200 Subject: [PATCH 04/30] Update readme.md Updates the jsp url for the sample usage in JSP --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 8a90f8981..a314398a2 100644 --- a/readme.md +++ b/readme.md @@ -73,7 +73,7 @@ File -> Import -> Maven -> Existing Maven project webjars declaration inside pom.xml
Resource mapping in Spring configuration
- sample usage in JSP + sample usage in JSP From 818529b5b10bbf2f5ef861f0439ef1d84fc69577 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Tue, 9 Jun 2015 08:37:20 +0200 Subject: [PATCH 05/30] #64 Remove N+1 select by using the OneToManyResultSetExtractor of Spring Data Core JDBC Extensions --- pom.xml | 14 ++++++ .../jdbc/JdbcOwnerRepositoryImpl.java | 10 +--- .../repository/jdbc/JdbcPetRowMapper.java | 2 +- .../jdbc/JdbcPetVisitExtractor.java | 50 +++++++++++++++++++ .../jdbc/JdbcVisitRepositoryImpl.java | 30 +++-------- .../repository/jdbc/JdbcVisitRowMapper.java | 38 ++++++++++++++ 6 files changed, 111 insertions(+), 33 deletions(-) create mode 100644 src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetVisitExtractor.java create mode 100644 src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java diff --git a/pom.xml b/pom.xml index b929a6447..fd3b8896a 100644 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,7 @@ 4.1.6.RELEASE 1.8.0.RELEASE + 1.1.0.RELEASE @@ -127,6 +128,19 @@ + + org.springframework.data + spring-data-jdbc-core + ${spring-data-jdbc.version} + + + org.springframework + * + + + + + org.springframework spring-jdbc diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java index 579de5284..6759c5836 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java @@ -116,18 +116,12 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository { Map params = new HashMap(); params.put("id", owner.getId().intValue()); final List pets = this.namedParameterJdbcTemplate.query( - "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE owner_id=:id", + "SELECT pets.id, name, birth_date, type_id, owner_id, visits.id, visit_date, description, pet_id FROM pets LEFT OUTER JOIN visits ON pets.id = pet_id WHERE owner_id=:id", params, - new JdbcPetRowMapper() + new JdbcPetVisitExtractor() ); for (JdbcPet pet : pets) { owner.addPet(pet); - // Pet types have not been loaded at this stage. They are loaded separately - pet.setType(EntityUtils.getById(getPetTypes(), PetType.class, pet.getTypeId())); - List visits = this.visitRepository.findByPetId(pet.getId()); - for (Visit visit : visits) { - pet.addVisit(visit); - } } } diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRowMapper.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRowMapper.java index 4164f746f..28151a723 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRowMapper.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRowMapper.java @@ -31,7 +31,7 @@ class JdbcPetRowMapper extends BeanPropertyRowMapper { @Override public JdbcPet mapRow(ResultSet rs, int rownum) throws SQLException { JdbcPet pet = new JdbcPet(); - pet.setId(rs.getInt("id")); + pet.setId(rs.getInt("pets.id")); pet.setName(rs.getString("name")); Date birthDate = rs.getDate("birth_date"); pet.setBirthDate(new DateTime(birthDate)); diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetVisitExtractor.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetVisitExtractor.java new file mode 100644 index 000000000..922d608fe --- /dev/null +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetVisitExtractor.java @@ -0,0 +1,50 @@ +/* + * Copyright 2002-2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.samples.petclinic.repository.jdbc; + +import org.springframework.data.jdbc.core.OneToManyResultSetExtractor; +import org.springframework.samples.petclinic.model.Visit; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class JdbcPetVisitExtractor extends + OneToManyResultSetExtractor { + + public JdbcPetVisitExtractor() { + super(new JdbcPetRowMapper(), new JdbcVisitRowMapper()); + } + + @Override + protected Integer mapPrimaryKey(ResultSet rs) throws SQLException { + return rs.getInt("pets.id"); + } + + @Override + protected Integer mapForeignKey(ResultSet rs) throws SQLException { + if (rs.getObject("visits.pet_id") == null) { + return null; + } + else { + return rs.getInt("visits.pet_id"); + } + } + + @Override + protected void addChild(JdbcPet root, Visit child) { + root.addVisit(child); + } +} \ No newline at end of file diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java index b6a004561..19210574f 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java @@ -15,17 +15,8 @@ */ package org.springframework.samples.petclinic.repository.jdbc; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Date; -import java.util.List; - -import javax.sql.DataSource; - -import org.joda.time.DateTime; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; -import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.simple.SimpleJdbcInsert; @@ -33,6 +24,9 @@ import org.springframework.samples.petclinic.model.Visit; import org.springframework.samples.petclinic.repository.VisitRepository; import org.springframework.stereotype.Repository; +import javax.sql.DataSource; +import java.util.List; + /** * A simple JDBC-based implementation of the {@link VisitRepository} interface. * @@ -90,21 +84,9 @@ public class JdbcVisitRepositoryImpl implements VisitRepository { @Override public List findByPetId(Integer petId) { - final List visits = this.jdbcTemplate.query( - "SELECT id, visit_date, description FROM visits WHERE pet_id=?", - new BeanPropertyRowMapper() { - @Override - public Visit mapRow(ResultSet rs, int row) throws SQLException { - Visit visit = new Visit(); - visit.setId(rs.getInt("id")); - Date visitDate = rs.getDate("visit_date"); - visit.setDate(new DateTime(visitDate)); - visit.setDescription(rs.getString("description")); - return visit; - } - }, - petId); - return visits; + return this.jdbcTemplate.query( + "SELECT id as visit_id, visit_date, description FROM visits WHERE pet_id=?", + new JdbcVisitRowMapper(), petId); } } diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java new file mode 100644 index 000000000..241a7902b --- /dev/null +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java @@ -0,0 +1,38 @@ +/* + * Copyright 2002-2015 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.samples.petclinic.repository.jdbc; + + +import org.joda.time.DateTime; +import org.springframework.jdbc.core.RowMapper; +import org.springframework.samples.petclinic.model.Visit; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Date; + +class JdbcVisitRowMapper implements RowMapper { + + @Override + public Visit mapRow(ResultSet rs, int row) throws SQLException { + Visit visit = new Visit(); + visit.setId(rs.getInt("visits.id")); + Date visitDate = rs.getDate("visit_date"); + visit.setDate(new DateTime(visitDate)); + visit.setDescription(rs.getString("description")); + return visit; + } +} From fb644658026099b661d82241ac1cb2f1dcec09b2 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Tue, 9 Jun 2015 08:40:49 +0200 Subject: [PATCH 06/30] Add some javadoc --- .../petclinic/repository/jdbc/JdbcPetVisitExtractor.java | 8 ++++++-- .../petclinic/repository/jdbc/JdbcVisitRowMapper.java | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetVisitExtractor.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetVisitExtractor.java index 922d608fe..c40786d93 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetVisitExtractor.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetVisitExtractor.java @@ -16,11 +16,16 @@ package org.springframework.samples.petclinic.repository.jdbc; import org.springframework.data.jdbc.core.OneToManyResultSetExtractor; +import org.springframework.jdbc.core.ResultSetExtractor; import org.springframework.samples.petclinic.model.Visit; import java.sql.ResultSet; import java.sql.SQLException; +/** + * {@link ResultSetExtractor} implementation by using the + * {@link OneToManyResultSetExtractor} of Spring Data Core JDBC Extensions. + */ public class JdbcPetVisitExtractor extends OneToManyResultSetExtractor { @@ -37,8 +42,7 @@ public class JdbcPetVisitExtractor extends protected Integer mapForeignKey(ResultSet rs) throws SQLException { if (rs.getObject("visits.pet_id") == null) { return null; - } - else { + } else { return rs.getInt("visits.pet_id"); } } diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java index 241a7902b..d6dd0cbf8 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java @@ -24,6 +24,10 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.Date; +/** + * {@link RowMapper} implementation mapping data from a {@link ResultSet} to the corresponding properties + * of the {@link Visit} class. + */ class JdbcVisitRowMapper implements RowMapper { @Override From 8d20340518d5d0b4f3dea577ce1abdb1655d2750 Mon Sep 17 00:00:00 2001 From: michaelisvy Date: Tue, 9 Jun 2015 17:14:53 +0800 Subject: [PATCH 07/30] removed unused attribute #64 --- .../petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java index 6759c5836..98ae49dba 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java @@ -36,7 +36,6 @@ 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.VisitRepository; -import org.springframework.samples.petclinic.util.EntityUtils; import org.springframework.stereotype.Repository; /** @@ -52,8 +51,6 @@ import org.springframework.stereotype.Repository; @Repository public class JdbcOwnerRepositoryImpl implements OwnerRepository { - private VisitRepository visitRepository; - private NamedParameterJdbcTemplate namedParameterJdbcTemplate; private SimpleJdbcInsert insertOwner; @@ -68,7 +65,6 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository { this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(dataSource); - this.visitRepository = visitRepository; } From 5570366cfd960bc64fd688bc8f82d54f18772ead Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Wed, 17 Jun 2015 08:30:26 +0200 Subject: [PATCH 08/30] Use a simple RowMapper instead of a BeanPropertyRowMapper --- .../samples/petclinic/repository/jdbc/JdbcPetRowMapper.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRowMapper.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRowMapper.java index 28151a723..ad00a7163 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRowMapper.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRowMapper.java @@ -20,13 +20,13 @@ import java.sql.SQLException; import java.util.Date; import org.joda.time.DateTime; -import org.springframework.jdbc.core.BeanPropertyRowMapper; +import org.springframework.jdbc.core.RowMapper; /** - * {@link BeanPropertyRowMapper} implementation mapping data from a {@link ResultSet} to the corresponding properties + * {@link RowMapper} implementation mapping data from a {@link ResultSet} to the corresponding properties * of the {@link JdbcPet} class. */ -class JdbcPetRowMapper extends BeanPropertyRowMapper { +class JdbcPetRowMapper implements RowMapper { @Override public JdbcPet mapRow(ResultSet rs, int rownum) throws SQLException { From dc0fb9abd898336d3da51aed799defe2ea4dfce4 Mon Sep 17 00:00:00 2001 From: michaelisvy Date: Wed, 17 Jun 2015 13:10:00 -0500 Subject: [PATCH 09/30] removing unused method #85 --- .../petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java index 19210574f..a923b7652 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java @@ -66,10 +66,6 @@ public class JdbcVisitRepositoryImpl implements VisitRepository { } } - public void deletePet(int id) throws DataAccessException { - this.jdbcTemplate.update("DELETE FROM pets WHERE id=?", id); - } - /** * Creates a {@link MapSqlParameterSource} based on data values from the supplied {@link Visit} instance. From 735fb1149b5f1e8371242313678ae41fb4cc9dc7 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Wed, 17 Jun 2015 18:54:26 +0200 Subject: [PATCH 10/30] Remove explicit unboxing --- .../petclinic/repository/jdbc/JdbcPetRepositoryImpl.java | 2 +- .../petclinic/repository/jdbc/JdbcVetRepositoryImpl.java | 4 ++-- .../springframework/samples/petclinic/util/EntityUtils.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImpl.java index 546451dcc..e068791a1 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImpl.java @@ -91,7 +91,7 @@ public class JdbcPetRepositoryImpl implements PetRepository { params, new JdbcPetRowMapper()); } catch (EmptyResultDataAccessException ex) { - throw new ObjectRetrievalFailureException(Pet.class, new Integer(id)); + throw new ObjectRetrievalFailureException(Pet.class, id); } Owner owner = this.ownerRepository.findById(pet.getOwnerId()); owner.addPet(pet); diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java index 9a85bde11..f6e91cf5e 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java @@ -78,10 +78,10 @@ public class JdbcVetRepositoryImpl implements VetRepository { new BeanPropertyRowMapper() { @Override public Integer mapRow(ResultSet rs, int row) throws SQLException { - return Integer.valueOf(rs.getInt(1)); + return rs.getInt(1); } }, - vet.getId().intValue()); + vet.getId()); for (int specialtyId : vetSpecialtiesIds) { Specialty specialty = EntityUtils.getById(specialties, Specialty.class, specialtyId); vet.addSpecialty(specialty); diff --git a/src/main/java/org/springframework/samples/petclinic/util/EntityUtils.java b/src/main/java/org/springframework/samples/petclinic/util/EntityUtils.java index a18f65c39..41486a5a7 100644 --- a/src/main/java/org/springframework/samples/petclinic/util/EntityUtils.java +++ b/src/main/java/org/springframework/samples/petclinic/util/EntityUtils.java @@ -45,7 +45,7 @@ public abstract class EntityUtils { public static T getById(Collection entities, Class entityClass, int entityId) throws ObjectRetrievalFailureException { for (T entity : entities) { - if (entity.getId().intValue() == entityId && entityClass.isInstance(entity)) { + if (entity.getId() == entityId && entityClass.isInstance(entity)) { return entity; } } From 1b4d4256c433a7f7e51516dc06ba1fe4be36bd0d Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Thu, 18 Jun 2015 18:28:31 +0200 Subject: [PATCH 11/30] Fix typo into javadoc --- .../samples/petclinic/service/AbstractClinicServiceTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java b/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java index 61ed54571..428c285fd 100644 --- a/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java +++ b/src/test/java/org/springframework/samples/petclinic/service/AbstractClinicServiceTests.java @@ -38,7 +38,7 @@ import org.springframework.transaction.annotation.Transactional; * TestContext Framework:

  • Spring IoC container caching which spares us unnecessary set up * time between test execution.
  • Dependency Injection of test fixture instances, meaning that * we don't need to perform application context lookups. See the use of {@link Autowired @Autowired} on the {@link - * AbstractclinicServiceTests#clinicService clinicService} instance variable, which uses autowiring by + * AbstractClinicServiceTests#clinicService clinicService} instance variable, which uses autowiring by * type.
  • Transaction management, meaning each test method is executed in its own transaction, * which is automatically rolled back by default. Thus, even if tests insert or otherwise change database state, there * is no need for a teardown or cleanup script.
  • An {@link org.springframework.context.ApplicationContext From ca3bb07fa4182fee0ce9e5f212d20acdb458f740 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Thu, 18 Jun 2015 18:29:49 +0200 Subject: [PATCH 12/30] Remove unused WebApplicationContext property --- .../samples/petclinic/web/VetControllerTests.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java b/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java index a079ae59e..b8c623b39 100644 --- a/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java @@ -32,9 +32,6 @@ public class VetControllerTests { @Autowired private VetController vetController; - - @Autowired - private WebApplicationContext ctx; private MockMvc mockMvc; From 6f6fa64dd78a113e1284091fc533e1921b4900e9 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Wed, 24 Jun 2015 08:11:09 +0200 Subject: [PATCH 13/30] Remove unused VisitRepository from constructor --- .../petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java index 98ae49dba..960c66c01 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java @@ -35,7 +35,6 @@ 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.VisitRepository; import org.springframework.stereotype.Repository; /** @@ -56,8 +55,7 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository { private SimpleJdbcInsert insertOwner; @Autowired - public JdbcOwnerRepositoryImpl(DataSource dataSource, NamedParameterJdbcTemplate namedParameterJdbcTemplate, - VisitRepository visitRepository) { + public JdbcOwnerRepositoryImpl(DataSource dataSource, NamedParameterJdbcTemplate namedParameterJdbcTemplate) { this.insertOwner = new SimpleJdbcInsert(dataSource) .withTableName("owners") From 71f2424542b7b8998dc40762a89dc9587cedac96 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Wed, 24 Jun 2015 08:12:43 +0200 Subject: [PATCH 14/30] Remove explicit unboxing --- .../petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java index 960c66c01..31839ad12 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java @@ -108,7 +108,7 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository { public void loadPetsAndVisits(final Owner owner) { Map params = new HashMap(); - params.put("id", owner.getId().intValue()); + params.put("id", owner.getId()); final List pets = this.namedParameterJdbcTemplate.query( "SELECT pets.id, name, birth_date, type_id, owner_id, visits.id, visit_date, description, pet_id FROM pets LEFT OUTER JOIN visits ON pets.id = pet_id WHERE owner_id=:id", params, From 98d9bbb6296300db5d0a98edb8bfdf4bf95b02c0 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Wed, 24 Jun 2015 18:43:45 +0200 Subject: [PATCH 15/30] Removing reference to the unknown UserResource class --- .../samples/petclinic/web/VetControllerTests.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java b/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java index b8c623b39..61e6d3287 100644 --- a/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/web/VetControllerTests.java @@ -21,8 +21,6 @@ import org.springframework.web.context.WebApplicationContext; /** * Test class for the UserResource REST controller. - * - * @see UserResource */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({"classpath:spring/business-config.xml", "classpath:spring/tools-config.xml", "classpath:spring/mvc-core-config.xml"}) From 5e56bc222bce4139a401cca29aaced12aba96558 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Wed, 24 Jun 2015 21:15:29 +0200 Subject: [PATCH 16/30] Using JSP and JSTL version from the section --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index fd3b8896a..07e1e58e5 100644 --- a/pom.xml +++ b/pom.xml @@ -86,14 +86,14 @@ javax.servlet.jsp jsp-api - 2.1 + ${jsp.version} provided org.glassfish.web jstl-impl - 1.2 + ${jstl.version} javax.servlet From a07cf692921b426f3cce8f5270471698168fc32f Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Thu, 25 Jun 2015 08:33:25 +0200 Subject: [PATCH 17/30] Fix #88 upgrading to Hibernate Validator 5.1.3 --- pom.xml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 07e1e58e5..e15e6ab78 100644 --- a/pom.xml +++ b/pom.xml @@ -24,17 +24,16 @@ 2.2 1.2 - 7.0.47 + 7.0.47 2.2.7 4.3.8.Final - 4.3.1.Final + 5.1.3.Final - 7.0.42 2.6.10 2.3.2 @@ -80,7 +79,7 @@ org.apache.tomcat tomcat-servlet-api - ${tomcat.servlet.version} + ${tomcat.version} provided @@ -89,6 +88,12 @@ ${jsp.version} provided + + org.apache.tomcat + tomcat-jasper-el + ${tomcat.version} + provided + org.glassfish.web @@ -203,7 +208,7 @@ org.apache.tomcat tomcat-jdbc - ${tomcat-jdbc.version} + ${tomcat.version} runtime From 80ff54ac03c32d5974b2e5e6e9ed6bde10402372 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Mon, 29 Jun 2015 08:37:29 +0200 Subject: [PATCH 18/30] Fix #89 Web layer: use @Valid whenever possible --- .../samples/petclinic/web/PetController.java | 12 ++++++------ .../samples/petclinic/web/PetValidator.java | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/web/PetController.java b/src/main/java/org/springframework/samples/petclinic/web/PetController.java index ea8aeaaa8..bf823023e 100644 --- a/src/main/java/org/springframework/samples/petclinic/web/PetController.java +++ b/src/main/java/org/springframework/samples/petclinic/web/PetController.java @@ -34,6 +34,8 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.SessionAttributes; import org.springframework.web.bind.support.SessionStatus; +import javax.validation.Valid; + /** * @author Juergen Hoeller * @author Ken Krebs @@ -57,8 +59,9 @@ public class PetController { } @InitBinder - public void setAllowedFields(WebDataBinder dataBinder) { + public void initBinder(WebDataBinder dataBinder) { dataBinder.setDisallowedFields("id"); + dataBinder.setValidator(new PetValidator()); } @RequestMapping(value = "/owners/{ownerId}/pets/new", method = RequestMethod.GET) @@ -71,8 +74,7 @@ public class PetController { } @RequestMapping(value = "/owners/{ownerId}/pets/new", method = RequestMethod.POST) - public String processCreationForm(@ModelAttribute("pet") Pet pet, BindingResult result, SessionStatus status) { - new PetValidator().validate(pet, result); + public String processCreationForm(@Valid Pet pet, BindingResult result, SessionStatus status) { if (result.hasErrors()) { return "pets/createOrUpdatePetForm"; } else { @@ -90,9 +92,7 @@ public class PetController { } @RequestMapping(value = "/owners/{ownerId}/pets/{petId}/edit", method = {RequestMethod.PUT, RequestMethod.POST}) - public String processUpdateForm(@ModelAttribute("pet") Pet pet, BindingResult result, SessionStatus status) { - // we're not using @Valid annotation here because it is easier to define such validation rule in Java - new PetValidator().validate(pet, result); + public String processUpdateForm(@Valid Pet pet, BindingResult result, SessionStatus status) { if (result.hasErrors()) { return "pets/createOrUpdatePetForm"; } else { diff --git a/src/main/java/org/springframework/samples/petclinic/web/PetValidator.java b/src/main/java/org/springframework/samples/petclinic/web/PetValidator.java index 03a1bca7c..0621c98ab 100644 --- a/src/main/java/org/springframework/samples/petclinic/web/PetValidator.java +++ b/src/main/java/org/springframework/samples/petclinic/web/PetValidator.java @@ -18,16 +18,22 @@ package org.springframework.samples.petclinic.web; import org.springframework.samples.petclinic.model.Pet; import org.springframework.util.StringUtils; import org.springframework.validation.Errors; +import org.springframework.validation.Validator; /** * Validator for Pet forms. + *

    + * We're not using Bean Validation annotations here because it is easier to define such validation rule in Java. + *

    * * @author Ken Krebs * @author Juergen Hoeller */ -public class PetValidator { +public class PetValidator implements Validator { - public void validate(Pet pet, Errors errors) { + @Override + public void validate(Object obj, Errors errors) { + Pet pet = (Pet) obj; String name = pet.getName(); // name validation if (!StringUtils.hasLength(name)) { @@ -47,4 +53,13 @@ public class PetValidator { } } + /** + * This Validator validates *just* Pet instances + */ + @Override + public boolean supports(Class clazz) { + return Pet.class.equals(clazz); + } + + } From 8b625617cb24353ee906fab080c7677a6ec37870 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Mon, 29 Jun 2015 08:50:04 +0200 Subject: [PATCH 19/30] #87 Petclinic should be compatible with Java 7 for the time being --- pom.xml | 2 +- .../org/springframework/samples/petclinic/model/Owner.java | 4 ++-- .../org/springframework/samples/petclinic/model/Pet.java | 4 ++-- .../org/springframework/samples/petclinic/model/Vet.java | 4 ++-- .../org/springframework/samples/petclinic/model/Vets.java | 2 +- .../petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java | 6 +++--- .../petclinic/repository/jdbc/JdbcPetRepositoryImpl.java | 4 ++-- .../petclinic/repository/jdbc/JdbcVetRepositoryImpl.java | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index e15e6ab78..201f6dd36 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ - 1.8 + 1.7 UTF-8 UTF-8 diff --git a/src/main/java/org/springframework/samples/petclinic/model/Owner.java b/src/main/java/org/springframework/samples/petclinic/model/Owner.java index 840a965ed..ca7c97ec2 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Owner.java +++ b/src/main/java/org/springframework/samples/petclinic/model/Owner.java @@ -91,13 +91,13 @@ public class Owner extends Person { protected Set getPetsInternal() { if (this.pets == null) { - this.pets = new HashSet(); + this.pets = new HashSet<>(); } return this.pets; } public List getPets() { - List sortedPets = new ArrayList(getPetsInternal()); + List sortedPets = new ArrayList<>(getPetsInternal()); PropertyComparator.sort(sortedPets, new MutableSortDefinition("name", true, true)); return Collections.unmodifiableList(sortedPets); } diff --git a/src/main/java/org/springframework/samples/petclinic/model/Pet.java b/src/main/java/org/springframework/samples/petclinic/model/Pet.java index 4bc2b92f7..536fe07e6 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Pet.java +++ b/src/main/java/org/springframework/samples/petclinic/model/Pet.java @@ -94,13 +94,13 @@ public class Pet extends NamedEntity { protected Set getVisitsInternal() { if (this.visits == null) { - this.visits = new HashSet(); + this.visits = new HashSet<>(); } return this.visits; } public List getVisits() { - List sortedVisits = new ArrayList(getVisitsInternal()); + List sortedVisits = new ArrayList<>(getVisitsInternal()); PropertyComparator.sort(sortedVisits, new MutableSortDefinition("date", false, false)); return Collections.unmodifiableList(sortedVisits); } diff --git a/src/main/java/org/springframework/samples/petclinic/model/Vet.java b/src/main/java/org/springframework/samples/petclinic/model/Vet.java index c58bd85b2..61c518786 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Vet.java +++ b/src/main/java/org/springframework/samples/petclinic/model/Vet.java @@ -56,14 +56,14 @@ public class Vet extends Person { protected Set getSpecialtiesInternal() { if (this.specialties == null) { - this.specialties = new HashSet(); + this.specialties = new HashSet<>(); } return this.specialties; } @XmlElement public List getSpecialties() { - List sortedSpecs = new ArrayList(getSpecialtiesInternal()); + List sortedSpecs = new ArrayList<>(getSpecialtiesInternal()); PropertyComparator.sort(sortedSpecs, new MutableSortDefinition("name", true, true)); return Collections.unmodifiableList(sortedSpecs); } diff --git a/src/main/java/org/springframework/samples/petclinic/model/Vets.java b/src/main/java/org/springframework/samples/petclinic/model/Vets.java index e8f44a7bc..aaf96b685 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Vets.java +++ b/src/main/java/org/springframework/samples/petclinic/model/Vets.java @@ -36,7 +36,7 @@ public class Vets { @XmlElement public List getVetList() { if (vets == null) { - vets = new ArrayList(); + vets = new ArrayList<>(); } return vets; } diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java index 31839ad12..63aec2a1f 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java @@ -73,7 +73,7 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository { */ @Override public Collection findByLastName(String lastName) throws DataAccessException { - Map params = new HashMap(); + Map params = new HashMap<>(); params.put("lastName", lastName + "%"); List owners = this.namedParameterJdbcTemplate.query( "SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE last_name like :lastName", @@ -92,7 +92,7 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository { public Owner findById(int id) throws DataAccessException { Owner owner; try { - Map params = new HashMap(); + Map 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", @@ -107,7 +107,7 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository { } public void loadPetsAndVisits(final Owner owner) { - Map params = new HashMap(); + Map params = new HashMap<>(); params.put("id", owner.getId()); final List pets = this.namedParameterJdbcTemplate.query( "SELECT pets.id, name, birth_date, type_id, owner_id, visits.id, visit_date, description, pet_id FROM pets LEFT OUTER JOIN visits ON pets.id = pet_id WHERE owner_id=:id", diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImpl.java index e068791a1..e3c02fc93 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcPetRepositoryImpl.java @@ -73,7 +73,7 @@ public class JdbcPetRepositoryImpl implements PetRepository { @Override public List findPetTypes() throws DataAccessException { - Map params = new HashMap(); + Map params = new HashMap<>(); return this.namedParameterJdbcTemplate.query( "SELECT id, name FROM types ORDER BY name", params, @@ -84,7 +84,7 @@ public class JdbcPetRepositoryImpl implements PetRepository { public Pet findById(int id) throws DataAccessException { JdbcPet pet; try { - Map params = new HashMap(); + Map 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", diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java index f6e91cf5e..cf6ec3e42 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java @@ -60,7 +60,7 @@ public class JdbcVetRepositoryImpl implements VetRepository { */ @Override public Collection findAll() throws DataAccessException { - List vets = new ArrayList(); + List 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", From 7fe5184bc8326b2f5ab19c00ecae850b096a94f4 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Mon, 29 Jun 2015 09:01:08 +0200 Subject: [PATCH 20/30] Servlet 3.0, JSP 2.2 and EL 2.2 are the minimum required to deploy Petclinic --- src/main/webapp/WEB-INF/web.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 2bb1d5f84..bd3ea6d4a 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -1,9 +1,9 @@ - + http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" + version="3.0" metadata-complete="true"> Spring PetClinic Spring PetClinic sample application From 0fdd1504b43c789727834fa7d2cd362d08833c71 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Mon, 29 Jun 2015 09:03:58 +0200 Subject: [PATCH 21/30] Removing deprecated javadoc --- .../petclinic/repository/jdbc/JdbcVetRepositoryImpl.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java index cf6ec3e42..79db917f9 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVetRepositoryImpl.java @@ -32,8 +32,7 @@ import org.springframework.samples.petclinic.util.EntityUtils; import org.springframework.stereotype.Repository; /** - * A simple JDBC-based implementation of the {@link VetRepository} interface. Uses @Cacheable to cache the result of the - * {@link findAll} method + * A simple JDBC-based implementation of the {@link VetRepository} interface. * * @author Ken Krebs * @author Juergen Hoeller @@ -55,8 +54,6 @@ public class JdbcVetRepositoryImpl implements VetRepository { /** * Refresh the cache of Vets that the ClinicService is holding. - * - * @see org.springframework.samples.petclinic.model.service.ClinicService#shouldFindVets() */ @Override public Collection findAll() throws DataAccessException { From 11af3ae3e9e4155dc9e435d5f8b34b5ceed6383e Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Thu, 2 Jul 2015 08:11:02 +0200 Subject: [PATCH 22/30] #90 Reduce the POM size by inheriting from the spring.io BOM --- pom.xml | 108 ++++++++++++++------------------------------------------ 1 file changed, 26 insertions(+), 82 deletions(-) diff --git a/pom.xml b/pom.xml index 201f6dd36..397d8dffe 100644 --- a/pom.xml +++ b/pom.xml @@ -16,45 +16,22 @@ UTF-8 - 4.1.6.RELEASE - 1.8.0.RELEASE + 1.1.2.RELEASE 1.1.0.RELEASE - 2.2 - 1.2 - 7.0.47 - 2.2.7 - - - 4.3.8.Final - - - 5.1.3.Final - - - 2.6.10 - 2.3.2 - - - 1.8.5 - - - 1.1.3 - 1.7.12 + 7.0.59 2.0.0 - 4.12 3.0.0 1.3 1.1.1 - 2.7 3.2.0.GA @@ -64,12 +41,23 @@ 2.0.3-1 0.10.1 - 5.1.22 - 2.7 + + + + + io.spring.platform + platform-bom + ${spring-io-platform.version} + pom + import + + + + org.jadira.usertype @@ -83,11 +71,10 @@ provided - javax.servlet.jsp - jsp-api - ${jsp.version} - provided - + javax.servlet.jsp + javax.servlet.jsp-api + provided +
    org.apache.tomcat tomcat-jasper-el @@ -96,21 +83,12 @@ - org.glassfish.web - jstl-impl - ${jstl.version} - - - javax.servlet - servlet-api - - + javax.servlet.jsp.jstl + javax.servlet.jsp.jstl-api - com.sun.xml.bind - jaxb-impl - ${jaxb-impl.version} - provided + org.apache.taglibs + taglibs-standard-jstlel @@ -123,14 +101,6 @@ org.springframework.data spring-data-jpa - ${spring-data-jpa.version} - - - org.springframework - * - - - @@ -149,55 +119,40 @@ org.springframework spring-jdbc - ${spring-framework.version} org.springframework spring-aop - ${spring-framework.version} org.springframework spring-webmvc - ${spring-framework.version} org.springframework spring-tx - ${spring-framework.version} org.springframework spring-context-support - ${spring-framework.version} org.springframework spring-orm - ${spring-framework.version} org.springframework spring-oxm - ${spring-framework.version} - - - commons-lang - commons-lang - - org.aspectj aspectjrt - ${aspectj.version} org.aspectj aspectjweaver - ${aspectj.version} runtime @@ -208,7 +163,6 @@ org.apache.tomcat tomcat-jdbc - ${tomcat.version} runtime @@ -216,13 +170,10 @@ org.slf4j slf4j-api - ${slf4j.version} - compile ch.qos.logback logback-classic - ${logback.version} runtime @@ -230,7 +181,6 @@ joda-time joda-time - ${jodatime.version} joda-time @@ -244,37 +194,31 @@ - org.hsqldb hsqldb - ${hsqldb.version} runtime - + org.hibernate hibernate-entitymanager - ${hibernate.version} org.hibernate hibernate-validator - ${hibernate-validator.version} org.hibernate hibernate-ehcache - ${hibernate.version} net.sf.ehcache ehcache-core - ${ehcache.version} commons-logging @@ -303,19 +247,18 @@ org.springframework spring-test - ${spring-framework.version} test junit junit - ${junit.version} test org.assertj assertj-core ${assertj.version} + test @@ -452,6 +395,7 @@ html + From bc9682cfb3e0e97046e3d347731e00aef47aa2f8 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Thu, 2 Jul 2015 18:15:25 +0200 Subject: [PATCH 23/30] #87 Downgrade to AssertJ 2.1.0 in order to build Petclinic with the JDK 7 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 397d8dffe..925f79c30 100644 --- a/pom.xml +++ b/pom.xml @@ -27,7 +27,7 @@ 2.0.0 - 3.0.0 + 2.1.0 1.3 From 7326267c48f67ec3d01b5597aad607b6a4b16686 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Thu, 2 Jul 2015 18:20:17 +0200 Subject: [PATCH 24/30] #90 Remove the json-path version which be inherited from the spring.io BOM --- pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pom.xml b/pom.xml index 925f79c30..07d633a23 100644 --- a/pom.xml +++ b/pom.xml @@ -23,9 +23,6 @@ 7.0.59 - - 2.0.0 - 2.1.0 @@ -94,7 +91,6 @@ com.jayway.jsonpath json-path - ${json-path.version} test From 122c8a74b9a03526ecf65e67361b6d3a562f3a24 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Wed, 15 Jul 2015 21:53:05 +0200 Subject: [PATCH 25/30] Upgrade to Spring IO platform v1.1.3. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 07d633a23..076435e8b 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ UTF-8 - 1.1.2.RELEASE + 1.1.3.RELEASE 1.1.0.RELEASE From 8e3848f9c5cc8ea55523ab0f275243479adf63fa Mon Sep 17 00:00:00 2001 From: michaelisvy Date: Sat, 25 Jul 2015 19:30:23 +0800 Subject: [PATCH 26/30] upgraded to latest version of Dandelion --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 076435e8b..84614f31c 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ 2.3.0 1.10.3 2.0.3-1 - 0.10.1 + 1.0.1 2.7 From 85a2be1c11adeee9c72eabe901b3dac525e4cdd4 Mon Sep 17 00:00:00 2001 From: michaelisvy Date: Sat, 25 Jul 2015 19:38:02 +0800 Subject: [PATCH 27/30] adding spring boot starter and removing spring-aop --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 84614f31c..aab99a052 100644 --- a/pom.xml +++ b/pom.xml @@ -94,6 +94,10 @@ test + + org.springframework.boot + spring-boot-starter + org.springframework.data spring-data-jpa @@ -116,10 +120,6 @@ org.springframework spring-jdbc - - org.springframework - spring-aop - org.springframework spring-webmvc From 39ab8361d4fae189295af5fc4af848f4c6bd3756 Mon Sep 17 00:00:00 2001 From: michaelisvy Date: Sat, 25 Jul 2015 19:44:53 +0800 Subject: [PATCH 28/30] moved spring-data dependency to boot-starter --- pom.xml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index aab99a052..3f2e357ca 100644 --- a/pom.xml +++ b/pom.xml @@ -99,8 +99,8 @@ spring-boot-starter - org.springframework.data - spring-data-jpa + org.springframework.boot + spring-boot-starter-data-jpa @@ -124,19 +124,11 @@ org.springframework spring-webmvc - - org.springframework - spring-tx - org.springframework spring-context-support - - org.springframework - spring-orm - org.springframework spring-oxm From 91d19d17b817eb7c24593ea3a3c1ef52374b2eee Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Wed, 19 Aug 2015 18:44:14 +0200 Subject: [PATCH 29/30] #92 Fix column 'visits.id' not found on MySql --- .../petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java | 2 +- .../samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java index a923b7652..62bf430e9 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java @@ -81,7 +81,7 @@ public class JdbcVisitRepositoryImpl implements VisitRepository { @Override public List findByPetId(Integer petId) { return this.jdbcTemplate.query( - "SELECT id as visit_id, visit_date, description FROM visits WHERE pet_id=?", + "SELECT id, visit_date, description FROM visits WHERE pet_id=?", new JdbcVisitRowMapper(), petId); } diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java index d6dd0cbf8..0577182e3 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java @@ -33,7 +33,7 @@ class JdbcVisitRowMapper implements RowMapper { @Override public Visit mapRow(ResultSet rs, int row) throws SQLException { Visit visit = new Visit(); - visit.setId(rs.getInt("visits.id")); + visit.setId(rs.getInt("id")); Date visitDate = rs.getDate("visit_date"); visit.setDate(new DateTime(visitDate)); visit.setDescription(rs.getString("description")); From 06be7eb5bee7792109ef00302506888312429819 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Thu, 20 Aug 2015 08:13:03 +0200 Subject: [PATCH 30/30] #92 Use column alias --- .../petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java | 2 +- .../petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java | 2 +- .../samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java index 63aec2a1f..0a471b4d8 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcOwnerRepositoryImpl.java @@ -110,7 +110,7 @@ public class JdbcOwnerRepositoryImpl implements OwnerRepository { Map params = new HashMap<>(); params.put("id", owner.getId()); final List pets = this.namedParameterJdbcTemplate.query( - "SELECT pets.id, name, birth_date, type_id, owner_id, visits.id, visit_date, description, pet_id FROM pets LEFT OUTER JOIN visits ON pets.id = pet_id WHERE owner_id=:id", + "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() ); diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java index 62bf430e9..a923b7652 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRepositoryImpl.java @@ -81,7 +81,7 @@ public class JdbcVisitRepositoryImpl implements VisitRepository { @Override public List findByPetId(Integer petId) { return this.jdbcTemplate.query( - "SELECT id, visit_date, description FROM visits WHERE pet_id=?", + "SELECT id as visit_id, visit_date, description FROM visits WHERE pet_id=?", new JdbcVisitRowMapper(), petId); } diff --git a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java index 0577182e3..94069042b 100644 --- a/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java +++ b/src/main/java/org/springframework/samples/petclinic/repository/jdbc/JdbcVisitRowMapper.java @@ -33,7 +33,7 @@ class JdbcVisitRowMapper implements RowMapper { @Override public Visit mapRow(ResultSet rs, int row) throws SQLException { Visit visit = new Visit(); - visit.setId(rs.getInt("id")); + visit.setId(rs.getInt("visit_id")); Date visitDate = rs.getDate("visit_date"); visit.setDate(new DateTime(visitDate)); visit.setDescription(rs.getString("description"));