use of org.postgresql.util.PSQLException in project midpoint by Evolveum.
the class AddObjectContext method execute.
/**
* Inserts the object provided to the constructor and returns its OID.
*/
public String execute() throws SchemaException, ObjectAlreadyExistsException {
try (JdbcSession jdbcSession = repositoryContext.newJdbcSession().startTransaction()) {
String oid = execute(jdbcSession);
jdbcSession.commit();
return oid;
} catch (QueryException e) {
// Querydsl exception, not ours
Throwable cause = e.getCause();
if (cause instanceof PSQLException) {
SqaleUtils.handlePostgresException((PSQLException) cause);
}
throw e;
}
}
use of org.postgresql.util.PSQLException in project summerb by skarpushin.
the class DaoExceptionToFveTranslatorPostgresImpl method throwIfDuplicate.
private void throwIfDuplicate(Throwable t) throws FieldValidationException {
DuplicateKeyException dke = ExceptionUtils.findExceptionOfType(t, DuplicateKeyException.class);
if (dke == null) {
return;
}
PSQLException dkep = ExceptionUtils.findExceptionOfType(t, PSQLException.class);
if (dkep == null) {
return;
}
String detail = dkep.getServerErrorMessage().getDetail();
if (!StringUtils.hasText(detail)) {
return;
}
if (!detail.startsWith("Key (")) {
return;
}
String fieldsStr = detail.substring(5, detail.indexOf(")"));
String[] fields = fieldsStr.split(",");
ValidationContext ctx = new ValidationContext();
for (String field : fields) {
ctx.add(new DuplicateRecordValidationError(JdbcUtils.convertUnderscoreNameToPropertyName(field.trim())));
}
ctx.throwIfHasErrors();
}
Aggregations