HHH-12159 - Fix Warning HHH000274 when using Formula with a string-based size constrained property.

This commit is contained in:
Chris Cranford 2017-12-11 18:03:45 -05:00
parent 2296ee7768
commit 6c1948b6b3
1 changed files with 53 additions and 15 deletions

View File

@ -282,22 +282,37 @@ class TypeSafeActivator {
ConstraintDescriptor<Min> minConstraint = (ConstraintDescriptor<Min>) descriptor;
long min = minConstraint.getAnnotation().value();
Column col = (Column) property.getColumnIterator().next();
@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 );
}
}
}
}
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();
Column col = (Column) property.getColumnIterator().next();
String checkConstraint = col.getQuotedName(dialect) + "<=" + max;
@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 );
}
}
}
}
private static void applySQLCheck(Column col, String checkConstraint) {
String existingCheck = col.getCheckConstraint();
@ -344,24 +359,39 @@ class TypeSafeActivator {
ConstraintDescriptor<Digits> digitsConstraint = (ConstraintDescriptor<Digits>) descriptor;
int integerDigits = digitsConstraint.getAnnotation().integer();
int fractionalDigits = digitsConstraint.getAnnotation().fraction();
Column col = (Column) property.getColumnIterator().next();
@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;
col.setPrecision( integerDigits + fractionalDigits );
col.setScale( fractionalDigits );
}
}
}
}
private static void applySize(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) {
if ( Size.class.equals( descriptor.getAnnotation().annotationType() )
&& String.class.equals( propertyDescriptor.getElementClass() ) ) {
@SuppressWarnings("unchecked")
ConstraintDescriptor<Size> sizeConstraint = (ConstraintDescriptor<Size>) descriptor;
int max = sizeConstraint.getAnnotation().max();
Column col = (Column) property.getColumnIterator().next();
@SuppressWarnings("unchecked")
final Iterator<Selectable> itor = property.getColumnIterator();
if ( itor.hasNext() ) {
final Selectable selectable = itor.next();
Column col = (Column) selectable;
if ( max < Integer.MAX_VALUE ) {
col.setLength( max );
}
}
}
}
private static void applyLength(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) {
if ( "org.hibernate.validator.constraints.Length".equals(
@ -370,12 +400,20 @@ class TypeSafeActivator {
&& String.class.equals( propertyDescriptor.getElementClass() ) ) {
@SuppressWarnings("unchecked")
int max = (Integer) descriptor.getAttributes().get( "max" );
Column col = (Column) property.getColumnIterator().next();
@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;
if ( max < Integer.MAX_VALUE ) {
col.setLength( max );
}
}
}
}
}
/**
* Locate the property by path in a recursive way, including IdentifierProperty in the loop if propertyName is