33
33
import jakarta .persistence .metamodel .PluralAttribute ;
34
34
import jakarta .persistence .metamodel .SingularAttribute ;
35
35
36
- import static java .util .Collections .emptyList ;
37
36
import static org .hibernate .internal .util .NullnessUtil .castNonNull ;
38
37
39
38
/**
@@ -49,7 +48,7 @@ public abstract class AbstractSqmPath<T> extends AbstractSqmExpression<T> implem
49
48
* E.g., given {@code p.mate.mate} the {@code SqmRoot} identified by {@code p} would
50
49
* have a reusable path for the {@code p.mate} path.
51
50
*/
52
- private Map <String , SqmPath <?>> reusablePaths ;
51
+ private final Map <String , SqmPath <?>> reusablePaths = new ConcurrentHashMap <>( 0 ) ;
53
52
54
53
protected AbstractSqmPath (
55
54
NavigablePath navigablePath ,
@@ -103,32 +102,27 @@ public SqmPath<?> getLhs() {
103
102
104
103
@ Override
105
104
public List <SqmPath <?>> getReusablePaths () {
106
- return reusablePaths == null ? emptyList () : new ArrayList <>( reusablePaths .values () );
105
+ return new ArrayList <>( reusablePaths .values () );
107
106
}
108
107
109
108
@ Override
110
109
public void visitReusablePaths (Consumer <SqmPath <?>> consumer ) {
111
- if ( reusablePaths != null ) {
112
- reusablePaths .values ().forEach ( consumer );
113
- }
110
+ reusablePaths .values ().forEach ( consumer );
114
111
}
115
112
116
113
@ Override
117
114
public void registerReusablePath (SqmPath <?> path ) {
118
115
assert path .getLhs () == this ;
119
- if ( reusablePaths == null ) {
120
- reusablePaths = new ConcurrentHashMap <>();
121
- }
122
116
final String relativeName = path .getNavigablePath ().getLocalName ();
123
- final SqmPath <?> previous = reusablePaths .put ( relativeName , path );
117
+ final SqmPath <?> previous = reusablePaths .putIfAbsent ( relativeName , path );
124
118
if ( previous != null && previous != path ) {
125
119
throw new IllegalStateException ( "Implicit-join path registration unexpectedly overrode previous registration - " + relativeName );
126
120
}
127
121
}
128
122
129
123
@ Override
130
124
public SqmPath <?> getReusablePath (String name ) {
131
- return reusablePaths == null ? null : reusablePaths .get ( name );
125
+ return reusablePaths .get ( name );
132
126
}
133
127
134
128
@ Override
@@ -206,18 +200,10 @@ protected <X> SqmPath<X> resolvePath(PersistentAttribute<?, X> attribute) {
206
200
protected <X > SqmPath <X > resolvePath (String attributeName , SqmPathSource <X > pathSource ) {
207
201
final SqmPathSource <?> intermediatePathSource =
208
202
getResolvedModel ().getIntermediatePathSource ( pathSource );
209
- if ( reusablePaths == null ) {
210
- reusablePaths = new ConcurrentHashMap <>();
211
- final SqmPath <X > path = pathSource .createSqmPath ( this , intermediatePathSource );
212
- reusablePaths .put ( attributeName , path );
213
- return path ;
214
- }
215
- else {
216
- //noinspection unchecked
217
- return (SqmPath <X >)
218
- reusablePaths .computeIfAbsent ( attributeName ,
219
- name -> pathSource .createSqmPath ( this , intermediatePathSource ) );
220
- }
203
+ //noinspection unchecked
204
+ return (SqmPath <X >)
205
+ reusablePaths .computeIfAbsent ( attributeName ,
206
+ name -> pathSource .createSqmPath ( this , intermediatePathSource ) );
221
207
}
222
208
223
209
protected <S extends T > SqmTreatedPath <T , S > getTreatedPath (ManagedDomainType <S > treatTarget ) {
0 commit comments