@@ -135,7 +135,6 @@ public BasicPersistentEntity(TypeInformation<T> information, @Nullable Comparato
135135
136136 @ Nullable
137137 @ Override
138- @ SuppressWarnings ("unchecked" )
139138 public PreferredConstructor <T , P > getPersistenceConstructor () {
140139 return creator instanceof PreferredConstructor ? (PreferredConstructor <T , P >) creator : null ;
141140 }
@@ -151,36 +150,89 @@ public boolean isCreatorArgument(PersistentProperty<?> property) {
151150 return creator != null && creator .isCreatorParameter (property );
152151 }
153152
153+ /**
154+ * Calculates the {@link Alias} to be used for the given type.
155+ *
156+ * @param type must not be {@literal null}.
157+ * @return the alias for {@code type}
158+ */
159+ private static Alias getAliasFromAnnotation (Class <?> type ) {
160+
161+ TypeAlias typeAlias = AnnotatedElementUtils .findMergedAnnotation (type , TypeAlias .class );
162+
163+ if (typeAlias != null && StringUtils .hasText (typeAlias .value ())) {
164+ return Alias .of (typeAlias .value ());
165+ }
166+
167+ return Alias .empty ();
168+ }
169+
170+ @ Override
154171 public boolean isIdProperty (PersistentProperty <?> property ) {
155172 return idProperty != null && idProperty .equals (property );
156173 }
157174
175+ @ Override
158176 public boolean isVersionProperty (PersistentProperty <?> property ) {
159177 return versionProperty != null && versionProperty .equals (property );
160178 }
161179
180+ @ Override
162181 public String getName () {
163182 return getType ().getName ();
164183 }
165184
185+ @ Override
166186 @ Nullable
167187 public P getIdProperty () {
168188 return idProperty ;
169189 }
170190
191+ @ Override
171192 @ Nullable
172193 public P getVersionProperty () {
173194 return versionProperty ;
174195 }
175196
197+ @ Override
176198 public boolean hasIdProperty () {
177199 return idProperty != null ;
178200 }
179201
202+ @ Override
180203 public boolean hasVersionProperty () {
181204 return versionProperty != null ;
182205 }
183206
207+ @ Override
208+ public void setEvaluationContextProvider (EvaluationContextProvider provider ) {
209+ this .evaluationContextProvider = provider ;
210+ }
211+
212+ /**
213+ * Returns the given property if it is a better candidate for the id property than the current id property.
214+ *
215+ * @param property the new id property candidate, will never be {@literal null}.
216+ * @return the given id property or {@literal null} if the given property is not an id property.
217+ */
218+ @ Nullable
219+ protected P returnPropertyIfBetterIdPropertyCandidateOrNull (P property ) {
220+
221+ if (!property .isIdProperty ()) {
222+ return null ;
223+ }
224+
225+ P idProperty = this .idProperty ;
226+
227+ if (idProperty != null ) {
228+ throw new MappingException (String .format ("Attempt to add id property %s but already have property %s registered "
229+ + "as id; Check your mapping configuration " , property .getField (), idProperty .getField ()));
230+ }
231+
232+ return property ;
233+ }
234+
235+ @ Override
184236 public void addPersistentProperty (P property ) {
185237
186238 Assert .notNull (property , "Property must not be null" );
@@ -230,41 +282,6 @@ public void addPersistentProperty(P property) {
230282 }
231283 }
232284
233- @ Override
234- public void setEvaluationContextProvider (EvaluationContextProvider provider ) {
235- this .evaluationContextProvider = provider ;
236- }
237-
238- /**
239- * Returns the given property if it is a better candidate for the id property than the current id property.
240- *
241- * @param property the new id property candidate, will never be {@literal null}.
242- * @return the given id property or {@literal null} if the given property is not an id property.
243- */
244- @ Nullable
245- protected P returnPropertyIfBetterIdPropertyCandidateOrNull (P property ) {
246-
247- if (!property .isIdProperty ()) {
248- return null ;
249- }
250-
251- P idProperty = this .idProperty ;
252-
253- if (idProperty != null ) {
254- throw new MappingException (String .format ("Attempt to add id property %s but already have property %s registered "
255- + "as id; Check your mapping configuration " , property .getField (), idProperty .getField ()));
256- }
257-
258- return property ;
259- }
260-
261- public void addAssociation (Association <P > association ) {
262-
263- Assert .notNull (association , "Association must not be null" );
264-
265- associations .add (association );
266- }
267-
268285 @ Override
269286 @ Nullable
270287 public P getPersistentProperty (String name ) {
@@ -306,27 +323,29 @@ private List<P> doFindPersistentProperty(Class<? extends Annotation> annotationT
306323 .filter (it -> it .isAnnotationPresent (annotationType )).collect (Collectors .toList ());
307324 }
308325
326+ @ Override
327+ public void addAssociation (Association <P > association ) {
328+
329+ Assert .notNull (association , "Association must not be null" );
330+
331+ associations .add (association );
332+ }
333+
334+ @ Override
309335 public Class <T > getType () {
310336 return information .getType ();
311337 }
312338
339+ @ Override
313340 public Alias getTypeAlias () {
314341 return typeAlias .get ();
315342 }
316343
344+ @ Override
317345 public TypeInformation <T > getTypeInformation () {
318346 return information ;
319347 }
320348
321- public void doWithProperties (PropertyHandler <P > handler ) {
322-
323- Assert .notNull (handler , "PropertyHandler must not be null" );
324-
325- for (P property : persistentPropertiesCache ) {
326- handler .doWithPersistentProperty (property );
327- }
328- }
329-
330349 @ Override
331350 public void doWithProperties (SimplePropertyHandler handler ) {
332351
@@ -337,20 +356,22 @@ public void doWithProperties(SimplePropertyHandler handler) {
337356 }
338357 }
339358
340- public void doWithAssociations (AssociationHandler <P > handler ) {
359+ @ Override
360+ public void doWithProperties (PropertyHandler <P > handler ) {
341361
342- Assert .notNull (handler , "Handler must not be null" );
362+ Assert .notNull (handler , "PropertyHandler must not be null" );
343363
344- for (Association < P > association : associations ) {
345- handler .doWithAssociation ( association );
364+ for (P property : persistentPropertiesCache ) {
365+ handler .doWithPersistentProperty ( property );
346366 }
347367 }
348368
349- public void doWithAssociations (SimpleAssociationHandler handler ) {
369+ @ Override
370+ public void doWithAssociations (AssociationHandler <P > handler ) {
350371
351372 Assert .notNull (handler , "Handler must not be null" );
352373
353- for (Association <? extends PersistentProperty <?> > association : associations ) {
374+ for (Association <P > association : associations ) {
354375 handler .doWithAssociation (association );
355376 }
356377 }
@@ -373,11 +394,13 @@ private <A extends Annotation> Optional<A> doFindAnnotation(Class<A> annotationT
373394 it -> Optional .ofNullable (AnnotatedElementUtils .findMergedAnnotation (getType (), it )));
374395 }
375396
376- public void verify () {
397+ @ Override
398+ public void doWithAssociations (SimpleAssociationHandler handler ) {
377399
378- if (comparator != null ) {
379- properties .sort (comparator );
380- persistentPropertiesCache .sort (comparator );
400+ Assert .notNull (handler , "Handler must not be null" );
401+
402+ for (Association <? extends PersistentProperty <?>> association : associations ) {
403+ handler .doWithAssociation (association );
381404 }
382405 }
383406
@@ -471,16 +494,13 @@ protected EvaluationContext getEvaluationContext(Object rootObject, ExpressionDe
471494 return evaluationContextProvider .getEvaluationContext (rootObject , dependencies );
472495 }
473496
474- /**
475- * Returns the default {@link IsNewStrategy} to be used. Will be a {@link PersistentEntityIsNewStrategy} by default.
476- * Note, that this strategy only gets used if the entity doesn't implement {@link Persistable} as this indicates the
477- * user wants to be in control over whether an entity is new or not.
478- *
479- * @return
480- * @since 2.1
481- */
482- protected IsNewStrategy getFallbackIsNewStrategy () {
483- return PersistentEntityIsNewStrategy .of (this );
497+ @ Override
498+ public void verify () {
499+
500+ if (comparator != null ) {
501+ properties .sort (comparator );
502+ persistentPropertiesCache .sort (comparator );
503+ }
484504 }
485505
486506 /**
@@ -496,20 +516,15 @@ private void verifyBeanType(Object bean) {
496516 }
497517
498518 /**
499- * Calculates the {@link Alias} to be used for the given type.
519+ * Returns the default {@link IsNewStrategy} to be used. Will be a {@link PersistentEntityIsNewStrategy} by default.
520+ * Note, that this strategy only gets used if the entity doesn't implement {@link Persistable} as this indicates the
521+ * user wants to be in control over whether an entity is new or not.
500522 *
501- * @param type must not be {@literal null }.
502- * @return
523+ * @return the fallback {@link IsNewStrategy }.
524+ * @since 2.1
503525 */
504- private static Alias getAliasFromAnnotation (Class <?> type ) {
505-
506- TypeAlias typeAlias = AnnotatedElementUtils .findMergedAnnotation (type , TypeAlias .class );
507-
508- if (typeAlias != null && StringUtils .hasText (typeAlias .value ())) {
509- return Alias .of (typeAlias .value ());
510- }
511-
512- return Alias .empty ();
526+ protected IsNewStrategy getFallbackIsNewStrategy () {
527+ return PersistentEntityIsNewStrategy .of (this );
513528 }
514529
515530 /**
@@ -546,6 +561,7 @@ private static final class AssociationComparator<P extends PersistentProperty<P>
546561 this .delegate = delegate ;
547562 }
548563
564+ @ Override
549565 public int compare (@ Nullable Association <P > left , @ Nullable Association <P > right ) {
550566
551567 if (left == null ) {
0 commit comments