@@ -36,11 +36,15 @@ public Predicate toPredicate(@NonNull Root<S> root, @NonNull CriteriaQuery<?> qu
36
36
return predicates .toPredicate (criteriaBuilder );
37
37
}
38
38
39
- private boolean isCountQuery (CriteriaQuery <?> query ) {
39
+ private static boolean isCountQuery (CriteriaQuery <?> query ) {
40
40
return query .getResultType () == Long .class ;
41
41
}
42
42
43
- protected void initPredicatesRecursively (Predicates predicates , CriteriaQuery <?> query , Node <Filter > node , From <S , S > from , FetchParent <S , S > fetch , CriteriaBuilder criteriaBuilder ) {
43
+ private static boolean isAggregateQuery (CriteriaQuery <?> query ) {
44
+ return query .getGroupList ().size () > 0 ;
45
+ }
46
+
47
+ private void initPredicatesRecursively (Predicates predicates , CriteriaQuery <?> query , Node <Filter > node , From <S , S > from , FetchParent <S , S > fetch , CriteriaBuilder criteriaBuilder ) {
44
48
if (node .isLeaf ()) {
45
49
boolean hasColumnFilter = node .getData () != null ;
46
50
if (hasColumnFilter ) {
@@ -62,7 +66,7 @@ protected void initPredicatesRecursively(Predicates predicates, CriteriaQuery<?>
62
66
} else {
63
67
Join <S , S > join = from .join (child .getName (), JoinType .LEFT );
64
68
65
- if (isCountQuery (query )) {
69
+ if (isCountQuery (query ) || isAggregateQuery ( query ) ) {
66
70
initPredicatesRecursively (predicates , query , child , join , join , criteriaBuilder );
67
71
} else {
68
72
Fetch <S , S > childFetch = fetch .fetch (child .getName (), JoinType .LEFT );
@@ -73,41 +77,6 @@ protected void initPredicatesRecursively(Predicates predicates, CriteriaQuery<?>
73
77
}
74
78
}
75
79
76
- private class DataTablesSearchPaneSpecification <S > extends DataTablesSpecification <S > {
77
-
78
- @ Override
79
- protected void initPredicatesRecursively (Predicates predicates , CriteriaQuery <?> query , Node <Filter > node , From <S , S > from ,
80
- FetchParent <S , S > fetch , CriteriaBuilder criteriaBuilder ) {
81
- if (node .isLeaf ()) {
82
- boolean hasColumnFilter = node .getData () != null ;
83
- if (hasColumnFilter ) {
84
- Filter columnFilter = node .getData ();
85
- predicates .columns .add (columnFilter .createPredicate (from , criteriaBuilder , node .getName ()));
86
- } else if (hasGlobalFilter ) {
87
- Filter globalFilter = tree .getData ();
88
- predicates .global .add (globalFilter .createPredicate (from , criteriaBuilder , node .getName ()));
89
- }
90
- }
91
- for (Node <Filter > child : node .getChildren ()) {
92
- Path <Object > path = from .get (child .getName ());
93
- if (path .getModel ().getBindableType () == BindableType .PLURAL_ATTRIBUTE ) {
94
- // ignore OneToMany and ManyToMany relationships
95
- continue ;
96
- }
97
- if (child .isLeaf ()) {
98
- initPredicatesRecursively (predicates , query , child , from , fetch , criteriaBuilder );
99
- } else {
100
- Join <S , S > join = from .join (child .getName (), JoinType .LEFT );
101
- initPredicatesRecursively (predicates , query , child , join , fetch , criteriaBuilder );
102
- }
103
- }
104
- }
105
- }
106
-
107
- public Specification <T > buildSearchPane () {
108
- return new DataTablesSearchPaneSpecification <>();
109
- }
110
-
111
80
private static class Predicates {
112
81
public List <Predicate > columns = new ArrayList <>();
113
82
public List <Predicate > global = new ArrayList <>();
0 commit comments