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);
}
}
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);
}
}
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());
}
}
}
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));
}
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));
}
Aggregations