Search in sources :

Example 11 with BasicType

use of org.hibernate.type.BasicType in project hibernate-orm by hibernate.

the class AttributeConverterTest method testBasicOrmXmlConverterApplication.

@Test
@TestForIssue(jiraKey = "HHH-8462")
public void testBasicOrmXmlConverterApplication() {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Tester.class).addURL(ConfigHelper.findAsResource("org/hibernate/test/converter/orm.xml")).getMetadataBuilder().build();
        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");
        }
        AttributeConverterTypeAdapter basicType = assertTyping(AttributeConverterTypeAdapter.class, type);
        assertSame(StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor());
        assertEquals(Types.CLOB, basicType.getSqlTypeDescriptor().getSqlType());
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : BasicType(org.hibernate.type.BasicType) AbstractStandardBasicType(org.hibernate.type.AbstractStandardBasicType) Type(org.hibernate.type.Type) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) AttributeConverterTypeAdapter(org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter) Property(org.hibernate.mapping.Property) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Example 12 with BasicType

use of org.hibernate.type.BasicType in project hibernate-orm by hibernate.

the class AttributeConverterTest method testBasicConverterDisableApplication.

@Test
public void testBasicConverterDisableApplication() {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Tester2.class).getMetadataBuilder().applyAttributeConverter(StringClobConverter.class, true).build();
        PersistentClass tester = metadata.getEntityBinding(Tester2.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 applied (should not have been)");
        }
        AbstractStandardBasicType basicType = assertTyping(AbstractStandardBasicType.class, type);
        assertSame(StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor());
        assertEquals(Types.VARCHAR, basicType.getSqlTypeDescriptor().getSqlType());
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : BasicType(org.hibernate.type.BasicType) AbstractStandardBasicType(org.hibernate.type.AbstractStandardBasicType) Type(org.hibernate.type.Type) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) Property(org.hibernate.mapping.Property) AbstractStandardBasicType(org.hibernate.type.AbstractStandardBasicType) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Example 13 with BasicType

use of org.hibernate.type.BasicType in project hibernate-orm by hibernate.

the class AttributeConverterTest method testBasicConverterApplication.

@Test
public void testBasicConverterApplication() {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Tester.class).getMetadataBuilder().applyAttributeConverter(StringClobConverter.class, true).build();
        PersistentClass tester = metadata.getEntityBinding(Tester.class.getName());
        Property nameProp = tester.getProperty("name");
        SimpleValue nameValue = (SimpleValue) nameProp.getValue();
        Type type = nameValue.getType();
        assertNotNull(type);
        assertTyping(BasicType.class, type);
        if (!AttributeConverterTypeAdapter.class.isInstance(type)) {
            fail("AttributeConverter not applied");
        }
        AbstractStandardBasicType basicType = assertTyping(AbstractStandardBasicType.class, type);
        assertSame(StringTypeDescriptor.INSTANCE, basicType.getJavaTypeDescriptor());
        assertEquals(Types.CLOB, basicType.getSqlTypeDescriptor().getSqlType());
    } finally {
        StandardServiceRegistryBuilder.destroy(ssr);
    }
}
Also used : BasicType(org.hibernate.type.BasicType) AbstractStandardBasicType(org.hibernate.type.AbstractStandardBasicType) Type(org.hibernate.type.Type) StandardServiceRegistryBuilder(org.hibernate.boot.registry.StandardServiceRegistryBuilder) MetadataSources(org.hibernate.boot.MetadataSources) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) AttributeConverterTypeAdapter(org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter) Property(org.hibernate.mapping.Property) AbstractStandardBasicType(org.hibernate.type.AbstractStandardBasicType) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Aggregations

BasicType (org.hibernate.type.BasicType)13 Test (org.junit.Test)10 SimpleValue (org.hibernate.mapping.SimpleValue)7 Type (org.hibernate.type.Type)6 MetadataSources (org.hibernate.boot.MetadataSources)5 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)5 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)5 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)5 PersistentClass (org.hibernate.mapping.PersistentClass)5 Property (org.hibernate.mapping.Property)5 AbstractStandardBasicType (org.hibernate.type.AbstractStandardBasicType)5 BasicTypeRegistry (org.hibernate.type.BasicTypeRegistry)4 AttributeConverterTypeAdapter (org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter)4 TestForIssue (org.hibernate.testing.TestForIssue)3 AbstractSingleColumnStandardBasicType (org.hibernate.type.AbstractSingleColumnStandardBasicType)3 Map (java.util.Map)2 SessionFactory (org.hibernate.SessionFactory)2 TypeContributor (org.hibernate.boot.model.TypeContributor)2 CustomType (org.hibernate.type.CustomType)2 HashMap (java.util.HashMap)1