@@ -41,27 +41,31 @@ class PersistentEntityIsNewStrategy implements IsNewStrategy {
41
41
* Creates a new {@link PersistentEntityIsNewStrategy} for the given entity.
42
42
*
43
43
* @param entity must not be {@literal null}.
44
+ * @param idOnly {@code true} if should consider only the ID property of the {@link PersistentEntity}, {@code false}
45
+ * if other properties such as {@link PersistentEntity#getVersionProperty() version} shall be
46
+ * considered.
44
47
*/
45
48
private PersistentEntityIsNewStrategy (PersistentEntity <?, ?> entity , boolean idOnly ) {
46
49
47
50
Assert .notNull (entity , "PersistentEntity must not be null" );
48
51
49
- this . valueLookup = entity .hasVersionProperty () && !idOnly //
50
- ? source -> entity .getPropertyAccessor (source ).getProperty (entity .getRequiredVersionProperty ())
51
- : source -> entity .getIdentifierAccessor ( source ). getIdentifier ();
52
-
53
- this .valueType = entity .hasVersionProperty () && ! idOnly //
54
- ? entity .getRequiredVersionProperty ().getType () //
55
- : entity . hasIdProperty () ? entity . getRequiredIdProperty (). getType () : null ;
52
+ if ( entity .hasVersionProperty () && !idOnly ) {
53
+ this . valueLookup = source -> entity .getPropertyAccessor (source ).getProperty (entity .getRequiredVersionProperty ());
54
+ this . valueType = entity .getRequiredVersionProperty (). getType ();
55
+ } else {
56
+ this .valueLookup = source -> entity .getIdentifierAccessor ( source ). getIdentifier ();
57
+ this . valueType = entity . hasIdProperty () ? entity .getRequiredIdProperty ().getType () : null ;
58
+ }
56
59
57
60
Class <?> type = valueType ;
58
61
59
62
if (type != null && type .isPrimitive ()) {
60
63
61
64
if (!ClassUtils .isAssignable (Number .class , type )) {
62
65
63
- throw new IllegalArgumentException (String
64
- .format ("Only numeric primitives are supported as identifier / version field types; Got: %s" , valueType ));
66
+ throw new IllegalArgumentException (
67
+ String .format ("Only numeric primitives are supported as identifier / version field types; Got: %s" ,
68
+ valueType ));
65
69
}
66
70
}
67
71
}
0 commit comments