Search in sources :

Example 1 with NationalizationSupport

use of org.hibernate.dialect.NationalizationSupport 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());
}
Also used : SkipForDialect(org.hibernate.testing.orm.junit.SkipForDialect) Dialect(org.hibernate.dialect.Dialect) SybaseDialect(org.hibernate.dialect.SybaseDialect) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) NationalizationSupport(org.hibernate.dialect.NationalizationSupport) JdbcTypeRegistry(org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.jupiter.api.Test)

Example 2 with NationalizationSupport

use of org.hibernate.dialect.NationalizationSupport in project hibernate-orm by hibernate.

the class StringNationalizedMappingTests method testMappings.

@Test
public void testMappings(SessionFactoryScope scope) {
    // first, verify the type selections...
    final MappingMetamodelImplementor mappingMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
    final EntityPersister entityDescriptor = mappingMetamodel.findEntityDescriptor(EntityOfStrings.class);
    final JdbcTypeRegistry jdbcTypeRegistry = mappingMetamodel.getTypeConfiguration().getJdbcTypeRegistry();
    final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
    final NationalizationSupport nationalizationSupport = dialect.getNationalizationSupport();
    {
        final BasicAttributeMapping attribute = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("nstring");
        final JdbcMapping jdbcMapping = attribute.getJdbcMapping();
        assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(String.class));
        assertThat(jdbcMapping.getJdbcType(), is(jdbcTypeRegistry.getDescriptor(nationalizationSupport.getVarcharVariantCode())));
    }
    {
        final BasicAttributeMapping attribute = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("nclobString");
        final JdbcMapping jdbcMapping = attribute.getJdbcMapping();
        assertThat(jdbcMapping.getJavaTypeDescriptor().getJavaTypeClass(), equalTo(String.class));
        assertThat(jdbcMapping.getJdbcType(), is(jdbcTypeRegistry.getDescriptor(nationalizationSupport.getClobVariantCode())));
    }
    // and try to use the mapping
    scope.inTransaction((session) -> session.persist(new EntityOfStrings(1, "nstring", "nclob")));
    scope.inTransaction((session) -> session.get(EntityOfStrings.class, 1));
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) BasicAttributeMapping(org.hibernate.metamodel.mapping.internal.BasicAttributeMapping) Dialect(org.hibernate.dialect.Dialect) MappingMetamodelImplementor(org.hibernate.metamodel.spi.MappingMetamodelImplementor) NationalizationSupport(org.hibernate.dialect.NationalizationSupport) JdbcTypeRegistry(org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry) Test(org.junit.jupiter.api.Test)

Example 3 with NationalizationSupport

use of org.hibernate.dialect.NationalizationSupport in project hibernate-orm by hibernate.

the class CharacterArrayNationalizedMappingTests method verifyMappings.

