5
5
package org .hibernate .query .sqm .internal ;
6
6
7
7
import java .util .Collection ;
8
- import java .util .Iterator ;
9
8
import java .util .Objects ;
10
9
import java .util .Set ;
11
- import java .util .function .Supplier ;
10
+ import java .util .function .BooleanSupplier ;
12
11
13
12
import org .hibernate .LockOptions ;
14
13
import org .hibernate .engine .spi .LoadQueryInfluencers ;
18
17
import org .hibernate .query .spi .QueryOptions ;
19
18
import org .hibernate .query .sqm .tree .SqmStatement ;
20
19
21
- import static java .lang .Boolean .TRUE ;
22
20
23
21
/**
24
22
* @author Steve Ebersole
25
23
*/
26
- public final class SqmInterpretationsKey implements QueryInterpretationCache .Key {
24
+ final class SqmInterpretationsKey implements QueryInterpretationCache .Key {
27
25
public interface CacheabilityInfluencers {
28
26
boolean isQueryPlanCacheable ();
29
27
String getQueryString ();
30
28
Object getQueryStringCacheKey ();
31
29
SqmStatement <?> getSqmStatement ();
32
30
QueryOptions getQueryOptions ();
33
31
LoadQueryInfluencers getLoadQueryInfluencers ();
34
- Supplier < Boolean > hasMultiValuedParameterBindingsChecker ();
32
+ BooleanSupplier hasMultiValuedParameterBindingsChecker ();
35
33
}
36
34
37
35
public interface InterpretationsKeySource extends CacheabilityInfluencers {
@@ -61,17 +59,15 @@ private static Collection<String> memoryEfficientDefensiveSetCopy(final Set<Stri
61
59
return null ;
62
60
}
63
61
else {
64
- switch ( set .size () ) {
65
- case 0 :
66
- return null ;
67
- case 1 :
68
- return Set .of ( set .iterator ().next () );
69
- case 2 :
70
- final Iterator <String > iterator = set .iterator ();
71
- return Set .of ( iterator .next (), iterator .next () );
72
- default :
73
- return Set .copyOf ( set );
74
- }
62
+ return switch ( set .size () ) {
63
+ case 0 -> null ;
64
+ case 1 -> Set .of ( set .iterator ().next () );
65
+ case 2 -> {
66
+ final var iterator = set .iterator ();
67
+ yield Set .of ( iterator .next (), iterator .next () );
68
+ }
69
+ default -> Set .copyOf ( set );
70
+ };
75
71
}
76
72
}
77
73
@@ -83,7 +79,7 @@ private static boolean isCacheable(InterpretationsKeySource keySource) {
83
79
// parameters are part of the query string; with Criteria, they're not.
84
80
return keySource .isQueryPlanCacheable ()
85
81
// At the moment we cannot cache query plan if there is filter enabled.
86
- && ! keySource .getLoadQueryInfluencers ().hasEnabledFilters ()
82
+ && !keySource .getLoadQueryInfluencers ().hasEnabledFilters ()
87
83
// At the moment we cannot cache query plan if it has an entity graph
88
84
&& keySource .getQueryOptions ().getAppliedGraph ().getSemantic () == null
89
85
// todo (6.0) : this one may be ok because of how I implemented multi-valued param handling
@@ -92,7 +88,7 @@ private static boolean isCacheable(InterpretationsKeySource keySource) {
92
88
// in ConcreteSqmSelectQueryPlan is a concurrency issue when cached
93
89
// - This could be solved by using a method-local clone of domainParameterXref
94
90
// when multi-valued params exist
95
- && ! keySource .hasMultiValuedParameterBindingsChecker ().get () == TRUE ;
91
+ && !keySource .hasMultiValuedParameterBindingsChecker ().getAsBoolean () ;
96
92
}
97
93
98
94
public static QueryInterpretationCache .Key generateNonSelectKey (InterpretationsKeySource keyDetails ) {
@@ -109,7 +105,7 @@ public static QueryInterpretationCache.Key generateNonSelectKey(InterpretationsK
109
105
private final TupleTransformer <?> tupleTransformer ;
110
106
private final ResultListTransformer <?> resultListTransformer ;
111
107
private final Collection <String > enabledFetchProfiles ;
112
- private final int hashcode ;
108
+ private final int hashCode ;
113
109
114
110
private SqmInterpretationsKey (
115
111
Object query ,
@@ -120,7 +116,7 @@ private SqmInterpretationsKey(
120
116
ResultListTransformer <?> resultListTransformer ,
121
117
Collection <String > enabledFetchProfiles ) {
122
118
this .query = query ;
123
- this .hashcode = hash ;
119
+ this .hashCode = hash ;
124
120
this .resultType = resultType ;
125
121
this .lockOptions = lockOptions ;
126
122
this .tupleTransformer = tupleTransformer ;
@@ -132,7 +128,7 @@ private SqmInterpretationsKey(
132
128
public QueryInterpretationCache .Key prepareForStore () {
133
129
return new SqmInterpretationsKey (
134
130
query ,
135
- hashcode ,
131
+ hashCode ,
136
132
resultType ,
137
133
// Since lock options might be mutable, we need a copy for the cache key
138
134
lockOptions .makeDefensiveCopy (),
@@ -148,26 +144,24 @@ public String getQueryString() {
148
144
}
149
145
150
146
@ Override
151
- public boolean equals (Object o ) {
152
- if ( this == o ) {
147
+ public boolean equals (Object other ) {
148
+ if ( this == other ) {
153
149
return true ;
154
150
}
155
- if ( o == null || SqmInterpretationsKey . class != o . getClass () ) {
151
+ if ( !( other instanceof SqmInterpretationsKey that ) ) {
156
152
return false ;
157
153
}
158
-
159
- final SqmInterpretationsKey that = (SqmInterpretationsKey ) o ;
160
- return this .hashcode == o .hashCode () //check this first as some other checks are expensive
161
- && query .equals ( that .query )
162
- && Objects .equals ( resultType , that .resultType )
163
- && Objects .equals ( lockOptions , that .lockOptions )
164
- && Objects .equals ( tupleTransformer , that .tupleTransformer )
165
- && Objects .equals ( resultListTransformer , that .resultListTransformer )
166
- && Objects .equals ( enabledFetchProfiles , that .enabledFetchProfiles );
154
+ return this .hashCode == that .hashCode //check this first as some other checks are expensive
155
+ && this .query .equals ( that .query )
156
+ && Objects .equals ( this .resultType , that .resultType )
157
+ && Objects .equals ( this .lockOptions , that .lockOptions )
158
+ && Objects .equals ( this .tupleTransformer , that .tupleTransformer )
159
+ && Objects .equals ( this .resultListTransformer , that .resultListTransformer )
160
+ && Objects .equals ( this .enabledFetchProfiles , that .enabledFetchProfiles );
167
161
}
168
162
169
163
@ Override
170
164
public int hashCode () {
171
- return hashcode ;
165
+ return hashCode ;
172
166
}
173
167
}
0 commit comments