Search in sources :

Example 1 with TypeConfiguration

use of org.hibernate.type.spi.TypeConfiguration in project hibernate-orm by hibernate.

the class CustomTypeConverterTest method testConverterAppliedScopedRegistration.

@Test
public void testConverterAppliedScopedRegistration() {
    try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).build()) {
        final MetadataSources metadataSources = new MetadataSources(ssr).addAnnotatedClass(MyCustomConverter.class).addAnnotatedClass(MyEntity.class);
        final MetadataBuilderImplementor metadataBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder();
        // now the new scoped way
        final TypeConfiguration bootTypeConfiguration = metadataBuilder.getBootstrapContext().getTypeConfiguration();
        bootTypeConfiguration.getJavaTypeDescriptorRegistry().addDescriptor(MyCustomJavaTypeDescriptor.INSTANCE);
        bootTypeConfiguration.getSqlTypeDescriptorRegistry().addDescriptor(MyCustomSqlTypeDescriptor.INSTANCE);
        performAssertions(metadataBuilder, bootTypeConfiguration);
    }
}
Also used : MetadataBuilderImplementor(org.hibernate.boot.spi.MetadataBuilderImplementor) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) TypeConfiguration(org.hibernate.type.spi.TypeConfiguration) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 2 with TypeConfiguration

use of org.hibernate.type.spi.TypeConfiguration in project hibernate-orm by hibernate.

the class CustomTypeConverterTest method testConverterAppliedStaticRegistration.

@Test
public void testConverterAppliedStaticRegistration() {
    // this is how we told users to do it previously using the static reference -
    // make sure it still works for now
    org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry.INSTANCE.addDescriptor(MyCustomJavaTypeDescriptor.INSTANCE);
    org.hibernate.type.descriptor.sql.SqlTypeDescriptorRegistry.INSTANCE.addDescriptor(MyCustomSqlTypeDescriptor.INSTANCE);
    try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).build()) {
        final MetadataSources metadataSources = new MetadataSources(ssr).addAnnotatedClass(MyCustomConverter.class).addAnnotatedClass(MyEntity.class);
        final MetadataBuilderImplementor metadataBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder();
        final TypeConfiguration bootTypeConfiguration = metadataBuilder.getBootstrapContext().getTypeConfiguration();
        performAssertions(metadataBuilder, bootTypeConfiguration);
    }
}
Also used : MetadataBuilderImplementor(org.hibernate.boot.spi.MetadataBuilderImplementor) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) TypeConfiguration(org.hibernate.type.spi.TypeConfiguration) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 3 with TypeConfiguration

use of org.hibernate.type.spi.TypeConfiguration in project hibernate-orm by hibernate.

the class GeometryConverterTest method testConverterUsage.

@Test
public void testConverterUsage() {
    try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.DIALECT, GeoDBDialect.class).applySetting(AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP).build()) {
        final MetadataSources metadataSources = new MetadataSources(ssr).addAnnotatedClass(GeometryConverter.class).addAnnotatedClass(MyEntity.class);
        final MetadataBuilderImplementor metadataBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder();
        try (final SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) metadataBuilder.build().buildSessionFactory()) {
            final TypeConfiguration typeConfiguration = sessionFactory.getMetamodel().getTypeConfiguration();
            assertThat(typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor(Geometry.class), sameInstance(GeolatteGeometryJavaTypeDescriptor.INSTANCE));
            // todo (5.3) : what to assert wrt to SqlTypeDescriptor?  Anything?
            final EntityPersister entityPersister = sessionFactory.getMetamodel().entityPersister(MyEntity.class);
            final AttributeConverterTypeAdapter geometryAttributeType = assertTyping(AttributeConverterTypeAdapter.class, entityPersister.getPropertyType("geometry"));
            final JpaAttributeConverter converter = assertTyping(JpaAttributeConverter.class, geometryAttributeType.getAttributeConverter());
            assert GeometryConverter.class.equals(converter.getConverterBean().getBeanClass());
        }
    }
}
Also used : MetadataBuilderImplementor(org.hibernate.boot.spi.MetadataBuilderImplementor) Geometry(org.geolatte.geom.Geometry) EntityPersister(org.hibernate.persister.entity.EntityPersister) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) JpaAttributeConverter(org.hibernate.metamodel.model.convert.spi.JpaAttributeConverter) MetadataSources(org.hibernate.boot.MetadataSources) AttributeConverterTypeAdapter(org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter) TypeConfiguration(org.hibernate.type.spi.TypeConfiguration) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) Test(org.junit.Test)

Example 4 with TypeConfiguration

use of org.hibernate.type.spi.TypeConfiguration in project hibernate-orm by hibernate.

the class JavaTypeDescriptorRegistryTest method testGetJavaTypeDescriptorRegistry.

@Test
public void testGetJavaTypeDescriptorRegistry() {
    TypeConfiguration typeConfiguration = new TypeConfiguration();
    JavaTypeDescriptor<String> descriptor = typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor(String.class);
    assertThat(descriptor, instanceOf(StringTypeDescriptor.class));
}
Also used : StringTypeDescriptor(org.hibernate.type.descriptor.java.StringTypeDescriptor) TypeConfiguration(org.hibernate.type.spi.TypeConfiguration) Test(org.junit.Test)

Example 5 with TypeConfiguration

use of org.hibernate.type.spi.TypeConfiguration in project hibernate-orm by hibernate.

the class JavaTypeDescriptorRegistryTest method testRegisterJavaTypeDescriptorRegistry.

@Test
public void testRegisterJavaTypeDescriptorRegistry() {
    TypeConfiguration typeConfiguration = new TypeConfiguration();
    typeConfiguration.getJavaTypeDescriptorRegistry().addDescriptor(new CustomJavaTypeDescriptor());
    JavaTypeDescriptor descriptor = typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor(CustomType.class);
    assertThat(descriptor, instanceOf(CustomJavaTypeDescriptor.class));
}
Also used : TypeConfiguration(org.hibernate.type.spi.TypeConfiguration) JavaTypeDescriptor(org.hibernate.type.descriptor.java.JavaTypeDescriptor) Test(org.junit.Test)

Aggregations

TypeConfiguration (org.hibernate.type.spi.TypeConfiguration)7 Test (org.junit.Test)7 MetadataSources (org.hibernate.boot.MetadataSources)3 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)3 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)3 MetadataBuilderImplementor (org.hibernate.boot.spi.MetadataBuilderImplementor)3 JavaTypeDescriptor (org.hibernate.type.descriptor.java.JavaTypeDescriptor)2 Geometry (org.geolatte.geom.Geometry)1 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)1 JpaAttributeConverter (org.hibernate.metamodel.model.convert.spi.JpaAttributeConverter)1 EntityPersister (org.hibernate.persister.entity.EntityPersister)1 BasicType (org.hibernate.type.BasicType)1 AttributeConverterTypeAdapter (org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter)1 StringTypeDescriptor (org.hibernate.type.descriptor.java.StringTypeDescriptor)1