@@ -40,7 +40,7 @@ public interface Initializer<Data extends InitializerData> {
40
40
* by traversing up {@link #getParent()}.
41
41
*/
42
42
default @ Nullable EntityInitializer <?> findOwningEntityInitializer () {
43
- return Initializer . findOwningEntityInitializer ( getParent () );
43
+ return findOwningEntityInitializer ( getParent () );
44
44
}
45
45
/**
46
46
* Find the entity initializer that owns this initializer
@@ -50,21 +50,22 @@ public interface Initializer<Data extends InitializerData> {
50
50
if ( parent == null || parent .isCollectionInitializer () ) {
51
51
return null ;
52
52
}
53
- final EntityInitializer <?> entityInitializer = parent . asEntityInitializer ();
54
- if ( entityInitializer != null ) {
55
- return entityInitializer ;
53
+ else {
54
+ final EntityInitializer <?> initializer = parent . asEntityInitializer ();
55
+ return initializer != null ? initializer : findOwningEntityInitializer ( parent . getParent () ) ;
56
56
}
57
- return findOwningEntityInitializer ( parent .getParent () );
58
57
}
59
58
60
59
NavigablePath getNavigablePath ();
61
60
62
61
ModelPart getInitializedPart ();
63
62
64
63
default Object getResolvedInstance (Data data ) {
65
- assert data .getState () != State .UNINITIALIZED
66
- && data .getState () != State .KEY_RESOLVED
67
- && ( data .getState () != State .MISSING || data .getInstance () == null );
64
+ assert switch ( data .getState () ) {
65
+ case UNINITIALIZED , KEY_RESOLVED -> false ;
66
+ case INITIALIZED , RESOLVED -> true ;
67
+ case MISSING -> data .getInstance () == null ;
68
+ };
68
69
return data .getInstance ();
69
70
}
70
71
default Object getResolvedInstance (RowProcessingState rowProcessingState ) {
@@ -79,8 +80,9 @@ default Object getResolvedInstance(RowProcessingState rowProcessingState) {
79
80
/**
80
81
* Step 0 - Callback for initializers before the first row is read.
81
82
* It is the responsibility of this initializer to recurse to the sub-initializers
82
- * and register {@link InitializerData} for the initializer id via {@link RowProcessingState#setInitializerData(int, InitializerData)}.
83
- *
83
+ * and register {@link InitializerData} for the initializer id via
84
+ * {@link RowProcessingState#setInitializerData(int, InitializerData)}.
85
+ * <p>
84
86
* This is useful for e.g. preparing initializers in case of a cache hit.
85
87
*/
86
88
void startLoading (RowProcessingState rowProcessingState );
@@ -89,7 +91,7 @@ default Object getResolvedInstance(RowProcessingState rowProcessingState) {
89
91
/**
90
92
* Step 1.1 - Resolve the key value for this initializer for the current
91
93
* row and then recurse to the sub-initializers.
92
- *
94
+ * <p>
93
95
* After this point, the initializer knows whether further processing is necessary
94
96
* for the current row i.e. if the object is missing.
95
97
*/
@@ -100,8 +102,8 @@ default void resolveKey(RowProcessingState rowProcessingState) {
100
102
}
101
103
102
104
/**
103
- * Step 1.2 - Special variant of {@link #resolveKey(InitializerData)} that allows the reuse of key value
104
- * and instance value from the previous row.
105
+ * Step 1.2 - Special variant of {@link #resolveKey(InitializerData)} that allows
106
+ * the reuse of key value and instance value from the previous row.
105
107
*
106
108
* @implSpec Defaults to simply delegating to {@link #resolveKey(InitializerData)}.
107
109
*/
@@ -116,10 +118,11 @@ default void resolveFromPreviousRow(RowProcessingState rowProcessingState) {
116
118
/**
117
119
* Step 2.1 - Using the key resolved in {@link #resolveKey}, resolve the
118
120
* instance (of the thing initialized) to use for the current row.
119
- *
121
+ * <p>
120
122
* After this point, the initializer knows the entity/collection/component
121
- * instance for the current row based on the resolved key.
122
- * If the resolving was successful, {@link #getResolvedInstance(RowProcessingState)} will return that instance.
123
+ * instance for the current row based on the resolved key. If the resolving
124
+ * was successful, {@link #getResolvedInstance(RowProcessingState)} will
125
+ * return that instance.
123
126
*/
124
127
void resolveInstance (Data data );
125
128
@@ -136,8 +139,9 @@ default void resolveState(RowProcessingState rowProcessingState) {
136
139
/**
137
140
* Step 2.2 - Use the given instance as resolved instance for this initializer.
138
141
* Initializers are supposed to recursively call this method for sub-initializers.
139
- *
140
- * This alternative initialization protocol is used when a parent instance was already part of the persistence context.
142
+ * <p>
143
+ * This alternative initialization protocol is used when a parent instance was
144
+ * already part of the persistence context.
141
145
*/
142
146
default void resolveInstance (@ Nullable Object instance , Data data ) {
143
147
resolveKey ( data );
@@ -150,7 +154,7 @@ default void resolveInstance(@Nullable Object instance, RowProcessingState rowPr
150
154
/**
151
155
* Step 3 - Initialize the state of the instance resolved in
152
156
* {@link #resolveInstance} from the current row values.
153
- *
157
+ * <p>
154
158
* All resolved state for the current row is injected into the resolved
155
159
* instance
156
160
*/
@@ -161,13 +165,14 @@ default void initializeInstance(RowProcessingState rowProcessingState) {
161
165
}
162
166
163
167
/**
164
- * Step 3.1 - Initialize the state of the instance as extracted from the given parentInstance.
165
- * Extraction can be done with the {@link #getInitializedPart()}.
168
+ * Step 3.1 - Initialize the state of the instance as extracted from the given
169
+ * {@code parentInstance}. Extraction can be done with the {@link #getInitializedPart()}.
166
170
* Initializers are supposed to recursively call this method for sub-initializers.
167
- *
171
+ * <p>
168
172
* This alternative initialization protocol is used for shallow query cache hits,
169
- * in which case there is no data available in the {@link org.hibernate.sql.results.jdbc.internal.JdbcValuesCacheHit}
170
- * to initialize potentially lazy associations.
173
+ * in which case there is no data available in the
174
+ * {@link org.hibernate.sql.results.jdbc.internal.JdbcValuesCacheHit} to initialize
175
+ * potentially lazy associations.
171
176
*/
172
177
default void initializeInstanceFromParent (Object parentInstance , Data data ) {
173
178
}
@@ -183,9 +188,9 @@ default void initializeInstanceFromParent(Object parentInstance, RowProcessingSt
183
188
*/
184
189
void finishUpRow (Data data );
185
190
186
- default void finishUpRow (RowProcessingState rowProcessingState ) {
187
- finishUpRow ( getData ( rowProcessingState ) );
188
- }
191
+ // default void finishUpRow(RowProcessingState rowProcessingState) {
192
+ // finishUpRow( getData( rowProcessingState ) );
193
+ // }
189
194
190
195
/**
191
196
* Lifecycle method called at the very end of the result values processing
@@ -194,15 +199,16 @@ default void endLoading(Data data) {
194
199
// by default - nothing to do
195
200
}
196
201
197
- default void endLoading (RowProcessingState rowProcessingState ) {
198
- final Data data = getData ( rowProcessingState );
199
- if ( data != null ) {
200
- endLoading ( data );
201
- }
202
- }
202
+ // default void endLoading(RowProcessingState rowProcessingState) {
203
+ // final Data data = getData( rowProcessingState );
204
+ // if ( data != null ) {
205
+ // endLoading( data );
206
+ // }
207
+ // }
203
208
204
209
/**
205
- * Indicates whether this initializer is part of a key i.e. entity identifier, foreign key or collection key.
210
+ * Indicates whether this initializer is part of a key i.e. entity identifier,
211
+ * foreign key or collection key.
206
212
*/
207
213
boolean isPartOfKey ();
208
214
0 commit comments