Search in sources :

Example 36 with PSQLException

use of org.postgresql.util.PSQLException in project cloudbreak by hortonworks.

the class SqlUtil method getProperSqlErrorMessage.

public static String getProperSqlErrorMessage(DataIntegrityViolationException ex) {
    Throwable cause = ex.getCause();
    while (cause.getCause() != null || cause instanceof PSQLException) {
        if (cause instanceof PSQLException && !((SQLException) cause).getSQLState().isEmpty()) {
            PSQLException e = (PSQLException) cause;
            String[] split = e.getLocalizedMessage().split("\\n");
            if (split.length > 0) {
                return split[0];
            }
        }
        cause = cause.getCause();
    }
    return ex.getLocalizedMessage();
}
Also used : PSQLException(org.postgresql.util.PSQLException)

Aggregations

PSQLException (org.postgresql.util.PSQLException)36 ServerErrorMessage (org.postgresql.util.ServerErrorMessage)28 Test (org.testng.annotations.Test)26 MolgenisValidationException (org.molgenis.data.validation.MolgenisValidationException)24 SQLException (java.sql.SQLException)3 MolgenisDataException (org.molgenis.data.MolgenisDataException)3 BatchUpdateException (java.sql.BatchUpdateException)2 PGExceptionSorter (com.alibaba.druid.pool.vendor.PGExceptionSorter)1 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)1 IOException (java.io.IOException)1 String.format (java.lang.String.format)1 ConnectException (java.net.ConnectException)1 ByteBuffer (java.nio.ByteBuffer)1 PreparedStatement (java.sql.PreparedStatement)1 SQLWarning (java.sql.SQLWarning)1 ArrayList (java.util.ArrayList)1 Collections.singleton (java.util.Collections.singleton)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1