Fix order by clauses for functions with positional and named arguments.
Related: #2045. Closes #425.
This commit is contained in:
@@ -77,6 +77,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Diego Krupitza
|
||||
* @author Jędrzej Biedrzycki
|
||||
* @author Darin Manica
|
||||
* @author Simon Paradies
|
||||
*/
|
||||
public abstract class QueryUtils {
|
||||
|
||||
@@ -182,7 +183,7 @@ public abstract class QueryUtils {
|
||||
|
||||
builder = new StringBuilder();
|
||||
// any function call including parameters within the brackets
|
||||
builder.append("\\w+\\s*\\([\\w\\.,\\s'=]+\\)");
|
||||
builder.append("\\w+\\s*\\([\\w\\.,\\s'=:\\\\?]+\\)");
|
||||
// the potential alias
|
||||
builder.append("\\s+[as|AS]+\\s+(([\\w\\.]+))");
|
||||
|
||||
|
||||
@@ -95,6 +95,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @author Greg Turnquist
|
||||
* @author Diego Krupitza
|
||||
* @author Daniel Shuy
|
||||
* @author Simon Paradies
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@ContextConfiguration("classpath:application-context.xml")
|
||||
@@ -2877,6 +2878,16 @@ public class UserRepositoryTests {
|
||||
assertThat(initialCount - finalCount).isEqualTo(3L);
|
||||
}
|
||||
|
||||
@Test // GH-2045, GH-425
|
||||
public void correctlyBuildSortClauseWhenSortingByFunctionAliasAndFunctionContainsPositionalParameters() {
|
||||
repository.findAllAndSortByFunctionResultPositionalParameter("prefix", "suffix", Sort.by("idWithPrefixAndSuffix"));
|
||||
}
|
||||
|
||||
@Test // GH-2045, GH-425
|
||||
public void correctlyBuildSortClauseWhenSortingByFunctionAliasAndFunctionContainsNamedParameters() {
|
||||
repository.findAllAndSortByFunctionResultNamedParameter("prefix", "suffix", Sort.by("idWithPrefixAndSuffix"));
|
||||
}
|
||||
|
||||
private Page<User> executeSpecWithSort(Sort sort) {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
@@ -54,6 +54,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @author Andrey Kovalev
|
||||
* @author JyotirmoyVS
|
||||
* @author Greg Turnquist
|
||||
* @author Simon Paradies
|
||||
*/
|
||||
public interface UserRepository
|
||||
extends JpaRepository<User, Integer>, JpaSpecificationExecutor<User>, UserRepositoryCustom {
|
||||
@@ -625,6 +626,17 @@ public interface UserRepository
|
||||
// GH-2408
|
||||
List<NameOnly> findAllInterfaceProjectedBy();
|
||||
|
||||
// GH-2045, GH-425
|
||||
@Query("select concat(?1,u.id,?2) as idWithPrefixAndSuffix from #{#entityName} u")
|
||||
List<String> findAllAndSortByFunctionResultPositionalParameter(
|
||||
@Param("positionalParameter1") String positionalParameter1,
|
||||
@Param("positionalParameter2") String positionalParameter2, Sort sort);
|
||||
|
||||
// GH-2045, GH-425
|
||||
@Query("select concat(:namedParameter1,u.id,:namedParameter2) as idWithPrefixAndSuffix from #{#entityName} u")
|
||||
List<String> findAllAndSortByFunctionResultNamedParameter(@Param("namedParameter1") String namedParameter1,
|
||||
@Param("namedParameter2") String namedParameter2, Sort sort);
|
||||
|
||||
interface RolesAndFirstname {
|
||||
|
||||
String getFirstname();
|
||||
|
||||
Reference in New Issue
Block a user