HHH-17460 - Ongoing JPA 32 work
This commit is contained in:
parent
ba26055c56
commit
b63af21c77
|
@ -437,10 +437,9 @@ public class MetadataBuildingProcess {
|
|||
final AnnotationDescriptorRegistry descriptorRegistry = sourceModelBuildingContext.getAnnotationDescriptorRegistry();
|
||||
final DomainModelCategorizationCollector modelCategorizationCollector = new DomainModelCategorizationCollector(
|
||||
areIdGeneratorsGlobal,
|
||||
classDetailsRegistry,
|
||||
descriptorRegistry,
|
||||
metadataCollector.getGlobalRegistrations(),
|
||||
jandexIndex
|
||||
jandexIndex,
|
||||
sourceModelBuildingContext
|
||||
);
|
||||
|
||||
final XmlProcessingResult xmlProcessingResult = XmlProcessor.processXml( xmlPreProcessingResult, modelCategorizationCollector, sourceModelBuildingContext );
|
||||
|
|
|
@ -46,6 +46,7 @@ public class DomainModelCategorizationCollector {
|
|||
private final IndexView jandexIndex;
|
||||
|
||||
private final GlobalRegistrationsImpl globalRegistrations;
|
||||
private final SourceModelBuildingContext modelsContext;
|
||||
|
||||
private final Set<ClassDetails> rootEntities = new HashSet<>();
|
||||
private final Map<String,ClassDetails> mappedSuperclasses = new HashMap<>();
|
||||
|
@ -53,13 +54,13 @@ public class DomainModelCategorizationCollector {
|
|||
|
||||
public DomainModelCategorizationCollector(
|
||||
boolean areIdGeneratorsGlobal,
|
||||
ClassDetailsRegistry classDetailsRegistry,
|
||||
AnnotationDescriptorRegistry descriptorRegistry,
|
||||
GlobalRegistrations globalRegistrations,
|
||||
IndexView jandexIndex) {
|
||||
IndexView jandexIndex,
|
||||
SourceModelBuildingContext modelsContext) {
|
||||
this.areIdGeneratorsGlobal = areIdGeneratorsGlobal;
|
||||
this.jandexIndex = jandexIndex;
|
||||
this.globalRegistrations = (GlobalRegistrationsImpl) globalRegistrations;
|
||||
this.modelsContext = modelsContext;
|
||||
}
|
||||
|
||||
public GlobalRegistrationsImpl getGlobalRegistrations() {
|
||||
|
@ -95,7 +96,7 @@ public class DomainModelCategorizationCollector {
|
|||
if ( persistenceUnitDefaults != null ) {
|
||||
final JaxbEntityListenerContainerImpl listenerContainer = persistenceUnitDefaults.getEntityListenerContainer();
|
||||
if ( listenerContainer != null ) {
|
||||
getGlobalRegistrations().collectEntityListenerRegistrations( listenerContainer.getEntityListeners() );
|
||||
getGlobalRegistrations().collectEntityListenerRegistrations( listenerContainer.getEntityListeners(), modelsContext );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,6 +80,7 @@ import org.hibernate.models.spi.AnnotationUsage;
|
|||
import org.hibernate.models.spi.ClassDetails;
|
||||
import org.hibernate.models.spi.ClassDetailsRegistry;
|
||||
import org.hibernate.models.spi.MutableAnnotationUsage;
|
||||
import org.hibernate.models.spi.SourceModelBuildingContext;
|
||||
import org.hibernate.models.spi.SourceModelContext;
|
||||
|
||||
import jakarta.persistence.ColumnResult;
|
||||
|
@ -583,7 +584,7 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
|
|||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// EntityListenerRegistration
|
||||
|
||||
public void collectEntityListenerRegistrations(List<JaxbEntityListenerImpl> listeners) {
|
||||
public void collectEntityListenerRegistrations(List<JaxbEntityListenerImpl> listeners, SourceModelBuildingContext modelsContext) {
|
||||
if ( CollectionHelper.isEmpty( listeners ) ) {
|
||||
return;
|
||||
}
|
||||
|
@ -593,7 +594,8 @@ public class GlobalRegistrationsImpl implements GlobalRegistrations {
|
|||
final JpaEventListener listener = JpaEventListener.from(
|
||||
JpaEventListenerStyle.LISTENER,
|
||||
classDetails,
|
||||
jaxbEntityListener
|
||||
jaxbEntityListener,
|
||||
modelsContext
|
||||
);
|
||||
addJpaEventListener( listener );
|
||||
} );
|
||||
|
|
|
@ -8,10 +8,13 @@ package org.hibernate.boot.models.categorize.spi;
|
|||
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListenerImpl;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitDefaultsImpl;
|
||||
import org.hibernate.boot.models.JpaAnnotations;
|
||||
import org.hibernate.internal.util.MutableObject;
|
||||
import org.hibernate.models.ModelsException;
|
||||
import org.hibernate.models.spi.ClassDetails;
|
||||
import org.hibernate.models.spi.MethodDetails;
|
||||
import org.hibernate.models.spi.MutableMemberDetails;
|
||||
import org.hibernate.models.spi.SourceModelBuildingContext;
|
||||
|
||||
import jakarta.persistence.PostLoad;
|
||||
import jakarta.persistence.PostPersist;
|
||||
|
@ -22,10 +25,10 @@ import jakarta.persistence.PreRemove;
|
|||
import jakarta.persistence.PreUpdate;
|
||||
|
||||
/**
|
||||
* JPA-style event listener with support for resolving callback methods
|
||||
* {@linkplain #from(JpaEventListenerStyle, ClassDetails, JaxbEntityListenerImpl) by name} (from XML)
|
||||
* or by {@linkplain #from(JpaEventListenerStyle, ClassDetails) annotation}.
|
||||
*
|
||||
* JPA-style event listener with support for resolving callback methods from
|
||||
* {@linkplain #from(JpaEventListenerStyle, ClassDetails, JaxbEntityListenerImpl, SourceModelBuildingContext) XML}
|
||||
* or from {@linkplain #from(JpaEventListenerStyle, ClassDetails) annotation}.
|
||||
* <p/>
|
||||
* Represents a global entity listener defined in the persistence unit
|
||||
*
|
||||
* @see JaxbPersistenceUnitDefaultsImpl#getEntityListenerContainer()
|
||||
|
@ -117,7 +120,8 @@ public class JpaEventListener {
|
|||
public static JpaEventListener from(
|
||||
JpaEventListenerStyle consumerType,
|
||||
ClassDetails listenerClassDetails,
|
||||
JaxbEntityListenerImpl jaxbMapping) {
|
||||
JaxbEntityListenerImpl jaxbMapping,
|
||||
SourceModelBuildingContext modelsContext) {
|
||||
final MutableObject<MethodDetails> prePersistMethod = new MutableObject<>();
|
||||
final MutableObject<MethodDetails> postPersistMethod = new MutableObject<>();
|
||||
final MutableObject<MethodDetails> preRemoveMethod = new MutableObject<>();
|
||||
|
@ -135,36 +139,78 @@ public class JpaEventListener {
|
|||
&& methodDetails.getName().equals( jaxbMapping.getPrePersist().getMethodName() )
|
||||
&& matchesSignature( consumerType, methodDetails ) ) {
|
||||
prePersistMethod.set( methodDetails );
|
||||
( (MutableMemberDetails) methodDetails ).addAnnotationUsage(
|
||||
JpaAnnotations.PRE_PERSIST.createUsage(
|
||||
methodDetails,
|
||||
modelsContext
|
||||
)
|
||||
);
|
||||
}
|
||||
else if ( jaxbMapping.getPostPersist() != null
|
||||
&& methodDetails.getName().equals( jaxbMapping.getPostPersist().getMethodName() )
|
||||
&& matchesSignature( consumerType, methodDetails ) ) {
|
||||
postPersistMethod.set( methodDetails );
|
||||
( (MutableMemberDetails) methodDetails ).addAnnotationUsage(
|
||||
JpaAnnotations.POST_PERSIST.createUsage(
|
||||
methodDetails,
|
||||
modelsContext
|
||||
)
|
||||
);
|
||||
}
|
||||
else if ( jaxbMapping.getPreRemove() != null
|
||||
&& methodDetails.getName().equals( jaxbMapping.getPreRemove().getMethodName() )
|
||||
&& matchesSignature( consumerType, methodDetails ) ) {
|
||||
preRemoveMethod.set( methodDetails );
|
||||
( (MutableMemberDetails) methodDetails ).addAnnotationUsage(
|
||||
JpaAnnotations.PRE_REMOVE.createUsage(
|
||||
methodDetails,
|
||||
modelsContext
|
||||
)
|
||||
);
|
||||
}
|
||||
else if ( jaxbMapping.getPostRemove() != null
|
||||
&& methodDetails.getName().equals( jaxbMapping.getPostRemove().getMethodName() )
|
||||
&& matchesSignature( consumerType, methodDetails ) ) {
|
||||
postRemoveMethod.set( methodDetails );
|
||||
( (MutableMemberDetails) methodDetails ).addAnnotationUsage(
|
||||
JpaAnnotations.POST_REMOVE.createUsage(
|
||||
methodDetails,
|
||||
modelsContext
|
||||
)
|
||||
);
|
||||
}
|
||||
else if ( jaxbMapping.getPreUpdate() != null
|
||||
&& methodDetails.getName().equals( jaxbMapping.getPreUpdate().getMethodName() )
|
||||
&& matchesSignature( consumerType, methodDetails ) ) {
|
||||
preUpdateMethod.set( methodDetails );
|
||||
( (MutableMemberDetails) methodDetails ).addAnnotationUsage(
|
||||
JpaAnnotations.PRE_UPDATE.createUsage(
|
||||
methodDetails,
|
||||
modelsContext
|
||||
)
|
||||
);
|
||||
}
|
||||
else if ( jaxbMapping.getPostUpdate() != null
|
||||
&& methodDetails.getName().equals( jaxbMapping.getPostUpdate().getMethodName() )
|
||||
&& matchesSignature( consumerType, methodDetails ) ) {
|
||||
postUpdateMethod.set( methodDetails );
|
||||
( (MutableMemberDetails) methodDetails ).addAnnotationUsage(
|
||||
JpaAnnotations.POST_UPDATE.createUsage(
|
||||
methodDetails,
|
||||
modelsContext
|
||||
)
|
||||
);
|
||||
}
|
||||
else if ( jaxbMapping.getPostLoad() != null
|
||||
&& methodDetails.getName().equals( jaxbMapping.getPostLoad().getMethodName() )
|
||||
&& matchesSignature( consumerType, methodDetails ) ) {
|
||||
postLoadMethod.set( methodDetails );
|
||||
( (MutableMemberDetails) methodDetails ).addAnnotationUsage(
|
||||
JpaAnnotations.POST_LOAD.createUsage(
|
||||
methodDetails,
|
||||
modelsContext
|
||||
)
|
||||
);
|
||||
}
|
||||
} );
|
||||
|
||||
|
|
|
@ -128,10 +128,9 @@ public class ManagedResourcesProcessor {
|
|||
final GlobalRegistrationsImpl globalRegistrations = new GlobalRegistrationsImpl( sourceModelBuildingContext );
|
||||
final DomainModelCategorizationCollector modelCategorizationCollector = new DomainModelCategorizationCollector(
|
||||
areIdGeneratorsGlobal,
|
||||
classDetailsRegistry,
|
||||
descriptorRegistry,
|
||||
globalRegistrations,
|
||||
jandexIndex
|
||||
jandexIndex,
|
||||
sourceModelBuildingContext
|
||||
);
|
||||
|
||||
final XmlProcessingResult xmlProcessingResult = XmlProcessor.processXml( xmlPreProcessingResult, modelCategorizationCollector, sourceModelBuildingContext );
|
||||
|
|
|
@ -126,10 +126,9 @@ public class XmlProcessingSmokeTests {
|
|||
|
||||
final DomainModelCategorizationCollector collector = new DomainModelCategorizationCollector(
|
||||
false,
|
||||
buildingContext.getClassDetailsRegistry(),
|
||||
buildingContext.getAnnotationDescriptorRegistry(),
|
||||
new GlobalRegistrationsImpl( buildingContext ),
|
||||
null
|
||||
null,
|
||||
buildingContext
|
||||
);
|
||||
collectedXmlResources.getDocuments().forEach( collector::apply );
|
||||
|
||||
|
|
Loading…
Reference in New Issue