@Test
public void verifyMappings(SessionFactoryScope scope) {
    final MappingMetamodelImplementor mappingMetamodel = scope.getSessionFactory().getRuntimeMetamodels().getMappingMetamodel();
    final EntityPersister entityDescriptor = mappingMetamodel.getEntityDescriptor(EntityWithCharArrays.class);
    final JdbcTypeRegistry jdbcTypeRegistry = mappingMetamodel.getTypeConfiguration().getJdbcTypeRegistry();
    final Dialect dialect = scope.getSessionFactory().getJdbcServices().getDialect();
    final NationalizationSupport nationalizationSupport = dialect.getNationalizationSupport();
    {
        final BasicAttributeMapping attributeMapping = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("primitiveNVarchar");
        final JdbcMapping jdbcMapping = attributeMapping.getJdbcMapping();
        assertThat(jdbcMapping.getJdbcType(), is(jdbcTypeRegistry.getDescriptor(nationalizationSupport.getVarcharVariantCode())));
    }
    {
        final BasicAttributeMapping attributeMapping = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("wrapperNVarchar");
        final JdbcMapping jdbcMapping = attributeMapping.getJdbcMapping();
        assertThat(jdbcMapping.getJdbcType(), is(jdbcTypeRegistry.getDescriptor(nationalizationSupport.getVarcharVariantCode())));
    }
    {
        final BasicAttributeMapping attributeMapping = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("primitiveNClob");
        final JdbcMapping jdbcMapping = attributeMapping.getJdbcMapping();
        assertThat(jdbcMapping.getJdbcType(), is(jdbcTypeRegistry.getDescriptor(nationalizationSupport.getClobVariantCode())));
    }
    {
        final BasicAttributeMapping attributeMapping = (BasicAttributeMapping) entityDescriptor.findAttributeMapping("wrapperNClob");
        final JdbcMapping jdbcMapping = attributeMapping.getJdbcMapping();
        assertThat(jdbcMapping.getJdbcType(), is(jdbcTypeRegistry.getDescriptor(nationalizationSupport.getClobVariantCode())));
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) JdbcMapping(org.hibernate.metamodel.mapping.JdbcMapping) BasicAttributeMapping(org.hibernate.metamodel.mapping.internal.BasicAttributeMapping) Dialect(org.hibernate.dialect.Dialect) MappingMetamodelImplementor(org.hibernate.metamodel.spi.MappingMetamodelImplementor) NationalizationSupport(org.hibernate.dialect.NationalizationSupport) JdbcTypeRegistry(org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry) Test(org.junit.jupiter.api.Test)

Example 4 with NationalizationSupport

use of org.hibernate.dialect.NationalizationSupport in project hibernate-orm by hibernate.

the class JdbcTypeTests 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(SimpleEntity.class.getName());
    verifyJdbcTypeCode(entityBinding.getProperty("materializedClob"), jdbcTypeRegistry.getDescriptor(Types.CLOB).getJdbcTypeCode());
    verifyJdbcTypeCode(entityBinding.getProperty("materializedNClob"), jdbcTypeRegistry.getDescriptor(nationalizationSupport.getClobVariantCode()).getJdbcTypeCode());
    verifyJdbcTypeCode(entityBinding.getProperty("jpaMaterializedClob"), jdbcTypeRegistry.getDescriptor(Types.CLOB).getJdbcTypeCode());
    verifyJdbcTypeCode(entityBinding.getProperty("jpaMaterializedNClob"), jdbcTypeRegistry.getDescriptor(nationalizationSupport.getClobVariantCode()).getJdbcTypeCode());
    verifyJdbcTypeCode(entityBinding.getProperty("nationalizedString"), jdbcTypeRegistry.getDescriptor(nationalizationSupport.getVarcharVariantCode()).getJdbcTypeCode());
    verifyJdbcTypeCode(entityBinding.getProperty("nationalizedClob"), jdbcTypeRegistry.getDescriptor(nationalizationSupport.getClobVariantCode()).getJdbcTypeCode());
    verifyResolution(entityBinding.getProperty("customType"), CustomJdbcType.class);
    verifyResolution(entityBinding.getProperty("customTypeRegistration"), RegisteredCustomJdbcType.class);
}
Also used : Dialect(org.hibernate.dialect.Dialect) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) NationalizationSupport(org.hibernate.dialect.NationalizationSupport) JdbcTypeRegistry(org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.jupiter.api.Test)

Aggregations

Dialect (org.hibernate.dialect.Dialect)4 NationalizationSupport (org.hibernate.dialect.NationalizationSupport)4 JdbcTypeRegistry (org.hibernate.type.descriptor.jdbc.spi.JdbcTypeRegistry)4 Test (org.junit.jupiter.api.Test)4 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)2 PersistentClass (org.hibernate.mapping.PersistentClass)2 JdbcMapping (org.hibernate.metamodel.mapping.JdbcMapping)2 BasicAttributeMapping (org.hibernate.metamodel.mapping.internal.BasicAttributeMapping)2 MappingMetamodelImplementor (org.hibernate.metamodel.spi.MappingMetamodelImplementor)2 EntityPersister (org.hibernate.persister.entity.EntityPersister)2 SybaseDialect (org.hibernate.dialect.SybaseDialect)1 SkipForDialect (org.hibernate.testing.orm.junit.SkipForDialect)1