HHH-16006 - Implement an "additional mapping" contributor SPI

This commit is contained in:
Steve Ebersole 2023-01-09 18:14:27 -06:00
parent a9ef9045f2
commit d1a890a9cc
3 changed files with 36 additions and 9 deletions

View File

@ -318,15 +318,19 @@ public class MetadataBuildingProcess {
processor.finishUp(); processor.finishUp();
processAdditionalMappingContributions( options, metadataCollector, classLoaderService, rootMetadataBuildingContext ); processAdditionalMappingContributions( metadataCollector, options, classLoaderService, rootMetadataBuildingContext );
processAdditionalJaxbMappingProducer( options, metadataCollector, classLoaderService, rootMetadataBuildingContext, jandexView ); processAdditionalJaxbMappingProducer( metadataCollector, options, jandexView, classLoaderService, rootMetadataBuildingContext );
applyExtraQueryImports( managedResources, metadataCollector ); applyExtraQueryImports( managedResources, metadataCollector );
return metadataCollector.buildMetadataInstance( rootMetadataBuildingContext ); return metadataCollector.buildMetadataInstance( rootMetadataBuildingContext );
} }
private static void processAdditionalMappingContributions(MetadataBuildingOptions options, InFlightMetadataCollectorImpl metadataCollector, ClassLoaderService classLoaderService, MetadataBuildingContextRootImpl rootMetadataBuildingContext) { private static void processAdditionalMappingContributions(
InFlightMetadataCollectorImpl metadataCollector,
MetadataBuildingOptions options,
ClassLoaderService classLoaderService,
MetadataBuildingContextRootImpl rootMetadataBuildingContext) {
final EntityHierarchyBuilder hierarchyBuilder = new EntityHierarchyBuilder(); final EntityHierarchyBuilder hierarchyBuilder = new EntityHierarchyBuilder();
final AdditionalMappingContributionsImpl contributions = new AdditionalMappingContributionsImpl( final AdditionalMappingContributionsImpl contributions = new AdditionalMappingContributionsImpl(
metadataCollector, metadataCollector,
@ -396,13 +400,10 @@ public class MetadataBuildingProcess {
this.hierarchyBuilder = hierarchyBuilder; this.hierarchyBuilder = hierarchyBuilder;
} }
public String getCurrentContributor() {
return currentContributor;
}
public void setCurrentContributor(String contributor) { public void setCurrentContributor(String contributor) {
this.currentContributor = contributor == null ? "orm" : contributor; this.currentContributor = contributor == null ? "orm" : contributor;
} }
@Override @Override
public void contributeBinding(JaxbHbmHibernateMapping hbmJaxbBinding, Origin origin) { public void contributeBinding(JaxbHbmHibernateMapping hbmJaxbBinding, Origin origin) {
if ( ! options.isXmlMappingEnabled() ) { if ( ! options.isXmlMappingEnabled() ) {
@ -447,8 +448,12 @@ public class MetadataBuildingProcess {
} }
} }
@Deprecated private static void processAdditionalJaxbMappingProducer(
private static void processAdditionalJaxbMappingProducer(MetadataBuildingOptions options, InFlightMetadataCollectorImpl metadataCollector, ClassLoaderService classLoaderService, MetadataBuildingContextRootImpl rootMetadataBuildingContext, IndexView jandexView) { InFlightMetadataCollectorImpl metadataCollector,
MetadataBuildingOptions options,
IndexView jandexView,
ClassLoaderService classLoaderService,
MetadataBuildingContextRootImpl rootMetadataBuildingContext) {
if ( options.isXmlMappingEnabled() ) { if ( options.isXmlMappingEnabled() ) {
final Iterable<AdditionalJaxbMappingProducer> producers = classLoaderService.loadJavaServices( AdditionalJaxbMappingProducer.class ); final Iterable<AdditionalJaxbMappingProducer> producers = classLoaderService.loadJavaServices( AdditionalJaxbMappingProducer.class );
if ( producers != null ) { if ( producers != null ) {

View File

@ -21,9 +21,28 @@ import org.hibernate.mapping.Table;
*/ */
@Incubating @Incubating
public interface AdditionalMappingContributions { public interface AdditionalMappingContributions {
/**
* Contribute mappings in the form of {@code hbm.xml} JAXB bindings
*/
void contributeBinding(JaxbHbmHibernateMapping hbmJaxbBinding, Origin origin); void contributeBinding(JaxbHbmHibernateMapping hbmJaxbBinding, Origin origin);
/**
* Contribute a materialized PersistentClass
*/
void contributeEntity(PersistentClass entity); void contributeEntity(PersistentClass entity);
/**
* Contribute a materialized Table
*/
void contributeTable(Table table); void contributeTable(Table table);
/**
* Contribute a materialized Sequence
*/
void contributeSequence(Sequence sequence); void contributeSequence(Sequence sequence);
/**
* Contribute a materialized AuxiliaryDatabaseObject
*/
void contributeAuxiliaryDatabaseObject(AuxiliaryDatabaseObject auxiliaryDatabaseObject); void contributeAuxiliaryDatabaseObject(AuxiliaryDatabaseObject auxiliaryDatabaseObject);
} }

View File

@ -19,6 +19,9 @@ import org.hibernate.boot.jaxb.internal.MappingBinder;
*/ */
@Incubating @Incubating
public interface AdditionalMappingContributor { public interface AdditionalMappingContributor {
/**
* The name of this contributor.
*/
default String getContributorName() { default String getContributorName() {
return null; return null;
} }