/** * Create a database exception for a specific error code. * * @param errorCode the error code * @param params the list of parameters of the message * @return the exception */ public static DbException get(int errorCode, String... params) { return new DbException(getJdbcSQLException(errorCode, null, params)); }
/** * Create a database exception for a specific error code. * * @param errorCode the error code * @param cause the cause of the exception * @param params the list of parameters of the message * @return the exception */ public static DbException get(int errorCode, Throwable cause, String... params) { return new DbException(getJdbcSQLException(errorCode, cause, params)); }
/** * Create a database exception for an arbitrary SQLState. * * @param sqlstate the state to use * @param message the message to use * @return the exception */ public static DbException fromUser(String sqlstate, String message) { // do not translate as sqlstate is arbitrary : avoid "message not found" return new DbException(new JdbcSQLException(message, null, sqlstate, 0, null, null)); }
/** * Create a syntax error exception. * * @param sql the SQL statement * @param index the position of the error in the SQL statement * @param message the message * @return the exception */ public static DbException getSyntaxError(String sql, int index, String message) { sql = StringUtils.addAsterisk(sql, index); return new DbException(getJdbcSQLException(ErrorCode.SYNTAX_ERROR_2, null, sql, message)); }
/** * Set the SQL statement of the given exception. * This method may create a new object. * * @param sql the SQL statement * @return the exception */ public DbException addSQL(String sql) { SQLException e = getSQLException(); if (e instanceof JdbcSQLException) { JdbcSQLException j = (JdbcSQLException) e; if (j.getSQL() == null) { j.setSQL(sql); } return this; } e = new JdbcSQLException(e.getMessage(), sql, e.getSQLState(), e.getErrorCode(), e, null); return new DbException(e); }
/** * Convert a throwable to an SQL exception using the default mapping. All * errors except the following are re-thrown: StackOverflowError, * LinkageError. * * @param e the root cause * @return the exception object */ public static DbException convert(Throwable e) { if (e instanceof DbException) { return (DbException) e; } else if (e instanceof SQLException) { return new DbException((SQLException) e); } else if (e instanceof InvocationTargetException) { return convertInvocation((InvocationTargetException) e, null); } else if (e instanceof IOException) { return get(ErrorCode.IO_EXCEPTION_1, e, e.toString()); } else if (e instanceof OutOfMemoryError) { return get(ErrorCode.OUT_OF_MEMORY, e); } else if (e instanceof StackOverflowError || e instanceof LinkageError) { return get(ErrorCode.GENERAL_ERROR_1, e, e.toString()); } else if (e instanceof Error) { throw (Error) e; } return get(ErrorCode.GENERAL_ERROR_1, e, e.toString()); }
/** * Create a database exception for a specific error code. * * @param errorCode the error code * @param cause the cause of the exception * @param params the list of parameters of the message * @return the exception */ public static DbException get(int errorCode, Throwable cause, String... params) { return new DbException(getJdbcSQLException(errorCode, cause, params)); }
/** * Create a database exception for a specific error code. * * @param errorCode the error code * @param params the list of parameters of the message * @return the exception */ public static DbException get(int errorCode, String... params) { return new DbException(getJdbcSQLException(errorCode, null, params)); }
/** * Create a database exception for a specific error code. * * @param errorCode the error code * @param cause the cause of the exception * @param params the list of parameters of the message * @return the exception */ public static DbException get(int errorCode, Throwable cause, String... params) { return new DbException(getJdbcSQLException(errorCode, cause, params)); }
/** * Create a database exception for a specific error code. * * @param errorCode the error code * @param params the list of parameters of the message * @return the exception */ public static DbException get(int errorCode, String... params) { return new DbException(getJdbcSQLException(errorCode, null, params)); }
/** * Create a syntax error exception. * * @param sql the SQL statement * @param index the position of the error in the SQL statement * @param message the message * @return the exception */ public static DbException getSyntaxError(String sql, int index, String message) { sql = StringUtils.addAsterisk(sql, index); return new DbException(getJdbcSQLException(ErrorCode.SYNTAX_ERROR_2, null, sql, message)); }
/** * Create a syntax error exception. * * @param sql the SQL statement * @param index the position of the error in the SQL statement * @param message the message * @return the exception */ public static DbException getSyntaxError(String sql, int index, String message) { sql = StringUtils.addAsterisk(sql, index); return new DbException(getJdbcSQLException(ErrorCode.SYNTAX_ERROR_2, null, sql, message)); }
/** * Set the SQL statement of the given exception. * This method may create a new object. * * @param sql the SQL statement * @return the exception */ public DbException addSQL(String sql) { SQLException e = getSQLException(); if (e instanceof JdbcSQLException) { JdbcSQLException j = (JdbcSQLException) e; if (j.getSQL() == null) { j.setSQL(sql); } return this; } e = new JdbcSQLException(e.getMessage(), sql, e.getSQLState(), e.getErrorCode(), e, null); return new DbException(e); }
/** * Set the SQL statement of the given exception. * This method may create a new object. * * @param sql the SQL statement * @return the exception */ public DbException addSQL(String sql) { SQLException e = getSQLException(); if (e instanceof JdbcSQLException) { JdbcSQLException j = (JdbcSQLException) e; if (j.getSQL() == null) { j.setSQL(sql); } return this; } e = new JdbcSQLException(e.getMessage(), sql, e.getSQLState(), e.getErrorCode(), e, null); return new DbException(e); }
/** * Convert a throwable to an SQL exception using the default mapping. All * errors except the following are re-thrown: StackOverflowError, * LinkageError. * * @param e the root cause * @return the exception object */ public static DbException convert(Throwable e) { if (e instanceof DbException) { return (DbException) e; } else if (e instanceof SQLException) { return new DbException((SQLException) e); } else if (e instanceof InvocationTargetException) { return convertInvocation((InvocationTargetException) e, null); } else if (e instanceof IOException) { return get(ErrorCode.IO_EXCEPTION_1, e, e.toString()); } else if (e instanceof OutOfMemoryError) { return get(ErrorCode.OUT_OF_MEMORY, e); } else if (e instanceof StackOverflowError || e instanceof LinkageError) { return get(ErrorCode.GENERAL_ERROR_1, e, e.toString()); } else if (e instanceof Error) { throw (Error) e; } return get(ErrorCode.GENERAL_ERROR_1, e, e.toString()); }
/** * Convert a throwable to an SQL exception using the default mapping. All * errors except the following are re-thrown: StackOverflowError, * LinkageError. * * @param e the root cause * @return the exception object */ public static DbException convert(Throwable e) { if (e instanceof DbException) { return (DbException) e; } else if (e instanceof SQLException) { return new DbException((SQLException) e); } else if (e instanceof InvocationTargetException) { return convertInvocation((InvocationTargetException) e, null); } else if (e instanceof IOException) { return get(ErrorCode.IO_EXCEPTION_1, e, e.toString()); } else if (e instanceof OutOfMemoryError) { return get(ErrorCode.OUT_OF_MEMORY, e); } else if (e instanceof StackOverflowError || e instanceof LinkageError) { return get(ErrorCode.GENERAL_ERROR_1, e, e.toString()); } else if (e instanceof Error) { throw (Error) e; } return get(ErrorCode.GENERAL_ERROR_1, e, e.toString()); }