use of org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry in project hibernate-orm by hibernate.
the class MapKeyJdbcTypeTests method verifyResolutions.
@Test
public void verifyResolutions(DomainModelScope scope) {
final MetadataImplementor domainModel = scope.getDomainModel();
final Dialect dialect = domainModel.getDatabase().getDialect();
final NationalizationSupport nationalizationSupport = dialect.getNationalizationSupport();
final JdbcTypeRegistry jdbcTypeRegistry = domainModel.getTypeConfiguration().getJdbcTypeRegistry();
final PersistentClass entityBinding = domainModel.getEntityBinding(MyEntity.class.getName());
verifyJdbcTypeCodes(entityBinding.getProperty("baseMap"), jdbcTypeRegistry.getDescriptor(Types.INTEGER).getJdbcTypeCode(), jdbcTypeRegistry.getDescriptor(Types.VARCHAR).getJdbcTypeCode());
verifyJdbcTypeCodes(entityBinding.getProperty("sqlTypeCodeMap"), jdbcTypeRegistry.getDescriptor(Types.TINYINT).getJdbcTypeCode(), jdbcTypeRegistry.getDescriptor(nationalizationSupport.getVarcharVariantCode()).getJdbcTypeCode());
verifyJdbcTypeCodes(entityBinding.getProperty("sqlTypeMap"), Types.TINYINT, jdbcTypeRegistry.getDescriptor(nationalizationSupport.getVarcharVariantCode()).getJdbcTypeCode());
}
use of org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry in project hibernate-orm by hibernate.
the class ListIndexJdbcTypeTests method verifyResolutions.
@Test
public void verifyResolutions(DomainModelScope scope) {
final MetadataImplementor domainModel = scope.getDomainModel();
final PersistentClass entityBinding = domainModel.getEntityBinding(TheEntity.class.getName());
final JdbcTypeRegistry jdbcTypeRegistry = domainModel.getTypeConfiguration().getJdbcTypeRegistry();
verifyJdbcTypeCodes(entityBinding.getProperty("listOfStrings"), Types.TINYINT);
verifyJdbcTypeCodes(entityBinding.getProperty("anotherListOfStrings"), jdbcTypeRegistry.getDescriptor(Types.TINYINT).getJdbcTypeCode());
}
use of org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry 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.spi.JdbcTypeRegistry in project hibernate-orm by hibernate.
the class AttributeConverterTest method testEnumConverter.
@Test
@TestForIssue(jiraKey = "HHH-8866")
public void testEnumConverter() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().applySetting(AvailableSettings.HBM2DDL_AUTO, "create-drop").build();
try {
MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(EntityWithConvertibleField.class).getMetadataBuilder().applyAttributeConverter(ConvertibleEnumConverter.class, true).build();
final JdbcTypeRegistry jdbcTypeRegistry = metadata.getTypeConfiguration().getJdbcTypeRegistry();
// first lets validate that the converter was applied...
final PersistentClass tester = metadata.getEntityBinding(EntityWithConvertibleField.class.getName());
final Property nameProp = tester.getProperty("convertibleEnum");
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(), instanceOf(EnumJavaType.class));
final int expectedJdbcTypeCode;
if (metadata.getDatabase().getDialect() instanceof HANAColumnStoreDialect && // Only for SAP HANA Cloud
metadata.getDatabase().getDialect().getVersion().isSameOrAfter(4)) {
expectedJdbcTypeCode = Types.NVARCHAR;
} else {
expectedJdbcTypeCode = Types.VARCHAR;
}
assertThat(typeAdapter.getJdbcType(), is(jdbcTypeRegistry.getDescriptor(expectedJdbcTypeCode)));
// then lets build the SF and verify its use...
final SessionFactory sf = metadata.buildSessionFactory();
try {
Session s = sf.openSession();
s.getTransaction().begin();
EntityWithConvertibleField entity = new EntityWithConvertibleField();
entity.setId("ID");
entity.setConvertibleEnum(ConvertibleEnum.VALUE);
String entityID = entity.getId();
s.persist(entity);
s.getTransaction().commit();
s.close();
s = sf.openSession();
s.beginTransaction();
entity = s.load(EntityWithConvertibleField.class, entityID);
assertEquals(ConvertibleEnum.VALUE, entity.getConvertibleEnum());
s.getTransaction().commit();
s.close();
s = sf.openSession();
s.beginTransaction();
s.createQuery("FROM EntityWithConvertibleField e where e.convertibleEnum = org.hibernate.orm.test.mapping.converted.converter.AttributeConverterTest$ConvertibleEnum.VALUE").list();
s.getTransaction().commit();
s.close();
s = sf.openSession();
s.beginTransaction();
s.delete(entity);
s.getTransaction().commit();
s.close();
} finally {
try {
sf.close();
} catch (Exception ignore) {
}
}
} finally {
StandardServiceRegistryBuilder.destroy(ssr);
}
}
use of org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry 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)));
}
}
Aggregations