Search in sources :

Example 11 with BeanDescriptor

use of javax.validation.metadata.BeanDescriptor 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

BeanDescriptor (javax.validation.metadata.BeanDescriptor)11 PropertyDescriptor (javax.validation.metadata.PropertyDescriptor)5 HashSet (java.util.HashSet)3 ConstraintViolation (javax.validation.ConstraintViolation)3 MetaClass (com.haulmont.chile.core.model.MetaClass)2 KeyValueEntity (com.haulmont.cuba.core.entity.KeyValueEntity)2 BeanValidation (com.haulmont.cuba.core.global.BeanValidation)2 MetadataTools (com.haulmont.cuba.core.global.MetadataTools)2 BeanValidator (com.haulmont.cuba.gui.components.validators.BeanValidator)2 Method (java.lang.reflect.Method)2 ConstraintViolationException (javax.validation.ConstraintViolationException)2 MethodDescriptor (javax.validation.metadata.MethodDescriptor)2 MinijaxBeanDescriptor (org.minijax.validator.metadata.MinijaxBeanDescriptor)2 MinijaxPropertyDescriptor (org.minijax.validator.metadata.MinijaxPropertyDescriptor)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1 Response (javax.ws.rs.core.Response)1 Invocable (org.glassfish.jersey.server.model.Invocable)1 Component (org.hibernate.mapping.Component)1