|
| 1 | +package org.hibernate.orm.test.type.contributor.usertype; |
| 2 | + |
| 3 | +import org.hibernate.boot.model.TypeContributions; |
| 4 | +import org.hibernate.boot.model.TypeContributor; |
| 5 | +import org.hibernate.service.ServiceRegistry; |
| 6 | + |
| 7 | +import org.hibernate.testing.orm.junit.BootstrapServiceRegistry; |
| 8 | +import org.hibernate.testing.orm.junit.DomainModel; |
| 9 | +import org.hibernate.testing.orm.junit.Jira; |
| 10 | +import org.hibernate.testing.orm.junit.SessionFactory; |
| 11 | +import org.hibernate.testing.orm.junit.SessionFactoryScope; |
| 12 | + |
| 13 | +import org.hibernate.type.descriptor.jdbc.VarcharJdbcType; |
| 14 | +import org.hibernate.type.spi.TypeConfiguration; |
| 15 | + |
| 16 | +import org.junit.jupiter.api.Assertions; |
| 17 | +import org.junit.jupiter.api.Test; |
| 18 | + |
| 19 | +/** |
| 20 | + * Test to assert that service loaded types are processed in ascending ordinal order |
| 21 | + * |
| 22 | + * @author Steven Barendregt |
| 23 | + */ |
| 24 | +@DomainModel |
| 25 | +@SessionFactory |
| 26 | +@BootstrapServiceRegistry( |
| 27 | + javaServices = { |
| 28 | + @BootstrapServiceRegistry.JavaService(role = TypeContributor.class, impl = TypeContributionOrdinalTest.HigherOrdinalServiceLoadedVarcharTypeContributor.class), |
| 29 | + @BootstrapServiceRegistry.JavaService(role = TypeContributor.class, impl = TypeContributionOrdinalTest.ServiceLoadedVarcharTypeContributor.class) |
| 30 | + } |
| 31 | +) |
| 32 | +public class TypeContributionOrdinalTest { |
| 33 | + |
| 34 | + @Test |
| 35 | + @Jira(value = "https://hibernate.atlassian.net/issues/HHH-19247") |
| 36 | + public void testHigherOrdinalServiceLoadedCustomUserTypeTakesPrecedence(SessionFactoryScope scope) { |
| 37 | + final TypeConfiguration typeConfigurations = scope.getSessionFactory() |
| 38 | + .getMappingMetamodel() |
| 39 | + .getTypeConfiguration(); |
| 40 | + Assertions.assertInstanceOf( |
| 41 | + HigherOrdinalServiceLoadedVarcharTypeContributor.HigherOrdinalExtendedVarcharJdbcType.class, |
| 42 | + typeConfigurations.getJdbcTypeRegistry().findDescriptor( 12 ) |
| 43 | + ); |
| 44 | + } |
| 45 | + |
| 46 | + public static class ServiceLoadedVarcharTypeContributor implements TypeContributor { |
| 47 | + |
| 48 | + @Override |
| 49 | + public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { |
| 50 | + typeContributions.contributeJdbcType( ExtendedVarcharJdbcType.INSTANCE ); |
| 51 | + } |
| 52 | + |
| 53 | + public static class ExtendedVarcharJdbcType extends VarcharJdbcType { |
| 54 | + |
| 55 | + public static final ExtendedVarcharJdbcType INSTANCE = new ExtendedVarcharJdbcType(); |
| 56 | + } |
| 57 | + |
| 58 | + } |
| 59 | + |
| 60 | + public static class HigherOrdinalServiceLoadedVarcharTypeContributor implements TypeContributor { |
| 61 | + |
| 62 | + @Override |
| 63 | + public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) { |
| 64 | + typeContributions.contributeJdbcType( HigherOrdinalExtendedVarcharJdbcType.INSTANCE ); |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public int ordinal() { |
| 69 | + return 2000; |
| 70 | + } |
| 71 | + |
| 72 | + public static class HigherOrdinalExtendedVarcharJdbcType extends VarcharJdbcType { |
| 73 | + |
| 74 | + public static final HigherOrdinalExtendedVarcharJdbcType INSTANCE = new HigherOrdinalExtendedVarcharJdbcType(); |
| 75 | + } |
| 76 | + } |
| 77 | +} |
0 commit comments