2424import org .springframework .data .mapping .model .BasicPersistentEntity ;
2525import org .springframework .data .mapping .model .ClassGeneratingPropertyAccessorFactory ;
2626import org .springframework .data .mapping .model .EntityInstantiator ;
27+ import org .springframework .data .mapping .model .EntityInstantiatorSource ;
2728import org .springframework .data .mapping .model .EntityInstantiators ;
28- import org .springframework .data .mapping .model .PersistentEntityClassInitializer ;
2929import org .springframework .data .mapping .model .Property ;
3030import org .springframework .data .mapping .model .SimpleTypeHolder ;
3131import org .springframework .data .repository .aot .generate .RepositoryContributor ;
3737 * @author Mark Paluch
3838 * @since 4.0
3939 */
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 > {
4342
4443 private static final Log logger = LogFactory .getLog (AotMappingContext .class );
4544
4645 private final EntityInstantiators instantiators = new EntityInstantiators ();
47- private final ClassGeneratingPropertyAccessorFactory propertyAccessorFactory = new ClassGeneratingPropertyAccessorFactory ();
46+ private final AotAccessorFactory propertyAccessorFactory = new AotAccessorFactory ();
4847
4948 /**
5049 * Contribute entity instantiators and property accessors for the given {@link PersistentEntity} that are captured
5150 * through Spring's {@code CglibClassHandler}. Otherwise, this is a no-op if contributions are not ran through
5251 * {@code CglibClassHandler}.
5352 *
54- * @param entity
53+ * @param entityType
5554 */
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 );
6067 }
61- propertyAccessorFactory .initialize (entity );
6268 }
6369
64- // TODO: can we extract some util for this using only type
6570 @ Override
66- protected <T > BasicPersistentEntity <?, BasicPersistentProperty > createPersistentEntity (
71+ protected <T > BasicPersistentEntity <?, AotPersistentProperty > createPersistentEntity (
6772 TypeInformation <T > typeInformation ) {
6873 logger .debug ("I hate gradle: create persistent entity for type: " + typeInformation );
6974 return new BasicPersistentEntity <>(typeInformation );
7075 }
7176
7277 @ 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 ) {
7580 logger .info ("creating property: " + property .getName ());
76- return new BasicPersistentProperty (property , owner , simpleTypeHolder );
81+ return new AotPersistentProperty (property , owner , simpleTypeHolder );
7782 }
7883
79- static class BasicPersistentProperty extends AnnotationBasedPersistentProperty <BasicPersistentProperty > {
84+ static class AotPersistentProperty extends AnnotationBasedPersistentProperty <AotPersistentProperty > {
8085
81- public BasicPersistentProperty (Property property , PersistentEntity <?, BasicPersistentProperty > owner ,
86+ public AotPersistentProperty (Property property , PersistentEntity <?, AotPersistentProperty > owner ,
8287 SimpleTypeHolder simpleTypeHolder ) {
8388 super (property , owner , simpleTypeHolder );
8489 }
@@ -89,15 +94,22 @@ public boolean isAssociation() {
8994 }
9095
9196 @ Override
92- protected Association <BasicPersistentProperty > createAssociation () {
97+ protected Association <AotPersistentProperty > createAssociation () {
9398 return new Association <>(this , null );
9499 }
95100
96101 @ Override
97- public Association <BasicPersistentProperty > getRequiredAssociation () {
102+ public Association <AotPersistentProperty > getAssociation () {
98103 return new Association <>(this , null );
99104 }
100105
101106 }
102107
108+ static class AotAccessorFactory extends ClassGeneratingPropertyAccessorFactory {
109+
110+ public void initialize (PersistentEntity <?, ?> entity ) {
111+ potentiallyCreateAndRegisterPersistentPropertyAccessorClass (entity );
112+ }
113+ }
114+
103115}
0 commit comments