From ae594415de21f2543c2d7d0d7e6ca02e5482654e Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Tue, 23 Jul 2019 11:13:22 +0200 Subject: [PATCH] DATAJPA-1579 - Polishing. Formatting the code. Original pull request: #390. --- .../data/jpa/domain/sample/User.java | 32 +------------- ...sitoryStoredProcedureIntegrationTests.java | 28 ++++++------ .../jpa/repository/sample/UserRepository.java | 43 ++++++++++--------- 3 files changed, 38 insertions(+), 65 deletions(-) diff --git a/src/test/java/org/springframework/data/jpa/domain/sample/User.java b/src/test/java/org/springframework/data/jpa/domain/sample/User.java index 734b2c65f..8f167a043 100644 --- a/src/test/java/org/springframework/data/jpa/domain/sample/User.java +++ b/src/test/java/org/springframework/data/jpa/domain/sample/User.java @@ -20,35 +20,7 @@ import java.util.Date; import java.util.HashSet; import java.util.Set; -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.ColumnResult; -import javax.persistence.ElementCollection; -import javax.persistence.Embedded; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Lob; -import javax.persistence.ManyToMany; -import javax.persistence.ManyToOne; -import javax.persistence.NamedAttributeNode; -import javax.persistence.NamedEntityGraph; -import javax.persistence.NamedEntityGraphs; -import javax.persistence.NamedNativeQueries; -import javax.persistence.NamedNativeQuery; -import javax.persistence.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.NamedStoredProcedureQueries; -import javax.persistence.NamedStoredProcedureQuery; -import javax.persistence.NamedSubgraph; -import javax.persistence.ParameterMode; -import javax.persistence.SqlResultSetMapping; -import javax.persistence.SqlResultSetMappings; -import javax.persistence.StoredProcedureParameter; -import javax.persistence.Table; -import javax.persistence.Temporal; -import javax.persistence.TemporalType; +import javax.persistence.*; /** * Domain class representing a person emphasizing the use of {@code AbstractEntity}. No declaration of an id is @@ -102,7 +74,7 @@ import javax.persistence.TemporalType; @NamedStoredProcedureQuery(name = "User.plus1IOoptional", procedureName = "plus1inoutoptional", parameters = { @StoredProcedureParameter(mode = ParameterMode.IN, name = "arg", type = Integer.class), @StoredProcedureParameter(mode = ParameterMode.OUT, name = "res", type = Integer.class), - @StoredProcedureParameter(mode = ParameterMode.OUT, name = "res2", type = Integer.class) }) // DATAJPA-1579 + @StoredProcedureParameter(mode = ParameterMode.OUT, name = "res2", type = Integer.class) }) // DATAJPA-1579 }) @NamedStoredProcedureQuery(name = "User.plus1IO", procedureName = "plus1inout", parameters = { @StoredProcedureParameter(mode = ParameterMode.IN, name = "arg", type = Integer.class), diff --git a/src/test/java/org/springframework/data/jpa/repository/UserRepositoryStoredProcedureIntegrationTests.java b/src/test/java/org/springframework/data/jpa/repository/UserRepositoryStoredProcedureIntegrationTests.java index 35a409a3f..6e2b1eccd 100644 --- a/src/test/java/org/springframework/data/jpa/repository/UserRepositoryStoredProcedureIntegrationTests.java +++ b/src/test/java/org/springframework/data/jpa/repository/UserRepositoryStoredProcedureIntegrationTests.java @@ -15,6 +15,15 @@ */ package org.springframework.data.jpa.repository; +import static org.assertj.core.api.Assertions.*; + +import java.util.Map; + +import javax.persistence.EntityManager; +import javax.persistence.ParameterMode; +import javax.persistence.PersistenceContext; +import javax.persistence.StoredProcedureQuery; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -24,15 +33,6 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; -import javax.persistence.EntityManager; -import javax.persistence.ParameterMode; -import javax.persistence.PersistenceContext; -import javax.persistence.StoredProcedureQuery; -import java.util.Map; -import java.util.Optional; - -import static org.assertj.core.api.Assertions.*; - /** * Integration tests for JPA 2.1 stored procedure support. * @@ -48,10 +48,8 @@ import static org.assertj.core.api.Assertions.*; @Transactional public class UserRepositoryStoredProcedureIntegrationTests { - @Autowired - UserRepository repository; - @PersistenceContext - EntityManager em; + @Autowired UserRepository repository; + @PersistenceContext EntityManager em; @Test // DATAJPA-455 public void callProcedureWithInAndOutParameters() { @@ -82,8 +80,8 @@ public class UserRepositoryStoredProcedureIntegrationTests { assertThatThrownBy( // () -> repository.entityAnnotatedCustomNamedProcedurePlus1IOInvalidOutParamName(1)) // - .isInstanceOf(InvalidDataAccessApiUsageException.class) // - .hasMessageContaining("parameter"); + .isInstanceOf(InvalidDataAccessApiUsageException.class) // + .hasMessageContaining("parameter"); } @Test // DATAJPA-707 diff --git a/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java b/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java index fb5a4ef28..3b535c276 100644 --- a/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java +++ b/src/test/java/org/springframework/data/jpa/repository/sample/UserRepository.java @@ -322,8 +322,8 @@ public interface UserRepository Integer plus1inout(Integer arg); /** - * Implicitly mapped to a procedure with name "plus1inout" in database via alias. - * Showing that outputParameterName is ignored when not a NamedStoredProcedure + * Implicitly mapped to a procedure with name "plus1inout" in database via alias. Showing that outputParameterName is + * ignored when not a NamedStoredProcedure */ @Procedure(procedureName = "plus1inout", outputParameterName = "fakeName") // DATAJPA-707 Integer plus1inoutInvalidOutParamName(Integer arg); @@ -335,29 +335,29 @@ public interface UserRepository Integer entityAnnotatedCustomNamedProcedurePlus1IO(@Param("arg") Integer arg); /** - * Explicitly mapped to named stored procedure "User.plus1IO" in {@link EntityManager}. - * with an invalid outputParameterName - test will fail + * Explicitly mapped to named stored procedure "User.plus1IO" in {@link EntityManager}. with an invalid + * outputParameterName - test will fail */ @Procedure(name = "User.plus1IO", outputParameterName = "fakeName") // DATAJPA-707 Integer entityAnnotatedCustomNamedProcedurePlus1IOInvalidOutParamName(@Param("arg") Integer arg); /** - * Explicitly mapped to named stored procedure "User.plus1IO2" in {@link EntityManager}. - * Stored Proc has 2 out params, but naming one out param here so it only returns one + * Explicitly mapped to named stored procedure "User.plus1IO2" in {@link EntityManager}. Stored Proc has 2 out params, + * but naming one out param here so it only returns one */ @Procedure(name = "User.plus1IO2", outputParameterName = "res2") // DATAJPA-707 Integer entityAnnotatedCustomNamedProcedurePlus1IO2TwoOutParamsButNamingOne(@Param("arg") Integer arg); /** - * Explicitly mapped to named stored procedure "User.plus1IO2" in {@link EntityManager}. - * Returns 2 out params as a Map. + * Explicitly mapped to named stored procedure "User.plus1IO2" in {@link EntityManager}. Returns 2 out params as a + * Map. */ @Procedure(name = "User.plus1IO2") // DATAJPA-707 DATAJPA-1579 Map entityAnnotatedCustomNamedProcedurePlus1IO2(@Param("arg") Integer arg); /** - * Explicitly mapped to named stored procedure "User.plus1IOoptional" in {@link EntityManager}. - * Returns 2 out params as a Map, second one amoung which is null. + * Explicitly mapped to named stored procedure "User.plus1IOoptional" in {@link EntityManager}. Returns 2 out params + * as a Map, second one amoung which is null. */ @Procedure(name = "User.plus1IOoptional") // DATAJPA-1579 Map entityAnnotatedCustomNamedProcedurePlus1IOoptional(@Param("arg") Integer arg); @@ -464,13 +464,13 @@ public interface UserRepository List findUsersByFirstnameForSpELExpressionWithParameterIndexOnly(String firstname); // DATAJPA-564 - @Query( - value = "select * from (" + - "select u.*, rownum() as RN from (" + - "select * from SD_User ORDER BY ucase(firstname)" + - ") u" + - ") where RN between ?#{ #pageable.offset +1 } and ?#{#pageable.offset + #pageable.pageSize}", - countQuery = "select count(u.id) from SD_User u", nativeQuery = true) + @Query(value = "select * from (" // + + "select u.*, rownum() as RN from (" // + + "select * from SD_User ORDER BY ucase(firstname)" // + + ") u" // + + ") where RN between ?#{ #pageable.offset +1 } and ?#{#pageable.offset + #pageable.pageSize}", // + countQuery = "select count(u.id) from SD_User u", // + nativeQuery = true) Page findUsersInNativeQueryWithPagination(Pageable pageable); // DATAJPA-1140 @@ -567,11 +567,14 @@ public interface UserRepository Page findAllOrderedBySpecialNameSingleParam(@Param("name") String name, Pageable page); // DATAJPA-1233 - @Query(value = "SELECT u FROM User u WHERE :other = 'x' ORDER BY CASE WHEN (u.firstname >= :name) THEN 0 ELSE 1 END, u.firstname") - Page findAllOrderedBySpecialNameMultipleParams(@Param("name") String name, @Param("other") String other, Pageable page); + @Query( + value = "SELECT u FROM User u WHERE :other = 'x' ORDER BY CASE WHEN (u.firstname >= :name) THEN 0 ELSE 1 END, u.firstname") + Page findAllOrderedBySpecialNameMultipleParams(@Param("name") String name, @Param("other") String other, + Pageable page); // DATAJPA-1233 - @Query(value = "SELECT u FROM User u WHERE ?2 = 'x' ORDER BY CASE WHEN (u.firstname >= ?1) THEN 0 ELSE 1 END, u.firstname") + @Query( + value = "SELECT u FROM User u WHERE ?2 = 'x' ORDER BY CASE WHEN (u.firstname >= ?1) THEN 0 ELSE 1 END, u.firstname") Page findAllOrderedBySpecialNameMultipleParamsIndexed(String name, String other, Pageable page); // DATAJPA-928