|
8 | 8 | import javax.persistence.criteria.Predicate; |
9 | 9 | import javax.persistence.criteria.Root; |
10 | 10 |
|
11 | | -import org.baeldung.persistence.model.User; |
12 | 11 | import org.springframework.data.jpa.domain.Specification; |
13 | 12 |
|
14 | 13 | import cz.jirutka.rsql.parser.ast.ComparisonOperator; |
15 | 14 |
|
16 | | -public class UserRsqlSpecification implements Specification<User> { |
| 15 | +public class GenericRsqlSpecification<T> implements Specification<T> { |
17 | 16 |
|
18 | 17 | private String property; |
19 | 18 | private ComparisonOperator operator; |
20 | 19 | private List<String> arguments; |
21 | 20 |
|
22 | | - public UserRsqlSpecification(final String property, final ComparisonOperator operator, final List<String> arguments) { |
| 21 | + public GenericRsqlSpecification(final String property, final ComparisonOperator operator, final List<String> arguments) { |
23 | 22 | super(); |
24 | 23 | this.property = property; |
25 | 24 | this.operator = operator; |
26 | 25 | this.arguments = arguments; |
27 | 26 | } |
28 | 27 |
|
29 | 28 | @Override |
30 | | - public Predicate toPredicate(final Root<User> root, final CriteriaQuery<?> query, final CriteriaBuilder builder) { |
| 29 | + public Predicate toPredicate(final Root<T> root, final CriteriaQuery<?> query, final CriteriaBuilder builder) { |
31 | 30 | final List<Object> args = castArguments(root); |
32 | 31 | final Object argument = args.get(0); |
33 | 32 | switch (RsqlSearchOperation.getSimpleOperator(operator)) { |
@@ -73,7 +72,7 @@ public Predicate toPredicate(final Root<User> root, final CriteriaQuery<?> query |
73 | 72 |
|
74 | 73 | // === private |
75 | 74 |
|
76 | | - private List<Object> castArguments(final Root<User> root) { |
| 75 | + private List<Object> castArguments(final Root<T> root) { |
77 | 76 | final List<Object> args = new ArrayList<Object>(); |
78 | 77 | final Class<? extends Object> type = root.get(property).getJavaType(); |
79 | 78 |
|
|
0 commit comments