Skip to content

Commit b3a1da7

Browse files
committed
HHH-17460 - Ongoing JPA 32 work
1 parent f494f52 commit b3a1da7

File tree

6 files changed

+66
-20
lines changed

6 files changed

+66
-20
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,9 @@ public static DomainModelSource processManagedResources(
437437
final AnnotationDescriptorRegistry descriptorRegistry = sourceModelBuildingContext.getAnnotationDescriptorRegistry();
438438
final DomainModelCategorizationCollector modelCategorizationCollector = new DomainModelCategorizationCollector(
439439
areIdGeneratorsGlobal,
440-
classDetailsRegistry,
441-
descriptorRegistry,
442440
metadataCollector.getGlobalRegistrations(),
443-
jandexIndex
441+
jandexIndex,
442+
sourceModelBuildingContext
444443
);
445444

446445
final XmlProcessingResult xmlProcessingResult = XmlProcessor.processXml( xmlPreProcessingResult, modelCategorizationCollector, sourceModelBuildingContext );

hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/DomainModelCategorizationCollector.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,21 @@ public class DomainModelCategorizationCollector {
4646
private final IndexView jandexIndex;
4747

4848
private final GlobalRegistrationsImpl globalRegistrations;
49+
private final SourceModelBuildingContext modelsContext;
4950

5051
private final Set<ClassDetails> rootEntities = new HashSet<>();
5152
private final Map<String,ClassDetails> mappedSuperclasses = new HashMap<>();
5253
private final Map<String,ClassDetails> embeddables = new HashMap<>();
5354

5455
public DomainModelCategorizationCollector(
5556
boolean areIdGeneratorsGlobal,
56-
ClassDetailsRegistry classDetailsRegistry,
57-
AnnotationDescriptorRegistry descriptorRegistry,
5857
GlobalRegistrations globalRegistrations,
59-
IndexView jandexIndex) {
58+
IndexView jandexIndex,
59+
SourceModelBuildingContext modelsContext) {
6060
this.areIdGeneratorsGlobal = areIdGeneratorsGlobal;
6161
this.jandexIndex = jandexIndex;
6262
this.globalRegistrations = (GlobalRegistrationsImpl) globalRegistrations;
63+
this.modelsContext = modelsContext;
6364
}
6465

6566
public GlobalRegistrationsImpl getGlobalRegistrations() {
@@ -95,7 +96,7 @@ public void apply(JaxbEntityMappingsImpl jaxbRoot) {
9596
if ( persistenceUnitDefaults != null ) {
9697
final JaxbEntityListenerContainerImpl listenerContainer = persistenceUnitDefaults.getEntityListenerContainer();
9798
if ( listenerContainer != null ) {
98-
getGlobalRegistrations().collectEntityListenerRegistrations( listenerContainer.getEntityListeners() );
99+
getGlobalRegistrations().collectEntityListenerRegistrations( listenerContainer.getEntityListeners(), modelsContext );
99100
}
100101
}
101102
}

hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/GlobalRegistrationsImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
import org.hibernate.models.spi.ClassDetails;
8181
import org.hibernate.models.spi.ClassDetailsRegistry;
8282
import org.hibernate.models.spi.MutableAnnotationUsage;
83+
import org.hibernate.models.spi.SourceModelBuildingContext;
8384
import org.hibernate.models.spi.SourceModelContext;
8485

8586
import jakarta.persistence.ColumnResult;
@@ -583,7 +584,7 @@ public void collectImportRename(String rename, String name) {
583584
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
584585
// EntityListenerRegistration
585586

586-
public void collectEntityListenerRegistrations(List<JaxbEntityListenerImpl> listeners) {
587+
public void collectEntityListenerRegistrations(List<JaxbEntityListenerImpl> listeners, SourceModelBuildingContext modelsContext) {
587588
if ( CollectionHelper.isEmpty( listeners ) ) {
588589
return;
589590
}
@@ -593,7 +594,8 @@ public void collectEntityListenerRegistrations(List<JaxbEntityListenerImpl> list
593594
final JpaEventListener listener = JpaEventListener.from(
594595
JpaEventListenerStyle.LISTENER,
595596
classDetails,
596-
jaxbEntityListener
597+
jaxbEntityListener,
598+
modelsContext
597599
);
598600
addJpaEventListener( listener );
599601
} );

hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/JpaEventListener.java

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88

99
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListenerImpl;
1010
import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitDefaultsImpl;
11+
import org.hibernate.boot.models.JpaAnnotations;
1112
import org.hibernate.internal.util.MutableObject;
1213
import org.hibernate.models.ModelsException;
1314
import org.hibernate.models.spi.ClassDetails;
1415
import org.hibernate.models.spi.MethodDetails;
16+
import org.hibernate.models.spi.MutableMemberDetails;
17+
import org.hibernate.models.spi.SourceModelBuildingContext;
1518

1619
import jakarta.persistence.PostLoad;
1720
import jakarta.persistence.PostPersist;
@@ -22,10 +25,10 @@
2225
import jakarta.persistence.PreUpdate;
2326

2427
/**
25-
* JPA-style event listener with support for resolving callback methods
26-
* {@linkplain #from(JpaEventListenerStyle, ClassDetails, JaxbEntityListenerImpl) by name} (from XML)
27-
* or by {@linkplain #from(JpaEventListenerStyle, ClassDetails) annotation}.
28-
*
28+
* JPA-style event listener with support for resolving callback methods from
29+
* {@linkplain #from(JpaEventListenerStyle, ClassDetails, JaxbEntityListenerImpl, SourceModelBuildingContext) XML}
30+
* or from {@linkplain #from(JpaEventListenerStyle, ClassDetails) annotation}.
31+
* <p/>
2932
* Represents a global entity listener defined in the persistence unit
3033
*
3134
* @see JaxbPersistenceUnitDefaultsImpl#getEntityListenerContainer()
@@ -117,7 +120,8 @@ public MethodDetails getPostLoadMethod() {
117120
public static JpaEventListener from(
118121
JpaEventListenerStyle consumerType,
119122
ClassDetails listenerClassDetails,
120-
JaxbEntityListenerImpl jaxbMapping) {
123+
JaxbEntityListenerImpl jaxbMapping,
124+
SourceModelBuildingContext modelsContext) {
121125
final MutableObject<MethodDetails> prePersistMethod = new MutableObject<>();
122126
final MutableObject<MethodDetails> postPersistMethod = new MutableObject<>();
123127
final MutableObject<MethodDetails> preRemoveMethod = new MutableObject<>();
@@ -135,36 +139,78 @@ public static JpaEventListener from(
135139
&& methodDetails.getName().equals( jaxbMapping.getPrePersist().getMethodName() )
136140
&& matchesSignature( consumerType, methodDetails ) ) {
137141
prePersistMethod.set( methodDetails );
142+
( (MutableMemberDetails) methodDetails ).addAnnotationUsage(
143+
JpaAnnotations.PRE_PERSIST.createUsage(
144+
methodDetails,
145+
modelsContext
146+
)
147+
);
138148
}
139149
else if ( jaxbMapping.getPostPersist() != null
140150
&& methodDetails.getName().equals( jaxbMapping.getPostPersist().getMethodName() )
141151
&& matchesSignature( consumerType, methodDetails ) ) {
142152
postPersistMethod.set( methodDetails );
153+
( (MutableMemberDetails) methodDetails ).addAnnotationUsage(
154+
JpaAnnotations.POST_PERSIST.createUsage(
155+
methodDetails,
156+
modelsContext
157+
)
158+
);
143159
}
144160
else if ( jaxbMapping.getPreRemove() != null
145161
&& methodDetails.getName().equals( jaxbMapping.getPreRemove().getMethodName() )
146162
&& matchesSignature( consumerType, methodDetails ) ) {
147163
preRemoveMethod.set( methodDetails );
164+
( (MutableMemberDetails) methodDetails ).addAnnotationUsage(
165+
JpaAnnotations.PRE_REMOVE.createUsage(
166+
methodDetails,
167+
modelsContext
168+
)
169+
);
148170
}
149171
else if ( jaxbMapping.getPostRemove() != null
150172
&& methodDetails.getName().equals( jaxbMapping.getPostRemove().getMethodName() )
151173
&& matchesSignature( consumerType, methodDetails ) ) {
152174
postRemoveMethod.set( methodDetails );
175+
( (MutableMemberDetails) methodDetails ).addAnnotationUsage(
176+
JpaAnnotations.POST_REMOVE.createUsage(
177+
methodDetails,
178+
modelsContext
179+
)
180+
);
153181
}
154182
else if ( jaxbMapping.getPreUpdate() != null
155183
&& methodDetails.getName().equals( jaxbMapping.getPreUpdate().getMethodName() )
156184
&& matchesSignature( consumerType, methodDetails ) ) {
157185
preUpdateMethod.set( methodDetails );
186+
( (MutableMemberDetails) methodDetails ).addAnnotationUsage(
187+
JpaAnnotations.PRE_UPDATE.createUsage(
188+
methodDetails,
189+
modelsContext
190+
)
191+
);
158192
}
159193
else if ( jaxbMapping.getPostUpdate() != null
160194
&& methodDetails.getName().equals( jaxbMapping.getPostUpdate().getMethodName() )
161195
&& matchesSignature( consumerType, methodDetails ) ) {
162196
postUpdateMethod.set( methodDetails );
197+
( (MutableMemberDetails) methodDetails ).addAnnotationUsage(
198+
JpaAnnotations.POST_UPDATE.createUsage(
199+
methodDetails,
200+
modelsContext
201+
)
202+
);
163203
}
164204
else if ( jaxbMapping.getPostLoad() != null
165205
&& methodDetails.getName().equals( jaxbMapping.getPostLoad().getMethodName() )
166206
&& matchesSignature( consumerType, methodDetails ) ) {
167207
postLoadMethod.set( methodDetails );
208+
( (MutableMemberDetails) methodDetails ).addAnnotationUsage(
209+
JpaAnnotations.POST_LOAD.createUsage(
210+
methodDetails,
211+
modelsContext
212+
)
213+
);
168214
}
169215
} );
170216

hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/ManagedResourcesProcessor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,9 @@ public static CategorizedDomainModel processManagedResources(
128128
final GlobalRegistrationsImpl globalRegistrations = new GlobalRegistrationsImpl( sourceModelBuildingContext );
129129
final DomainModelCategorizationCollector modelCategorizationCollector = new DomainModelCategorizationCollector(
130130
areIdGeneratorsGlobal,
131-
classDetailsRegistry,
132-
descriptorRegistry,
133131
globalRegistrations,
134-
jandexIndex
132+
jandexIndex,
133+
sourceModelBuildingContext
135134
);
136135

137136
final XmlProcessingResult xmlProcessingResult = XmlProcessor.processXml( xmlPreProcessingResult, modelCategorizationCollector, sourceModelBuildingContext );

hibernate-core/src/test/java/org/hibernate/orm/test/boot/models/xml/XmlProcessingSmokeTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,9 @@ void testSimpleGlobalXmlProcessing() {
126126

127127
final DomainModelCategorizationCollector collector = new DomainModelCategorizationCollector(
128128
false,
129-
buildingContext.getClassDetailsRegistry(),
130-
buildingContext.getAnnotationDescriptorRegistry(),
131129
new GlobalRegistrationsImpl( buildingContext ),
132-
null
130+
null,
131+
buildingContext
133132
);
134133
collectedXmlResources.getDocuments().forEach( collector::apply );
135134

0 commit comments

Comments
 (0)