HHH-15949 - Deprecate MetadataContributor

This commit is contained in:
Steve Ebersole 2023-01-20 16:42:14 -06:00
parent f310f80e33
commit b5022f94d3
3 changed files with 44 additions and 2 deletions

View File

@ -22,6 +22,8 @@ import org.hibernate.boot.MetadataBuilder;
* @author Vlad Mihalcea
*
* @since 5.3
*
* @deprecated Use
*/
public interface MetadataBuilderContributor {
/**

View File

@ -17,7 +17,11 @@ import org.jboss.jandex.IndexView;
* @author Steve Ebersole
*
* @since 5.0
*
* @deprecated Use {@link AdditionalMappingContributor} or {@link org.hibernate.boot.model.TypeContributor}
* instead depending on need
*/
@Deprecated(forRemoval = true)
public interface MetadataContributor {
/**
* Perform the contributions.

View File

@ -9,6 +9,8 @@ package org.hibernate.orm.test.mapping.converted.converter.custom;
import java.util.List;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.boot.model.TypeContributor;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.registry.StandardServiceRegistry;
@ -19,10 +21,12 @@ import org.hibernate.boot.spi.MetadataContributor;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.schema.Action;
import org.hibernate.type.spi.TypeConfiguration;
import org.hibernate.testing.boot.ExtraJavaServicesClassLoaderService;
import org.hibernate.testing.boot.ExtraJavaServicesClassLoaderService.JavaServiceDescriptor;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
@ -37,8 +41,8 @@ import static org.hamcrest.MatcherAssert.assertThat;
public class CustomTypeConverterTest extends BaseUnitTestCase {
@Test
public void testConverterAppliedScopedRegistration() {
final List<ExtraJavaServicesClassLoaderService.JavaServiceDescriptor<?>> services = List.of(
new ExtraJavaServicesClassLoaderService.JavaServiceDescriptor<>(
final List<JavaServiceDescriptor<?>> services = List.of(
new JavaServiceDescriptor<>(
MetadataContributor.class,
PayloadWrapperMetadataContributor.class
)
@ -85,6 +89,30 @@ public class CustomTypeConverterTest extends BaseUnitTestCase {
}
}
@Test
public void testConverterAppliedScopedContributions() {
final List<JavaServiceDescriptor<?>> services = List.of(
new JavaServiceDescriptor<>( TypeContributor.class, PayloadWrapperTypeContributorImpl.class )
);
final BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder().enableAutoClose()
.applyClassLoaderService( new ExtraJavaServicesClassLoaderService( services ) )
.build();
try ( final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr )
.applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP )
.build() ) {
final MetadataSources metadataSources = new MetadataSources( ssr )
.addAnnotatedClass( PayloadWrapperConverter.class )
.addAnnotatedClass( MyEntity.class );
final MetadataBuilderImplementor metadataBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder();
// now the new scoped way
final TypeConfiguration bootTypeConfiguration = metadataBuilder.getBootstrapContext().getTypeConfiguration();
performAssertions( metadataBuilder, bootTypeConfiguration );
}
}
public static class PayloadWrapperMetadataContributor implements MetadataContributor {
@Override
public void contribute(InFlightMetadataCollector metadataCollector, IndexView jandexIndex) {
@ -95,4 +123,12 @@ public class CustomTypeConverterTest extends BaseUnitTestCase {
.addDescriptor( PayloadWrapperJdbcType.INSTANCE );
}
}
public static class PayloadWrapperTypeContributorImpl implements TypeContributor {
@Override
public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
typeContributions.contributeJavaType( PayloadWrapperJavaType.INSTANCE );
typeContributions.contributeJdbcType( PayloadWrapperJdbcType.INSTANCE );
}
}
}