use of org.hibernate.type.descriptor.jdbc.JdbcType in project hibernate-orm by hibernate.
the class AttributeConverterTest method testBasicOrmXmlConverterWithOrmXmlPackage.
@Test
@TestForIssue(jiraKey = "HHH-14881")
public void testBasicOrmXmlConverterWithOrmXmlPackage() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Tester.class).addURL(ConfigHelper.findAsResource("org/hibernate/test/converter/package.xml")).getMetadataBuilder().build();
final JdbcTypeRegistry jdbcTypeRegistry = metadata.getTypeConfiguration().getJdbcTypeRegistry();
PersistentClass tester = metadata.getEntityBinding(Tester.class.getName());
Property nameProp = tester.getProperty("name");
SimpleValue nameValue = (SimpleValue) nameProp.getValue();
Type type = nameValue.getType();
assertNotNull(type);
if (!AttributeConverterTypeAdapter.class.isInstance(type)) {
fail("AttributeConverter not applied");
}
final AttributeConverterTypeAdapter typeAdapter = (AttributeConverterTypeAdapter) type;
assertThat(typeAdapter.getDomainJtd().getJavaTypeClass(), equalTo(String.class));
assertThat(typeAdapter.getRelationalJtd().getJavaTypeClass(), equalTo(Clob.class));
final JdbcType sqlTypeDescriptor = typeAdapter.getJdbcType();
assertThat(sqlTypeDescriptor, is(jdbcTypeRegistry.getDescriptor(Types.CLOB)));
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.type.descriptor.jdbc.JdbcType in project hibernate-orm by hibernate.
the class AttributeConverterTest method testBasicOperation.
@Test
public void testBasicOperation() {
try (StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().build()) {
final MetadataBuildingContext buildingContext = new MetadataBuildingContextTestingImpl(serviceRegistry);
final JdbcTypeRegistry jdbcTypeRegistry = buildingContext.getBootstrapContext().getTypeConfiguration().getJdbcTypeRegistry();
final BasicValue basicValue = new BasicValue(buildingContext);
basicValue.setJpaAttributeConverterDescriptor(new InstanceBasedConverterDescriptor(new StringClobConverter(), new ClassmateContext()));
basicValue.setTypeUsingReflection(IrrelevantEntity.class.getName(), "name");
final Type type = basicValue.getType();
assertNotNull(type);
assertThat(type, instanceOf(AttributeConverterTypeAdapter.class));
final AttributeConverterTypeAdapter typeAdapter = (AttributeConverterTypeAdapter) type;
assertThat(typeAdapter.getDomainJtd().getJavaTypeClass(), equalTo(String.class));
final JdbcType jdbcType = typeAdapter.getJdbcType();
assertThat(jdbcType, is(jdbcTypeRegistry.getDescriptor(Types.CLOB)));
}
}
use of org.hibernate.type.descriptor.jdbc.JdbcType in project hibernate-orm by hibernate.
the class AttributeConverterTest method testBasicConverterApplication.
@Test
public void testBasicConverterApplication() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Tester.class).getMetadataBuilder().applyAttributeConverter(StringClobConverter.class, true).build();
final JdbcTypeRegistry jdbcTypeRegistry = metadata.getTypeConfiguration().getJdbcTypeRegistry();
final PersistentClass tester = metadata.getEntityBinding(Tester.class.getName());
final Property nameProp = tester.getProperty("name");
final BasicValue nameValue = (BasicValue) nameProp.getValue();
final Type type = nameValue.getType();
assertNotNull(type);
assertThat(type, instanceOf(AttributeConverterTypeAdapter.class));
final AttributeConverterTypeAdapter typeAdapter = (AttributeConverterTypeAdapter) type;
assertThat(typeAdapter.getDomainJtd().getJavaTypeClass(), Matchers.equalTo(String.class));
final JdbcType jdbcType = typeAdapter.getJdbcType();
assertThat(jdbcType, is(jdbcTypeRegistry.getDescriptor(Types.CLOB)));
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.type.descriptor.jdbc.JdbcType in project hibernate-orm by hibernate.
the class AnnotationBinder method handleJdbcTypeRegistration.
private static void handleJdbcTypeRegistration(MetadataBuildingContext context, ManagedBeanRegistry managedBeanRegistry, JdbcTypeRegistration annotation) {
final Class<? extends JdbcType> jdbcTypeClass = annotation.value();
final JdbcType jdbcType = managedBeanRegistry.getBean(jdbcTypeClass).getBeanInstance();
final int typeCode = annotation.registrationCode() == Integer.MIN_VALUE ? jdbcType.getJdbcTypeCode() : annotation.registrationCode();
context.getMetadataCollector().addJdbcTypeRegistration(typeCode, jdbcType);
}
use of org.hibernate.type.descriptor.jdbc.JdbcType in project hibernate-orm by hibernate.
the class AnnotationBinder method resolveJavaType.
private static JdbcMapping resolveJavaType(Class<JavaType<?>> type, MetadataBuildingContext context) {
final TypeConfiguration typeConfiguration = context.getBootstrapContext().getTypeConfiguration();
final JavaTypeRegistry javaTypeRegistry = typeConfiguration.getJavaTypeRegistry();
final JavaType<?> registeredJtd = javaTypeRegistry.findDescriptor(type);
final JavaType<?> jtd;
if (registeredJtd != null) {
jtd = registeredJtd;
} else {
final StandardServiceRegistry serviceRegistry = context.getBootstrapContext().getServiceRegistry();
final ManagedBeanRegistry beanRegistry = serviceRegistry.getService(ManagedBeanRegistry.class);
final ManagedBean<JavaType<?>> bean = beanRegistry.getBean(type);
jtd = bean.getBeanInstance();
}
final JdbcType jdbcType = jtd.getRecommendedJdbcType(typeConfiguration.getCurrentBaseSqlTypeIndicators());
return typeConfiguration.getBasicTypeRegistry().resolve(jtd, jdbcType);
}
Aggregations