use of org.summerb.approaches.validation.errors.DuplicateRecordValidationError in project summerb by skarpushin.
the class EasyCrudDaoMySqlImpl method processDuplicateEntryException.
private void processDuplicateEntryException(Throwable t) throws FieldValidationException {
DuplicateKeyException dke = ExceptionUtils.findExceptionOfType(t, DuplicateKeyException.class);
if (dke == null) {
return;
}
String constraint = DaoExceptionUtils.findViolatedConstraintName(dke);
// Handle case when uuid is duplicated
if (DaoExceptionUtils.MYSQL_CONSTRAINT_PRIMARY.equals(constraint)) {
throw new IllegalArgumentException("Row with same primary key already exists", dke);
}
if (!constraint.contains(DaoExceptionUtils.MYSQL_CONSTRAINT_UNIQUE)) {
throw new IllegalArgumentException("Constraint violation " + constraint, dke);
}
String fieldName = constraint.substring(0, constraint.indexOf(DaoExceptionUtils.MYSQL_CONSTRAINT_UNIQUE));
if (fieldName.contains("_")) {
fieldName = JdbcUtils.convertUnderscoreNameToPropertyName(fieldName);
}
throw new FieldValidationException(new DuplicateRecordValidationError(fieldName));
}
Aggregations