@@ -135,7 +135,6 @@ public BasicPersistentEntity(TypeInformation<T> information, @Nullable Comparato
135
135
136
136
@ Nullable
137
137
@ Override
138
- @ SuppressWarnings ("unchecked" )
139
138
public PreferredConstructor <T , P > getPersistenceConstructor () {
140
139
return creator instanceof PreferredConstructor ? (PreferredConstructor <T , P >) creator : null ;
141
140
}
@@ -151,36 +150,89 @@ public boolean isCreatorArgument(PersistentProperty<?> property) {
151
150
return creator != null && creator .isCreatorParameter (property );
152
151
}
153
152
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
154
171
public boolean isIdProperty (PersistentProperty <?> property ) {
155
172
return idProperty != null && idProperty .equals (property );
156
173
}
157
174
175
+ @ Override
158
176
public boolean isVersionProperty (PersistentProperty <?> property ) {
159
177
return versionProperty != null && versionProperty .equals (property );
160
178
}
161
179
180
+ @ Override
162
181
public String getName () {
163
182
return getType ().getName ();
164
183
}
165
184
185
+ @ Override
166
186
@ Nullable
167
187
public P getIdProperty () {
168
188
return idProperty ;
169
189
}
170
190
191
+ @ Override
171
192
@ Nullable
172
193
public P getVersionProperty () {
173
194
return versionProperty ;
174
195
}
175
196
197
+ @ Override
176
198
public boolean hasIdProperty () {
177
199
return idProperty != null ;
178
200
}
179
201
202
+ @ Override
180
203
public boolean hasVersionProperty () {
181
204
return versionProperty != null ;
182
205
}
183
206
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
184
236
public void addPersistentProperty (P property ) {
185
237
186
238
Assert .notNull (property , "Property must not be null" );
@@ -230,41 +282,6 @@ public void addPersistentProperty(P property) {
230
282
}
231
283
}
232
284
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
-
268
285
@ Override
269
286
@ Nullable
270
287
public P getPersistentProperty (String name ) {
@@ -306,27 +323,29 @@ private List<P> doFindPersistentProperty(Class<? extends Annotation> annotationT
306
323
.filter (it -> it .isAnnotationPresent (annotationType )).collect (Collectors .toList ());
307
324
}
308
325
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
309
335
public Class <T > getType () {
310
336
return information .getType ();
311
337
}
312
338
339
+ @ Override
313
340
public Alias getTypeAlias () {
314
341
return typeAlias .get ();
315
342
}
316
343
344
+ @ Override
317
345
public TypeInformation <T > getTypeInformation () {
318
346
return information ;
319
347
}
320
348
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
-
330
349
@ Override
331
350
public void doWithProperties (SimplePropertyHandler handler ) {
332
351
@@ -337,20 +356,22 @@ public void doWithProperties(SimplePropertyHandler handler) {
337
356
}
338
357
}
339
358
340
- public void doWithAssociations (AssociationHandler <P > handler ) {
359
+ @ Override
360
+ public void doWithProperties (PropertyHandler <P > handler ) {
341
361
342
- Assert .notNull (handler , "Handler must not be null" );
362
+ Assert .notNull (handler , "PropertyHandler must not be null" );
343
363
344
- for (Association < P > association : associations ) {
345
- handler .doWithAssociation ( association );
364
+ for (P property : persistentPropertiesCache ) {
365
+ handler .doWithPersistentProperty ( property );
346
366
}
347
367
}
348
368
349
- public void doWithAssociations (SimpleAssociationHandler handler ) {
369
+ @ Override
370
+ public void doWithAssociations (AssociationHandler <P > handler ) {
350
371
351
372
Assert .notNull (handler , "Handler must not be null" );
352
373
353
- for (Association <? extends PersistentProperty <?> > association : associations ) {
374
+ for (Association <P > association : associations ) {
354
375
handler .doWithAssociation (association );
355
376
}
356
377
}
@@ -373,11 +394,13 @@ private <A extends Annotation> Optional<A> doFindAnnotation(Class<A> annotationT
373
394
it -> Optional .ofNullable (AnnotatedElementUtils .findMergedAnnotation (getType (), it )));
374
395
}
375
396
376
- public void verify () {
397
+ @ Override
398
+ public void doWithAssociations (SimpleAssociationHandler handler ) {
377
399
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 );
381
404
}
382
405
}
383
406
@@ -471,16 +494,13 @@ protected EvaluationContext getEvaluationContext(Object rootObject, ExpressionDe
471
494
return evaluationContextProvider .getEvaluationContext (rootObject , dependencies );
472
495
}
473
496
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
+ }
484
504
}
485
505
486
506
/**
@@ -496,20 +516,15 @@ private void verifyBeanType(Object bean) {
496
516
}
497
517
498
518
/**
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.
500
522
*
501
- * @param type must not be {@literal null }.
502
- * @return
523
+ * @return the fallback {@link IsNewStrategy }.
524
+ * @since 2.1
503
525
*/
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 );
513
528
}
514
529
515
530
/**
@@ -546,6 +561,7 @@ private static final class AssociationComparator<P extends PersistentProperty<P>
546
561
this .delegate = delegate ;
547
562
}
548
563
564
+ @ Override
549
565
public int compare (@ Nullable Association <P > left , @ Nullable Association <P > right ) {
550
566
551
567
if (left == null ) {
0 commit comments