protected boolean willHealViaReparse(SQLException e) { // "prepared statement \"S_2\" does not exist" if (PSQLState.INVALID_SQL_STATEMENT_NAME.getState().equals(e.getSQLState())) { return true; } if (!PSQLState.NOT_IMPLEMENTED.getState().equals(e.getSQLState())) { return false; } if (!(e instanceof PSQLException)) { return false; } PSQLException pe = (PSQLException) e; ServerErrorMessage serverErrorMessage = pe.getServerErrorMessage(); if (serverErrorMessage == null) { return false; } // "cached plan must not change result type" String routine = pe.getServerErrorMessage().getRoutine(); return "RevalidateCachedQuery".equals(routine) // 9.2+ || "RevalidateCachedPlan".equals(routine); // <= 9.1 }
private String getRefTableFromForeignKeyPsqlException(PSQLException pSqlException) { ServerErrorMessage serverErrorMessage = pSqlException.getServerErrorMessage(); Matcher messageMatcher = Pattern.compile( "update or delete on table \"(.*)\" violates foreign key constraint \"(.*)\" on table \"(.*)\"") .matcher(serverErrorMessage.getMessage()); if (!messageMatcher.matches()) { LOG.error(ERROR_TRANSLATING_POSTGRES_EXC_MSG, pSqlException); throw new RuntimeException(ERROR_TRANSLATING_EXCEPTION_MSG, pSqlException); } return messageMatcher.group(1); }
/** * Package private for testability * * @param pSqlException PostgreSQL exception * @return translated validation exception */ static MolgenisValidationException translateUndefinedColumnException( PSQLException pSqlException) { ServerErrorMessage serverErrorMessage = pSqlException.getServerErrorMessage(); String message = serverErrorMessage.getMessage(); // FIXME exposes internal message ConstraintViolation constraintViolation = new ConstraintViolation(message); return new MolgenisValidationException(singleton(constraintViolation)); }
/** * Package private for testability * * @param pSqlException PostgreSQL exception * @return translated validation exception */ MolgenisValidationException translateReadonlyViolation(PSQLException pSqlException) { Matcher matcher = Pattern.compile( "Updating read-only column \"?(.*?)\"? of table \"?(.*?)\"? with id \\[(.*?)] is not allowed") .matcher(pSqlException.getServerErrorMessage().getMessage()); boolean matches = matcher.matches(); if (!matches) { LOG.error(ERROR_TRANSLATING_POSTGRES_EXC_MSG, pSqlException); throw new RuntimeException(ERROR_TRANSLATING_EXCEPTION_MSG, pSqlException); } String colName = matcher.group(1); String tableName = matcher.group(2); String id = matcher.group(3); ConstraintViolation constraintViolation = new ConstraintViolation( format( "Updating read-only attribute '%s' of entity '%s' with id '%s' is not allowed.", tryGetAttributeName(tableName, colName).orElse(TOKEN_UNKNOWN), tryGetEntityTypeName(tableName).orElse(TOKEN_UNKNOWN), id)); return new MolgenisValidationException(singleton(constraintViolation)); }
ServerErrorMessage serverErrorMessage = pSqlException.getServerErrorMessage(); String detail = serverErrorMessage.getDetail(); Matcher matcher =
/** * Package private for testability * * @param pSqlException PostgreSQL exception * @return translated validation exception */ MolgenisValidationException translateCheckConstraintViolation(PSQLException pSqlException) { ServerErrorMessage serverErrorMessage = pSqlException.getServerErrorMessage(); String tableName = serverErrorMessage.getTable(); String constraintName = serverErrorMessage.getConstraint(); // constraint name: <tableName>_<columnName>_chk String columnName = constraintName.substring(tableName.length() + 1, constraintName.length() - 4); ConstraintViolation constraintViolation = new ConstraintViolation( format( "Unknown enum value for attribute '%s' of entity '%s'.", tryGetAttributeName(tableName, columnName).orElse(TOKEN_UNKNOWN), tryGetEntityTypeName(tableName).orElse(TOKEN_UNKNOWN)), null); return new MolgenisValidationException(singleton(constraintViolation)); }
ServerErrorMessage serverErrorMessage = pSqlException.getServerErrorMessage(); String tableName = serverErrorMessage.getTable(); String detailMessage = serverErrorMessage.getDetail();
} catch (PSQLException e) { ServerErrorMessage m = e.getServerErrorMessage(); System.out.println(m.getColumn()); System.out.println(m.getConstraint()); System.out.println(m.getDatatype()); System.out.println(m.getDetail()); System.out.println(m.getFile()); System.out.println(m.getHint()); System.out.println(m.getInternalPosition()); System.out.println(m.getInternalQuery()); System.out.println(m.getLine()); System.out.println(m.getMessage()); System.out.println(m.getPosition()); System.out.println(m.getRoutine()); System.out.println(m.getSchema()); System.out.println(m.getSeverity()); System.out.println(m.getSQLState()); System.out.println(m.getTable()); System.out.println(m.getWhere()); }
ServerErrorMessage serverErrorMessage = pSqlException.getServerErrorMessage(); String tableName = serverErrorMessage.getTable(); String detailMessage = serverErrorMessage.getDetail();
ServerErrorMessage serverErrorMessage = pSqlException.getServerErrorMessage(); String tableName = serverErrorMessage.getTable(); String message = serverErrorMessage.getMessage();
ServerErrorMessage serverErrorMessage = pSqlException.getServerErrorMessage(); String message = serverErrorMessage.getMessage(); Matcher matcher =