6
6
*/
7
7
package org .hibernate .query .sqm .internal ;
8
8
9
+ import java .util .Collection ;
10
+ import java .util .HashSet ;
9
11
import java .util .function .Supplier ;
10
12
11
13
import org .hibernate .LockOptions ;
16
18
import org .hibernate .query .spi .QueryOptions ;
17
19
18
20
import static java .lang .Boolean .TRUE ;
21
+ import static org .hibernate .query .spi .AbstractSelectionQuery .CRITERIA_HQL_STRING ;
19
22
20
23
/**
21
24
* @author Steve Ebersole
@@ -33,49 +36,39 @@ public interface InterpretationsKeySource extends CacheabilityInfluencers {
33
36
}
34
37
35
38
public static SqmInterpretationsKey createInterpretationsKey (InterpretationsKeySource keySource ) {
36
- if ( ! isCacheable ( keySource ) ) {
39
+ if ( isCacheable (keySource ) ) {
40
+ return new SqmInterpretationsKey (
41
+ keySource .getQueryString (),
42
+ keySource .getResultType (),
43
+ keySource .getQueryOptions ().getLockOptions (),
44
+ keySource .getQueryOptions ().getTupleTransformer (),
45
+ keySource .getQueryOptions ().getResultListTransformer (),
46
+ new HashSet <>( keySource .getLoadQueryInfluencers ().getEnabledFetchProfileNames () )
47
+ );
48
+ }
49
+ else {
37
50
return null ;
38
51
}
39
-
40
- return new SqmInterpretationsKey (
41
- keySource .getQueryString (),
42
- keySource .getResultType (),
43
- keySource .getQueryOptions ().getLockOptions (),
44
- keySource .getQueryOptions ().getTupleTransformer (),
45
- keySource .getQueryOptions ().getResultListTransformer ()
46
- );
47
52
}
48
- @ SuppressWarnings ( "RedundantIfStatement" )
53
+
49
54
private static boolean isCacheable (InterpretationsKeySource keySource ) {
50
55
assert keySource .getQueryOptions ().getAppliedGraph () != null ;
51
56
52
- if ( QuerySqmImpl .CRITERIA_HQL_STRING .equals ( keySource .getQueryString () ) ) {
53
- // for now at least, skip caching Criteria-based plans
54
- // - especially wrt parameters atm; this works with HQL because the parameters
55
- // are part of the query string; with Criteria, they are not.
56
- return false ;
57
- }
58
-
59
- if ( keySource .getLoadQueryInfluencers ().hasEnabledFilters () ) {
60
- // At the moment we cannot cache query plan if there is filter enabled.
61
- return false ;
62
- }
63
-
64
- if ( keySource .getQueryOptions ().getAppliedGraph ().getSemantic () != null ) {
65
- // At the moment we cannot cache query plan if there is an
66
- // EntityGraph enabled.
67
- return false ;
68
- }
69
-
70
- if ( keySource .hasMultiValuedParameterBindingsChecker ().get () == TRUE ) {
71
- // todo (6.0) : this one may be ok because of how I implemented multi-valued param handling
72
- // - the expansion is done per-execution based on the "static" SQM
73
- // - Note from Christian: The call to domainParameterXref.clearExpansions() in ConcreteSqmSelectQueryPlan is a concurrency issue when cached
74
- // - This could be solved by using a method-local clone of domainParameterXref when multi-valued params exist
75
- return false ;
76
- }
77
-
78
- return true ;
57
+ // for now at least, skip caching Criteria-based plans
58
+ // - especially wrt parameters atm; this works with HQL because the
59
+ // parameters are part of the query string; with Criteria, they're not.
60
+ return ! CRITERIA_HQL_STRING .equals ( keySource .getQueryString () )
61
+ // At the moment we cannot cache query plan if there is filter enabled.
62
+ && ! keySource .getLoadQueryInfluencers ().hasEnabledFilters ()
63
+ // At the moment we cannot cache query plan if it has an entity graph
64
+ && keySource .getQueryOptions ().getAppliedGraph ().getSemantic () == null
65
+ // todo (6.0) : this one may be ok because of how I implemented multi-valued param handling
66
+ // - the expansion is done per-execution based on the "static" SQM
67
+ // - Note from Christian: The call to domainParameterXref.clearExpansions()
68
+ // in ConcreteSqmSelectQueryPlan is a concurrency issue when cached
69
+ // - This could be solved by using a method-local clone of domainParameterXref
70
+ // when multi-valued params exist
71
+ && ! keySource .hasMultiValuedParameterBindingsChecker ().get () == TRUE ;
79
72
}
80
73
81
74
public static QueryInterpretationCache .Key generateNonSelectKey (InterpretationsKeySource keyDetails ) {
@@ -86,24 +79,26 @@ public static QueryInterpretationCache.Key generateNonSelectKey(InterpretationsK
86
79
return null ;
87
80
}
88
81
89
-
90
82
private final String query ;
91
83
private final Class <?> resultType ;
92
84
private final LockOptions lockOptions ;
93
85
private final TupleTransformer <?> tupleTransformer ;
94
- private final ResultListTransformer resultListTransformer ;
86
+ private final ResultListTransformer <?> resultListTransformer ;
87
+ private final Collection <String > enabledFetchProfiles ;
95
88
96
89
private SqmInterpretationsKey (
97
90
String query ,
98
91
Class <?> resultType ,
99
92
LockOptions lockOptions ,
100
93
TupleTransformer <?> tupleTransformer ,
101
- ResultListTransformer resultListTransformer ) {
94
+ ResultListTransformer <?> resultListTransformer ,
95
+ Collection <String > enabledFetchProfiles ) {
102
96
this .query = query ;
103
97
this .resultType = resultType ;
104
98
this .lockOptions = lockOptions ;
105
99
this .tupleTransformer = tupleTransformer ;
106
100
this .resultListTransformer = resultListTransformer ;
101
+ this .enabledFetchProfiles = enabledFetchProfiles ;
107
102
}
108
103
109
104
@ Override
@@ -114,7 +109,8 @@ public QueryInterpretationCache.Key prepareForStore() {
114
109
// Since lock options are mutable, we need a copy for the cache key
115
110
lockOptions .makeCopy (),
116
111
tupleTransformer ,
117
- resultListTransformer
112
+ resultListTransformer ,
113
+ enabledFetchProfiles
118
114
);
119
115
}
120
116
@@ -137,16 +133,12 @@ public boolean equals(Object o) {
137
133
&& areEqual ( resultType , that .resultType )
138
134
&& areEqual ( lockOptions , that .lockOptions )
139
135
&& areEqual ( tupleTransformer , that .tupleTransformer )
140
- && areEqual ( resultListTransformer , that .resultListTransformer );
136
+ && areEqual ( resultListTransformer , that .resultListTransformer )
137
+ && areEqual ( enabledFetchProfiles , that .enabledFetchProfiles );
141
138
}
142
139
143
140
private <T > boolean areEqual (T o1 , T o2 ) {
144
- if ( o1 == null ) {
145
- return o2 == null ;
146
- }
147
- else {
148
- return o1 .equals ( o2 );
149
- }
141
+ return o1 == null ? o2 == null : o1 .equals (o2 );
150
142
}
151
143
152
144
@ Override
0 commit comments