@@ -88,8 +88,8 @@ public static LoadState getLoadState(Object reference) {
88
88
else if ( isPersistentAttributeInterceptable ( reference ) ) {
89
89
return isInitialized ( asPersistentAttributeInterceptable ( reference ) ) ? LOADED : NOT_LOADED ;
90
90
}
91
- else if ( reference instanceof LazyInitializable ) {
92
- return ( ( LazyInitializable ) reference ) .wasInitialized () ? LOADED : NOT_LOADED ;
91
+ else if ( reference instanceof LazyInitializable lazyInitializable ) {
92
+ return lazyInitializable .wasInitialized () ? LOADED : NOT_LOADED ;
93
93
}
94
94
else {
95
95
return UNKNOWN ;
@@ -116,7 +116,7 @@ private static BytecodeLazyAttributeInterceptor extractInterceptor(PersistentAtt
116
116
* @return The LoadState
117
117
*/
118
118
public static LoadState isLoadedWithoutReference (Object entity , String attributeName , MetadataCache cache ) {
119
- boolean sureFromUs = false ;
119
+ final boolean sureFromUs ;
120
120
final LazyInitializer lazyInitializer = extractLazyInitializer ( entity );
121
121
if ( lazyInitializer != null ) {
122
122
if ( lazyInitializer .isUninitialized () ) {
@@ -129,54 +129,57 @@ public static LoadState isLoadedWithoutReference(Object entity, String attribute
129
129
}
130
130
sureFromUs = true ;
131
131
}
132
+ else {
133
+ sureFromUs = false ;
134
+ }
132
135
133
136
// we are instrumenting, but we can't assume we are the only ones
134
137
if ( isPersistentAttributeInterceptable ( entity ) ) {
135
- final BytecodeLazyAttributeInterceptor interceptor = extractInterceptor ( asPersistentAttributeInterceptable ( entity ) );
138
+ final BytecodeLazyAttributeInterceptor interceptor =
139
+ extractInterceptor ( asPersistentAttributeInterceptable ( entity ) );
136
140
final boolean isInitialized = interceptor == null || interceptor .isAttributeLoaded ( attributeName );
137
- LoadState state ;
138
- if (isInitialized && interceptor != null ) {
139
- // attributeName is loaded according to bytecode enhancement, but is it loaded as far as association?
140
- // it's ours, we can read
141
- try {
142
- state = getLoadState ( getAttributeValue ( entity , attributeName , cache ) );
143
- // it's ours so we know it's loaded
144
- if ( state == UNKNOWN ) {
145
- state = LOADED ;
146
- }
147
- }
148
- catch (AttributeExtractionException ignore ) {
149
- state = UNKNOWN ;
150
- }
151
- }
152
- else if ( interceptor != null ) {
153
- state = NOT_LOADED ;
154
- }
155
- else if ( sureFromUs ) {
156
- // property is loaded according to bytecode enhancement, but is it loaded as far as association?
157
- // it's ours, we can read
158
- try {
159
- state = getLoadState ( getAttributeValue ( entity , attributeName , cache ) );
160
- // it's ours so we know it's loaded
161
- if ( state == UNKNOWN ) {
162
- state = LOADED ;
163
- }
164
- }
165
- catch (AttributeExtractionException ignore ) {
166
- state = UNKNOWN ;
167
- }
168
- }
169
- else {
170
- state = UNKNOWN ;
171
- }
141
+ return getLoadState ( entity , attributeName , cache , isInitialized , interceptor , sureFromUs );
142
+ }
143
+ else {
144
+ return UNKNOWN ;
145
+ }
146
+ }
172
147
173
- return state ;
148
+ private static LoadState getLoadState (
149
+ Object entity , String attributeName ,
150
+ MetadataCache cache ,
151
+ boolean isInitialized ,
152
+ BytecodeLazyAttributeInterceptor interceptor ,
153
+ boolean sureFromUs ) {
154
+ if ( isInitialized && interceptor != null ) {
155
+ // attributeName is loaded according to bytecode enhancement, but is it loaded as far as association?
156
+ // it's ours, we can read
157
+ return getLoadState ( entity , attributeName , cache );
158
+ }
159
+ else if ( interceptor != null ) {
160
+ return NOT_LOADED ;
161
+ }
162
+ else if ( sureFromUs ) {
163
+ // property is loaded according to bytecode enhancement, but is it loaded as far as association?
164
+ // it's ours, we can read
165
+ return getLoadState ( entity , attributeName , cache );
174
166
}
175
167
else {
176
168
return UNKNOWN ;
177
169
}
178
170
}
179
171
172
+ private static LoadState getLoadState (Object entity , String attributeName , MetadataCache cache ) {
173
+ try {
174
+ final LoadState state = getLoadState ( getAttributeValue ( entity , attributeName , cache ) );
175
+ // it's ours so we know it's loaded
176
+ return state == UNKNOWN ? LOADED : state ;
177
+ }
178
+ catch (AttributeExtractionException ignore ) {
179
+ return UNKNOWN ;
180
+ }
181
+ }
182
+
180
183
/**
181
184
* Is the given attribute (by name) loaded? This form must take care to not access the attribute (trigger
182
185
* initialization).
@@ -328,7 +331,7 @@ public ClassMetadataCache(Class<?> clazz) {
328
331
}
329
332
330
333
private static List <Class <?>> findClassHierarchy (Class <?> clazz ) {
331
- List <Class <?>> classes = new ArrayList <>();
334
+ final List <Class <?>> classes = new ArrayList <>();
332
335
Class <?> current = clazz ;
333
336
do {
334
337
classes .add ( current );
@@ -374,9 +377,9 @@ private AttributeAccess buildAttributeAccess(final String attributeName) {
374
377
*/
375
378
private static Method getMethod (Class <?> clazz , String attributeName ) {
376
379
try {
377
- char [] string = attributeName .toCharArray ();
380
+ final char [] string = attributeName .toCharArray ();
378
381
string [0 ] = Character .toUpperCase ( string [0 ] );
379
- String casedAttributeName = new String ( string );
382
+ final String casedAttributeName = new String ( string );
380
383
try {
381
384
return clazz .getDeclaredMethod ( "get" + casedAttributeName );
382
385
}
0 commit comments