24
24
import org .springframework .data .mapping .model .BasicPersistentEntity ;
25
25
import org .springframework .data .mapping .model .ClassGeneratingPropertyAccessorFactory ;
26
26
import org .springframework .data .mapping .model .EntityInstantiator ;
27
+ import org .springframework .data .mapping .model .EntityInstantiatorSource ;
27
28
import org .springframework .data .mapping .model .EntityInstantiators ;
28
- import org .springframework .data .mapping .model .PersistentEntityClassInitializer ;
29
29
import org .springframework .data .mapping .model .Property ;
30
30
import org .springframework .data .mapping .model .SimpleTypeHolder ;
31
31
import org .springframework .data .repository .aot .generate .RepositoryContributor ;
37
37
* @author Mark Paluch
38
38
* @since 4.0
39
39
*/
40
- class AotMappingContext extends // TODO: hide this one and delegate to other component - can we use the
41
- // AotContext for it?
42
- AbstractMappingContext <BasicPersistentEntity <?, AotMappingContext .BasicPersistentProperty >, AotMappingContext .BasicPersistentProperty > {
40
+ class AotMappingContext extends
41
+ AbstractMappingContext <BasicPersistentEntity <?, AotMappingContext .AotPersistentProperty >, AotMappingContext .AotPersistentProperty > {
43
42
44
43
private static final Log logger = LogFactory .getLog (AotMappingContext .class );
45
44
46
45
private final EntityInstantiators instantiators = new EntityInstantiators ();
47
- private final ClassGeneratingPropertyAccessorFactory propertyAccessorFactory = new ClassGeneratingPropertyAccessorFactory ();
46
+ private final AotAccessorFactory propertyAccessorFactory = new AotAccessorFactory ();
48
47
49
48
/**
50
49
* Contribute entity instantiators and property accessors for the given {@link PersistentEntity} that are captured
51
50
* through Spring's {@code CglibClassHandler}. Otherwise, this is a no-op if contributions are not ran through
52
51
* {@code CglibClassHandler}.
53
52
*
54
- * @param entity
53
+ * @param entityType
55
54
*/
56
- public void contribute (PersistentEntity <?, ?> entity ) {
57
- EntityInstantiator instantiator = instantiators .getInstantiatorFor (entity );
58
- if (instantiator instanceof PersistentEntityClassInitializer pec ) {
59
- pec .initialize (entity );
55
+ public void contribute (Class <?> entityType ) {
56
+
57
+ BasicPersistentEntity <?, AotPersistentProperty > entity = getPersistentEntity (entityType );
58
+
59
+ if (entity != null ) {
60
+
61
+ EntityInstantiator instantiator = instantiators .getInstantiatorFor (entity );
62
+ if (instantiator instanceof EntityInstantiatorSource source ) {
63
+ source .getInstantiatorFor (entity );
64
+ }
65
+
66
+ propertyAccessorFactory .initialize (entity );
60
67
}
61
- propertyAccessorFactory .initialize (entity );
62
68
}
63
69
64
- // TODO: can we extract some util for this using only type
65
70
@ Override
66
- protected <T > BasicPersistentEntity <?, BasicPersistentProperty > createPersistentEntity (
71
+ protected <T > BasicPersistentEntity <?, AotPersistentProperty > createPersistentEntity (
67
72
TypeInformation <T > typeInformation ) {
68
73
logger .debug ("I hate gradle: create persistent entity for type: " + typeInformation );
69
74
return new BasicPersistentEntity <>(typeInformation );
70
75
}
71
76
72
77
@ Override
73
- protected BasicPersistentProperty createPersistentProperty (Property property ,
74
- BasicPersistentEntity <?, BasicPersistentProperty > owner , SimpleTypeHolder simpleTypeHolder ) {
78
+ protected AotPersistentProperty createPersistentProperty (Property property ,
79
+ BasicPersistentEntity <?, AotPersistentProperty > owner , SimpleTypeHolder simpleTypeHolder ) {
75
80
logger .info ("creating property: " + property .getName ());
76
- return new BasicPersistentProperty (property , owner , simpleTypeHolder );
81
+ return new AotPersistentProperty (property , owner , simpleTypeHolder );
77
82
}
78
83
79
- static class BasicPersistentProperty extends AnnotationBasedPersistentProperty <BasicPersistentProperty > {
84
+ static class AotPersistentProperty extends AnnotationBasedPersistentProperty <AotPersistentProperty > {
80
85
81
- public BasicPersistentProperty (Property property , PersistentEntity <?, BasicPersistentProperty > owner ,
86
+ public AotPersistentProperty (Property property , PersistentEntity <?, AotPersistentProperty > owner ,
82
87
SimpleTypeHolder simpleTypeHolder ) {
83
88
super (property , owner , simpleTypeHolder );
84
89
}
@@ -89,15 +94,22 @@ public boolean isAssociation() {
89
94
}
90
95
91
96
@ Override
92
- protected Association <BasicPersistentProperty > createAssociation () {
97
+ protected Association <AotPersistentProperty > createAssociation () {
93
98
return new Association <>(this , null );
94
99
}
95
100
96
101
@ Override
97
- public Association <BasicPersistentProperty > getRequiredAssociation () {
102
+ public Association <AotPersistentProperty > getAssociation () {
98
103
return new Association <>(this , null );
99
104
}
100
105
101
106
}
102
107
108
+ static class AotAccessorFactory extends ClassGeneratingPropertyAccessorFactory {
109
+
110
+ public void initialize (PersistentEntity <?, ?> entity ) {
111
+ potentiallyCreateAndRegisterPersistentPropertyAccessorClass (entity );
112
+ }
113
+ }
114
+
103
115
}
0 commit comments