Search in sources :

Example 1 with DataTooLongValidationError

use of org.summerb.approaches.validation.errors.DataTooLongValidationError in project summerb by skarpushin.

the class DaoExceptionUtils method propagateIfTruncationError.

/**
 * @deprecated This feature will not actually work at least with mysql.
 *             MySql doesn't send the numbers - it sends only field name
 *             which was truncated.
 */
@Deprecated
public static void propagateIfTruncationError(Throwable t) throws FieldValidationException {
    DataTruncation exc = ExceptionUtils.findExceptionOfType(t, DataTruncation.class);
    if (exc == null) {
        return;
    }
    String fieldName = findTruncatedFieldNameIfAny(t);
    if (fieldName == null) {
        return;
    }
    DataTooLongValidationError dataTooLongValidationError = new DataTooLongValidationError(exc.getDataSize(), exc.getTransferSize(), fieldName);
    throw new FieldValidationException(dataTooLongValidationError);
}
Also used : FieldValidationException(org.summerb.approaches.validation.FieldValidationException) DataTooLongValidationError(org.summerb.approaches.validation.errors.DataTooLongValidationError) DataTruncation(java.sql.DataTruncation)

Example 2 with DataTooLongValidationError

use of org.summerb.approaches.validation.errors.DataTooLongValidationError in project summerb by skarpushin.

the class ValidationContext method validateDataLengthLessOrEqual.

public boolean validateDataLengthLessOrEqual(String str, int maxLength, String fieldToken) {
    int len = str == null ? 0 : str.length();
    if (len <= maxLength) {
        return true;
    }
    add(new DataTooLongValidationError(len, maxLength, fieldToken));
    return false;
}
Also used : DataTooLongValidationError(org.summerb.approaches.validation.errors.DataTooLongValidationError)

Aggregations

DataTooLongValidationError (org.summerb.approaches.validation.errors.DataTooLongValidationError)2 DataTruncation (java.sql.DataTruncation)1 FieldValidationException (org.summerb.approaches.validation.FieldValidationException)1