Search in sources :

Example 6 with ConstraintDescriptor

use of javax.validation.metadata.ConstraintDescriptor in project hibernate-orm by hibernate.

the class TypeSafeActivator method applyMin.

private static void applyMin(Property property, ConstraintDescriptor<?> descriptor, Dialect dialect) {
    if (Min.class.equals(descriptor.getAnnotation().annotationType())) {
        @SuppressWarnings("unchecked") ConstraintDescriptor<Min> minConstraint = (ConstraintDescriptor<Min>) descriptor;
        long min = minConstraint.getAnnotation().value();
        @SuppressWarnings("unchecked") final Iterator<Selectable> itor = property.getColumnIterator();
        if (itor.hasNext()) {
            final Selectable selectable = itor.next();
            if (Column.class.isInstance(selectable)) {
                Column col = (Column) selectable;
                String checkConstraint = col.getQuotedName(dialect) + ">=" + min;
                applySQLCheck(col, checkConstraint);
            }
        }
    }
}
Also used : Min(javax.validation.constraints.Min) Selectable(org.hibernate.mapping.Selectable) Column(org.hibernate.mapping.Column) ConstraintDescriptor(javax.validation.metadata.ConstraintDescriptor)

Example 7 with ConstraintDescriptor

use of javax.validation.metadata.ConstraintDescriptor in project hibernate-orm by hibernate.

the class TypeSafeActivator method applyMax.

private static void applyMax(Property property, ConstraintDescriptor<?> descriptor, Dialect dialect) {
    if (Max.class.equals(descriptor.getAnnotation().annotationType())) {
        @SuppressWarnings("unchecked") ConstraintDescriptor<Max> maxConstraint = (ConstraintDescriptor<Max>) descriptor;
        long max = maxConstraint.getAnnotation().value();
        @SuppressWarnings("unchecked") final Iterator<Selectable> itor = property.getColumnIterator();
        if (itor.hasNext()) {
            final Selectable selectable = itor.next();
            if (Column.class.isInstance(selectable)) {
                Column col = (Column) selectable;
                String checkConstraint = col.getQuotedName(dialect) + "<=" + max;
                applySQLCheck(col, checkConstraint);
            }
        }
    }
}
Also used : Max(javax.validation.constraints.Max) Selectable(org.hibernate.mapping.Selectable) Column(org.hibernate.mapping.Column) ConstraintDescriptor(javax.validation.metadata.ConstraintDescriptor)

Aggregations

ConstraintDescriptor (javax.validation.metadata.ConstraintDescriptor)7 Column (org.hibernate.mapping.Column)4 Selectable (org.hibernate.mapping.Selectable)4 Annotation (java.lang.annotation.Annotation)2 Validator (javax.validation.Validator)2 IValidator (org.apache.wicket.validation.IValidator)2 AnnotatedType (java.lang.reflect.AnnotatedType)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Digits (javax.validation.constraints.Digits)1 Max (javax.validation.constraints.Max)1 Min (javax.validation.constraints.Min)1 Size (javax.validation.constraints.Size)1 ContainerElementTypeDescriptor (javax.validation.metadata.ContainerElementTypeDescriptor)1