DATAJPA-564 - Add support for dynamically evaluating SpEL expressions in derived queries.
We now support the dynamic discovery and binding of SpEL Expression parameters in query derivation. Introduced ExpressionAwareParameterBinder for generic SpEL expression evaluation support.
This commit is contained in:
committed by
Oliver Gierke
parent
c4f245b11e
commit
a94a807bb3
@@ -59,6 +59,8 @@ import org.springframework.data.jpa.domain.sample.Role;
|
||||
import org.springframework.data.jpa.domain.sample.SpecialUser;
|
||||
import org.springframework.data.jpa.domain.sample.User;
|
||||
import org.springframework.data.jpa.repository.sample.UserRepository;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -287,7 +289,7 @@ public class UserRepositoryTests {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
repository.findByLastname(null);
|
||||
repository.findByLastname((String) null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1615,6 +1617,21 @@ public class UserRepositoryTests {
|
||||
assertThat(users.get(0), is(firstUser));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-XXX
|
||||
*/
|
||||
@Test
|
||||
public void shouldFindUserByLastnameWithSpelExpressionInDerivedQuery() {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
Expression expr = new SpelExpressionParser().parseExpression("'Gier' + 'ke'");
|
||||
List<User> users = repository.queryByLastname(expr);
|
||||
|
||||
assertThat(users, hasSize(1));
|
||||
assertThat(users.get(0), is(firstUser));
|
||||
}
|
||||
|
||||
private Page<User> executeSpecWithSort(Sort sort) {
|
||||
|
||||
flushTestUsers();
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.data.jpa.repository.QueryHints;
|
||||
import org.springframework.data.jpa.repository.query.Procedure;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
@@ -471,4 +472,9 @@ public interface UserRepository extends JpaRepository<User, Integer>, JpaSpecifi
|
||||
*/
|
||||
@Query("select u from User u where u.lastname like %:#{[0]}% and u.lastname like %:lastname%")
|
||||
List<User> findByLastnameWithSpelExpression(@Param("lastname") String lastname);
|
||||
|
||||
/**
|
||||
* @see DATAJPA-XXX
|
||||
*/
|
||||
List<User> queryByLastname(Expression lastname);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user