in grails-datastore-gorm-hibernate/src/main/groovy/org/grails/orm/hibernate/cfg/GrailsDomainBinder.java [3254:3300]
protected void bindNumericColumnConstraints(Column column, PersistentProperty property, ColumnConfig cc) {
int scale = Column.DEFAULT_SCALE;
int precision = Column.DEFAULT_PRECISION;
PropertyConfig constrainedProperty = (PropertyConfig) property.getMapping().getMappedForm();
if( cc != null && cc.getScale() > - 1) {
column.setScale(cc.getScale());
} else if (constrainedProperty.getScale() > -1) {
scale = constrainedProperty.getScale();
column.setScale(scale);
}
if( cc != null && cc.getPrecision() > -1) {
column.setPrecision(cc.getPrecision());
}
else {
Comparable<?> minConstraintValue = constrainedProperty.getMin();
Comparable<?> maxConstraintValue = constrainedProperty.getMax();
int minConstraintValueLength = 0;
if ((minConstraintValue != null) && (minConstraintValue instanceof Number)) {
minConstraintValueLength = Math.max(
countDigits((Number) minConstraintValue),
countDigits(((Number) minConstraintValue).longValue()) + scale);
}
int maxConstraintValueLength = 0;
if ((maxConstraintValue != null) && (maxConstraintValue instanceof Number)) {
maxConstraintValueLength = Math.max(
countDigits((Number) maxConstraintValue),
countDigits(((Number) maxConstraintValue).longValue()) + scale);
}
if (minConstraintValueLength > 0 && maxConstraintValueLength > 0) {
// If both of min and max constraints are setted we could use
// maximum digits number in it as precision
precision = Math.max(minConstraintValueLength, maxConstraintValueLength);
} else {
// Overwise we should also use default precision
precision = DefaultGroovyMethods.max(new Integer[]{precision, minConstraintValueLength, maxConstraintValueLength});
}
column.setPrecision(precision);
}
}