@@ -40,7 +40,7 @@ public interface Initializer<Data extends InitializerData> {
4040 * by traversing up {@link #getParent()}.
4141 */
4242 default @ Nullable EntityInitializer <?> findOwningEntityInitializer () {
43- return Initializer . findOwningEntityInitializer ( getParent () );
43+ return findOwningEntityInitializer ( getParent () );
4444 }
4545 /**
4646 * Find the entity initializer that owns this initializer
@@ -50,21 +50,22 @@ public interface Initializer<Data extends InitializerData> {
5050 if ( parent == null || parent .isCollectionInitializer () ) {
5151 return null ;
5252 }
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 () ) ;
5656 }
57- return findOwningEntityInitializer ( parent .getParent () );
5857 }
5958
6059 NavigablePath getNavigablePath ();
6160
6261 ModelPart getInitializedPart ();
6362
6463 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+ };
6869 return data .getInstance ();
6970 }
7071 default Object getResolvedInstance (RowProcessingState rowProcessingState ) {
@@ -79,8 +80,9 @@ default Object getResolvedInstance(RowProcessingState rowProcessingState) {
7980 /**
8081 * Step 0 - Callback for initializers before the first row is read.
8182 * 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>
8486 * This is useful for e.g. preparing initializers in case of a cache hit.
8587 */
8688 void startLoading (RowProcessingState rowProcessingState );
@@ -89,7 +91,7 @@ default Object getResolvedInstance(RowProcessingState rowProcessingState) {
8991 /**
9092 * Step 1.1 - Resolve the key value for this initializer for the current
9193 * row and then recurse to the sub-initializers.
92- *
94+ * <p>
9395 * After this point, the initializer knows whether further processing is necessary
9496 * for the current row i.e. if the object is missing.
9597 */
@@ -100,8 +102,8 @@ default void resolveKey(RowProcessingState rowProcessingState) {
100102 }
101103
102104 /**
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.
105107 *
106108 * @implSpec Defaults to simply delegating to {@link #resolveKey(InitializerData)}.
107109 */
@@ -116,10 +118,11 @@ default void resolveFromPreviousRow(RowProcessingState rowProcessingState) {
116118 /**
117119 * Step 2.1 - Using the key resolved in {@link #resolveKey}, resolve the
118120 * instance (of the thing initialized) to use for the current row.
119- *
121+ * <p>
120122 * 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.
123126 */
124127 void resolveInstance (Data data );
125128
@@ -136,8 +139,9 @@ default void resolveState(RowProcessingState rowProcessingState) {
136139 /**
137140 * Step 2.2 - Use the given instance as resolved instance for this initializer.
138141 * 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.
141145 */
142146 default void resolveInstance (@ Nullable Object instance , Data data ) {
143147 resolveKey ( data );
@@ -150,7 +154,7 @@ default void resolveInstance(@Nullable Object instance, RowProcessingState rowPr
150154 /**
151155 * Step 3 - Initialize the state of the instance resolved in
152156 * {@link #resolveInstance} from the current row values.
153- *
157+ * <p>
154158 * All resolved state for the current row is injected into the resolved
155159 * instance
156160 */
@@ -161,13 +165,14 @@ default void initializeInstance(RowProcessingState rowProcessingState) {
161165 }
162166
163167 /**
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()}.
166170 * Initializers are supposed to recursively call this method for sub-initializers.
167- *
171+ * <p>
168172 * 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.
171176 */
172177 default void initializeInstanceFromParent (Object parentInstance , Data data ) {
173178 }
@@ -183,9 +188,9 @@ default void initializeInstanceFromParent(Object parentInstance, RowProcessingSt
183188 */
184189 void finishUpRow (Data data );
185190
186- default void finishUpRow (RowProcessingState rowProcessingState ) {
187- finishUpRow ( getData ( rowProcessingState ) );
188- }
191+ // default void finishUpRow(RowProcessingState rowProcessingState) {
192+ // finishUpRow( getData( rowProcessingState ) );
193+ // }
189194
190195 /**
191196 * Lifecycle method called at the very end of the result values processing
@@ -194,15 +199,16 @@ default void endLoading(Data data) {
194199 // by default - nothing to do
195200 }
196201
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+ // }
203208
204209 /**
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.
206212 */
207213 boolean isPartOfKey ();
208214
0 commit comments