Search in sources :

Example 76 with Property

use of org.hibernate.mapping.Property 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)

Example 77 with Property

use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.

the class AttributeConverterTest method testNonAutoApplyHandling.

@Test
public void testNonAutoApplyHandling() {
    final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
    try {
        MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(ssr).addAnnotatedClass(Tester.class).getMetadataBuilder().applyAttributeConverter(NotAutoAppliedConverter.class, false).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 with autoApply=false was auto applied");
        }
    } 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) StandardServiceRegistry(org.hibernate.boot.registry.StandardServiceRegistry) PersistentClass(org.hibernate.mapping.PersistentClass) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test)

Example 78 with Property

use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.

the class MetadataImpl method getReferencedPropertyType.

@Override
public org.hibernate.type.Type getReferencedPropertyType(String entityName, String propertyName) throws MappingException {
    final PersistentClass pc = entityBindingMap.get(entityName);
    if (pc == null) {
        throw new MappingException("persistent class not known: " + entityName);
    }
    Property prop = pc.getReferencedProperty(propertyName);
    if (prop == null) {
        throw new MappingException("property not known: " + entityName + '.' + propertyName);
    }
    return prop.getType();
}
Also used : Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass) MappingException(org.hibernate.MappingException)

Example 79 with Property

use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.

the class InFlightMetadataCollectorImpl method getReferencedPropertyType.

@Override
public org.hibernate.type.Type getReferencedPropertyType(String entityName, String propertyName) throws MappingException {
    final PersistentClass pc = entityBindingMap.get(entityName);
    if (pc == null) {
        throw new MappingException("persistent class not known: " + entityName);
    }
    Property prop = pc.getReferencedProperty(propertyName);
    if (prop == null) {
        throw new MappingException("property not known: " + entityName + '.' + propertyName);
    }
    return prop.getType();
}
Also used : Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass) DuplicateMappingException(org.hibernate.DuplicateMappingException) MappingException(org.hibernate.MappingException)

Example 80 with Property

use of org.hibernate.mapping.Property in project hibernate-orm by hibernate.

the class TypeSafeActivator method applyDDL.

private static void applyDDL(String prefix, PersistentClass persistentClass, Class<?> clazz, ValidatorFactory factory, Set<Class<?>> groups, boolean activateNotNull, Dialect dialect) {
    final BeanDescriptor descriptor = factory.getValidator().getConstraintsForClass(clazz);
    for (PropertyDescriptor propertyDesc : descriptor.getConstrainedProperties()) {
        Property property = findPropertyByName(persistentClass, prefix + propertyDesc.getPropertyName());
        boolean hasNotNull;
        if (property != null) {
            hasNotNull = applyConstraints(propertyDesc.getConstraintDescriptors(), property, propertyDesc, groups, activateNotNull, dialect);
            if (property.isComposite() && propertyDesc.isCascaded()) {
                Class<?> componentClass = ((Component) property.getValue()).getComponentClass();
                /*
					 * we can apply not null if the upper component let's us activate not null
					 * and if the property is not null.
					 * Otherwise, all sub columns should be left nullable
					 */
                final boolean canSetNotNullOnColumns = activateNotNull && hasNotNull;
                applyDDL(prefix + propertyDesc.getPropertyName() + ".", persistentClass, componentClass, factory, groups, canSetNotNullOnColumns, dialect);
            }
        //FIXME add collection of components
        }
    }
}
Also used : PropertyDescriptor(javax.validation.metadata.PropertyDescriptor) BeanDescriptor(javax.validation.metadata.BeanDescriptor) Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property)

Aggregations

Property (org.hibernate.mapping.Property)94 PersistentClass (org.hibernate.mapping.PersistentClass)53 Component (org.hibernate.mapping.Component)30 Test (org.junit.Test)29 SimpleValue (org.hibernate.mapping.SimpleValue)24 Iterator (java.util.Iterator)23 SyntheticProperty (org.hibernate.mapping.SyntheticProperty)18 MetadataSources (org.hibernate.boot.MetadataSources)17 Column (org.hibernate.mapping.Column)17 AnnotationException (org.hibernate.AnnotationException)14 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)14 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)14 XProperty (org.hibernate.annotations.common.reflection.XProperty)12 Metadata (org.hibernate.boot.Metadata)11 Collection (org.hibernate.mapping.Collection)11 HashMap (java.util.HashMap)10 AssertionFailure (org.hibernate.AssertionFailure)10 MappingException (org.hibernate.MappingException)9 TestForIssue (org.hibernate.testing.TestForIssue)9 Map (java.util.Map)7