DATAJPA-1579 - Polishing.
Formatting the code. Original pull request: #390.
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<String, Integer> 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<String, Integer> entityAnnotatedCustomNamedProcedurePlus1IOoptional(@Param("arg") Integer arg);
|
||||
@@ -464,13 +464,13 @@ public interface UserRepository
|
||||
List<User> 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<User> findUsersInNativeQueryWithPagination(Pageable pageable);
|
||||
|
||||
// DATAJPA-1140
|
||||
@@ -567,11 +567,14 @@ public interface UserRepository
|
||||
Page<User> 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<User> 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<User> 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<User> findAllOrderedBySpecialNameMultipleParamsIndexed(String name, String other, Pageable page);
|
||||
|
||||
// DATAJPA-928
|
||||
|
||||
Reference in New Issue
Block a user