HHH-15949 - Deprecate MetadataContributor
This commit is contained in:
parent
f310f80e33
commit
b5022f94d3
|
@ -22,6 +22,8 @@ import org.hibernate.boot.MetadataBuilder;
|
||||||
* @author Vlad Mihalcea
|
* @author Vlad Mihalcea
|
||||||
*
|
*
|
||||||
* @since 5.3
|
* @since 5.3
|
||||||
|
*
|
||||||
|
* @deprecated Use
|
||||||
*/
|
*/
|
||||||
public interface MetadataBuilderContributor {
|
public interface MetadataBuilderContributor {
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -17,7 +17,11 @@ import org.jboss.jandex.IndexView;
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*
|
*
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
|
*
|
||||||
|
* @deprecated Use {@link AdditionalMappingContributor} or {@link org.hibernate.boot.model.TypeContributor}
|
||||||
|
* instead depending on need
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(forRemoval = true)
|
||||||
public interface MetadataContributor {
|
public interface MetadataContributor {
|
||||||
/**
|
/**
|
||||||
* Perform the contributions.
|
* Perform the contributions.
|
||||||
|
|
|
@ -9,6 +9,8 @@ package org.hibernate.orm.test.mapping.converted.converter.custom;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.boot.MetadataSources;
|
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.BootstrapServiceRegistry;
|
||||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||||
|
@ -19,10 +21,12 @@ import org.hibernate.boot.spi.MetadataContributor;
|
||||||
import org.hibernate.cfg.AvailableSettings;
|
import org.hibernate.cfg.AvailableSettings;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
import org.hibernate.persister.entity.EntityPersister;
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
import org.hibernate.service.ServiceRegistry;
|
||||||
import org.hibernate.tool.schema.Action;
|
import org.hibernate.tool.schema.Action;
|
||||||
import org.hibernate.type.spi.TypeConfiguration;
|
import org.hibernate.type.spi.TypeConfiguration;
|
||||||
|
|
||||||
import org.hibernate.testing.boot.ExtraJavaServicesClassLoaderService;
|
import org.hibernate.testing.boot.ExtraJavaServicesClassLoaderService;
|
||||||
|
import org.hibernate.testing.boot.ExtraJavaServicesClassLoaderService.JavaServiceDescriptor;
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
@ -37,8 +41,8 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
public class CustomTypeConverterTest extends BaseUnitTestCase {
|
public class CustomTypeConverterTest extends BaseUnitTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testConverterAppliedScopedRegistration() {
|
public void testConverterAppliedScopedRegistration() {
|
||||||
final List<ExtraJavaServicesClassLoaderService.JavaServiceDescriptor<?>> services = List.of(
|
final List<JavaServiceDescriptor<?>> services = List.of(
|
||||||
new ExtraJavaServicesClassLoaderService.JavaServiceDescriptor<>(
|
new JavaServiceDescriptor<>(
|
||||||
MetadataContributor.class,
|
MetadataContributor.class,
|
||||||
PayloadWrapperMetadataContributor.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 {
|
public static class PayloadWrapperMetadataContributor implements MetadataContributor {
|
||||||
@Override
|
@Override
|
||||||
public void contribute(InFlightMetadataCollector metadataCollector, IndexView jandexIndex) {
|
public void contribute(InFlightMetadataCollector metadataCollector, IndexView jandexIndex) {
|
||||||
|
@ -95,4 +123,12 @@ public class CustomTypeConverterTest extends BaseUnitTestCase {
|
||||||
.addDescriptor( PayloadWrapperJdbcType.INSTANCE );
|
.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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue