27
27
import org .springframework .data .mapping .Association ;
28
28
import org .springframework .data .mapping .PersistentEntity ;
29
29
import org .springframework .data .mapping .PersistentProperty ;
30
+ import org .springframework .data .util .KotlinReflectionUtils ;
30
31
import org .springframework .data .util .Lazy ;
31
32
import org .springframework .data .util .ReflectionUtils ;
32
33
import org .springframework .data .util .TypeInformation ;
@@ -70,6 +71,7 @@ public abstract class AbstractPersistentProperty<P extends PersistentProperty<P>
70
71
private final Method setter ;
71
72
private final Field field ;
72
73
private final Method wither ;
74
+ private final Lazy <Boolean > readable ;
73
75
private final boolean immutable ;
74
76
75
77
public AbstractPersistentProperty (Property property , PersistentEntity <?, P > owner ,
@@ -103,11 +105,27 @@ public AbstractPersistentProperty(Property property, PersistentEntity<?, P> owne
103
105
this .field = property .getField ().orElse (null );
104
106
this .wither = property .getWither ().orElse (null );
105
107
106
- if (setter == null && (field == null || Modifier .isFinal (field .getModifiers ()))) {
107
- this .immutable = true ;
108
- } else {
109
- this .immutable = false ;
110
- }
108
+ this .immutable = setter == null && (field == null || Modifier .isFinal (field .getModifiers ()));
109
+ this .readable = Lazy .of (() -> {
110
+
111
+ if (setter != null ) {
112
+ return true ;
113
+ }
114
+
115
+ if (wither != null ) {
116
+ return true ;
117
+ }
118
+
119
+ if (KotlinReflectionUtils .isDataClass (owner .getType ()) && KotlinCopyMethod .hasKotlinCopyMethodFor (this )) {
120
+ return true ;
121
+ }
122
+
123
+ if (field != null && !Modifier .isFinal (field .getModifiers ())) {
124
+ return true ;
125
+ }
126
+
127
+ return false ;
128
+ });
111
129
}
112
130
113
131
protected abstract Association <P > createAssociation ();
@@ -170,6 +188,7 @@ public Method getWither() {
170
188
}
171
189
172
190
@ Nullable
191
+ @ Override
173
192
public Field getField () {
174
193
return this .field ;
175
194
}
@@ -190,6 +209,11 @@ public boolean isWritable() {
190
209
return !isTransient ();
191
210
}
192
211
212
+ @ Override
213
+ public boolean isReadable () {
214
+ return !isTransient () && readable .get ();
215
+ }
216
+
193
217
@ Override
194
218
public boolean isImmutable () {
195
219
return immutable ;
@@ -313,10 +337,8 @@ private Set<TypeInformation<?>> detectEntityTypes(SimpleTypeHolder simpleTypes)
313
337
314
338
Set <TypeInformation <?>> result = detectEntityTypes (typeToStartWith );
315
339
316
- return result .stream ()
317
- .filter (it -> !simpleTypes .isSimpleType (it .getType ()))
318
- .filter (it -> !it .getType ().equals (ASSOCIATION_TYPE ))
319
- .collect (Collectors .toSet ());
340
+ return result .stream ().filter (it -> !simpleTypes .isSimpleType (it .getType ()))
341
+ .filter (it -> !it .getType ().equals (ASSOCIATION_TYPE )).collect (Collectors .toSet ());
320
342
}
321
343
322
344
private Set <TypeInformation <?>> detectEntityTypes (@ Nullable TypeInformation <?> source ) {
0 commit comments