Class DbException

  • All Implemented Interfaces:
    java.io.Serializable

    public class DbException
    extends java.lang.RuntimeException
    This exception wraps a checked exception. It is used in methods where checked exceptions are not supported, for example in a Comparator.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String HIDE_SQL
      If the SQL statement contains this text, then it is never added to the SQL exception.
      static java.sql.SQLException SQL_OOME
      Thrown when OOME exception happens on handle error inside convert(java.lang.Throwable).
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      DbException addSQL​(java.lang.String sql)
      Set the SQL statement of the given exception.
      static java.lang.String buildMessageForException​(JdbcException e)
      Builds message for an exception.
      static DbException convert​(java.lang.Throwable e)
      Convert a throwable to an SQL exception using the default mapping.
      static DbException convertInvocation​(java.lang.reflect.InvocationTargetException te, java.lang.String message)
      Convert an InvocationTarget exception to a database exception.
      static DbException convertIOException​(java.io.IOException e, java.lang.String message)
      Convert an IO exception to a database exception.
      static DbException fromUser​(java.lang.String sqlstate, java.lang.String message)
      Create a database exception for an arbitrary SQLState.
      static DbException get​(int errorCode)
      Create a database exception for a specific error code.
      static DbException get​(int errorCode, java.lang.String p1)
      Create a database exception for a specific error code.
      static DbException get​(int errorCode, java.lang.String... params)
      Create a database exception for a specific error code.
      static DbException get​(int errorCode, java.lang.Throwable cause, java.lang.String... params)
      Create a database exception for a specific error code.
      int getErrorCode()
      Get the error code.
      static DbException getFileVersionError​(java.lang.String dataFileName)
      Gets a file version exception.
      static java.lang.RuntimeException getInternalError()
      Gets an internal error.
      static java.lang.RuntimeException getInternalError​(java.lang.String s)
      Gets an internal error.
      static DbException getInvalidValueException​(java.lang.String param, java.lang.Object value)
      Gets a SQL exception meaning this value is invalid.
      static DbException getInvalidValueException​(java.lang.Throwable cause, java.lang.String param, java.lang.Object value)
      Gets a SQL exception meaning this value is invalid.
      static java.sql.SQLException getJdbcSQLException​(int errorCode)
      Gets the SQL exception object for a specific error code.
      static java.sql.SQLException getJdbcSQLException​(int errorCode, java.lang.String p1)
      Gets the SQL exception object for a specific error code.
      static java.sql.SQLException getJdbcSQLException​(int errorCode, java.lang.Throwable cause, java.lang.String... params)
      Gets the SQL exception object for a specific error code.
      static java.sql.SQLException getJdbcSQLException​(java.lang.String message, java.lang.String sql, java.lang.String state, int errorCode, java.lang.Throwable cause, java.lang.String stackTrace)
      Creates a SQLException.
      java.lang.Object getSource()  
      java.sql.SQLException getSQLException()
      Get the SQLException object.
      static DbException getSyntaxError​(int errorCode, java.lang.String sql, int index, java.lang.String... params)
      Create a syntax error exception for a specific error code.
      static DbException getSyntaxError​(java.lang.String sql, int index)
      Create a syntax error exception.
      static DbException getSyntaxError​(java.lang.String sql, int index, java.lang.String message)
      Create a syntax error exception.
      static DbException getUnsupportedException​(java.lang.String message)
      Gets a SQL exception meaning this feature is not supported.
      static DbException getValueTooLongException​(java.lang.String columnOrType, java.lang.String value, long valueLength)
      Gets a SQL exception meaning this value is too long.
      static void printNextExceptions​(java.sql.SQLException e, java.io.PrintStream s)
      Prints up to 100 next exceptions for a specified SQL exception.
      static void printNextExceptions​(java.sql.SQLException e, java.io.PrintWriter s)
      Prints up to 100 next exceptions for a specified SQL exception.
      void setSource​(java.lang.Object source)  
      static java.sql.SQLException toSQLException​(java.lang.Throwable e)
      Convert an exception to a SQL exception using the default mapping.
      static void traceThrowable​(java.lang.Throwable e)
      Write the exception to the driver manager log writer if configured.
      • Methods inherited from class java.lang.Throwable

        addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • HIDE_SQL

        public static final java.lang.String HIDE_SQL
        If the SQL statement contains this text, then it is never added to the SQL exception. Hiding the SQL statement may be important if it contains a passwords, such as a CREATE LINKED TABLE statement.
        See Also:
        Constant Field Values
      • SQL_OOME

        public static final java.sql.SQLException SQL_OOME
        Thrown when OOME exception happens on handle error inside convert(java.lang.Throwable).
    • Method Detail

      • getSQLException

        public java.sql.SQLException getSQLException()
        Get the SQLException object.
        Returns:
        the exception
      • getErrorCode

        public int getErrorCode()
        Get the error code.
        Returns:
        the error code
      • addSQL

        public DbException addSQL​(java.lang.String sql)
        Set the SQL statement of the given exception. This method may create a new object.
        Parameters:
        sql - the SQL statement
        Returns:
        the exception
      • get

        public static DbException get​(int errorCode)
        Create a database exception for a specific error code.
        Parameters:
        errorCode - the error code
        Returns:
        the exception
      • get

        public static DbException get​(int errorCode,
                                      java.lang.String p1)
        Create a database exception for a specific error code.
        Parameters:
        errorCode - the error code
        p1 - the first parameter of the message
        Returns:
        the exception
      • get

        public static DbException get​(int errorCode,
                                      java.lang.Throwable cause,
                                      java.lang.String... params)
        Create a database exception for a specific error code.
        Parameters:
        errorCode - the error code
        cause - the cause of the exception
        params - the list of parameters of the message
        Returns:
        the exception
      • get

        public static DbException get​(int errorCode,
                                      java.lang.String... params)
        Create a database exception for a specific error code.
        Parameters:
        errorCode - the error code
        params - the list of parameters of the message
        Returns:
        the exception
      • fromUser

        public static DbException fromUser​(java.lang.String sqlstate,
                                           java.lang.String message)
        Create a database exception for an arbitrary SQLState.
        Parameters:
        sqlstate - the state to use
        message - the message to use
        Returns:
        the exception
      • getSyntaxError

        public static DbException getSyntaxError​(java.lang.String sql,
                                                 int index)
        Create a syntax error exception.
        Parameters:
        sql - the SQL statement
        index - the position of the error in the SQL statement
        Returns:
        the exception
      • getSyntaxError

        public static DbException getSyntaxError​(java.lang.String sql,
                                                 int index,
                                                 java.lang.String message)
        Create a syntax error exception.
        Parameters:
        sql - the SQL statement
        index - the position of the error in the SQL statement
        message - the message
        Returns:
        the exception
      • getSyntaxError

        public static DbException getSyntaxError​(int errorCode,
                                                 java.lang.String sql,
                                                 int index,
                                                 java.lang.String... params)
        Create a syntax error exception for a specific error code.
        Parameters:
        errorCode - the error code
        sql - the SQL statement
        index - the position of the error in the SQL statement
        params - the list of parameters of the message
        Returns:
        the exception
      • getUnsupportedException

        public static DbException getUnsupportedException​(java.lang.String message)
        Gets a SQL exception meaning this feature is not supported.
        Parameters:
        message - what exactly is not supported
        Returns:
        the exception
      • getInvalidValueException

        public static DbException getInvalidValueException​(java.lang.String param,
                                                           java.lang.Object value)
        Gets a SQL exception meaning this value is invalid.
        Parameters:
        param - the name of the parameter
        value - the value passed
        Returns:
        the exception
      • getInvalidValueException

        public static DbException getInvalidValueException​(java.lang.Throwable cause,
                                                           java.lang.String param,
                                                           java.lang.Object value)
        Gets a SQL exception meaning this value is invalid.
        Parameters:
        cause - the cause of the exception
        param - the name of the parameter
        value - the value passed
        Returns:
        the exception
      • getValueTooLongException

        public static DbException getValueTooLongException​(java.lang.String columnOrType,
                                                           java.lang.String value,
                                                           long valueLength)
        Gets a SQL exception meaning this value is too long.
        Parameters:
        columnOrType - column with data type or data type name
        value - string representation of value, will be truncated to 80 characters
        valueLength - the actual length of value, -1L if unknown
        Returns:
        the exception
      • getFileVersionError

        public static DbException getFileVersionError​(java.lang.String dataFileName)
        Gets a file version exception.
        Parameters:
        dataFileName - the name of the database
        Returns:
        the exception
      • getInternalError

        public static java.lang.RuntimeException getInternalError​(java.lang.String s)
        Gets an internal error.
        Parameters:
        s - the message
        Returns:
        the RuntimeException object
      • getInternalError

        public static java.lang.RuntimeException getInternalError()
        Gets an internal error.
        Returns:
        the RuntimeException object
      • toSQLException

        public static java.sql.SQLException toSQLException​(java.lang.Throwable e)
        Convert an exception to a SQL exception using the default mapping.
        Parameters:
        e - the root cause
        Returns:
        the SQL exception object
      • convert

        public static DbException convert​(java.lang.Throwable e)
        Convert a throwable to an SQL exception using the default mapping. All errors except the following are re-thrown: StackOverflowError, LinkageError.
        Parameters:
        e - the root cause
        Returns:
        the exception object
      • convertInvocation

        public static DbException convertInvocation​(java.lang.reflect.InvocationTargetException te,
                                                    java.lang.String message)
        Convert an InvocationTarget exception to a database exception.
        Parameters:
        te - the root cause
        message - the added message or null
        Returns:
        the database exception object
      • convertIOException

        public static DbException convertIOException​(java.io.IOException e,
                                                     java.lang.String message)
        Convert an IO exception to a database exception.
        Parameters:
        e - the root cause
        message - the message or null
        Returns:
        the database exception object
      • getJdbcSQLException

        public static java.sql.SQLException getJdbcSQLException​(int errorCode)
        Gets the SQL exception object for a specific error code.
        Parameters:
        errorCode - the error code
        Returns:
        the SQLException object
      • getJdbcSQLException

        public static java.sql.SQLException getJdbcSQLException​(int errorCode,
                                                                java.lang.String p1)
        Gets the SQL exception object for a specific error code.
        Parameters:
        errorCode - the error code
        p1 - the first parameter of the message
        Returns:
        the SQLException object
      • getJdbcSQLException

        public static java.sql.SQLException getJdbcSQLException​(int errorCode,
                                                                java.lang.Throwable cause,
                                                                java.lang.String... params)
        Gets the SQL exception object for a specific error code.
        Parameters:
        errorCode - the error code
        cause - the cause of the exception
        params - the list of parameters of the message
        Returns:
        the SQLException object
      • getJdbcSQLException

        public static java.sql.SQLException getJdbcSQLException​(java.lang.String message,
                                                                java.lang.String sql,
                                                                java.lang.String state,
                                                                int errorCode,
                                                                java.lang.Throwable cause,
                                                                java.lang.String stackTrace)
        Creates a SQLException.
        Parameters:
        message - the reason
        sql - the SQL statement
        state - the SQL state
        errorCode - the error code
        cause - the exception that was the reason for this exception
        stackTrace - the stack trace
        Returns:
        the SQLException object
      • buildMessageForException

        public static java.lang.String buildMessageForException​(JdbcException e)
        Builds message for an exception.
        Parameters:
        e - exception
        Returns:
        message
      • printNextExceptions

        public static void printNextExceptions​(java.sql.SQLException e,
                                               java.io.PrintWriter s)
        Prints up to 100 next exceptions for a specified SQL exception.
        Parameters:
        e - SQL exception
        s - print writer
      • printNextExceptions

        public static void printNextExceptions​(java.sql.SQLException e,
                                               java.io.PrintStream s)
        Prints up to 100 next exceptions for a specified SQL exception.
        Parameters:
        e - SQL exception
        s - print stream
      • getSource

        public java.lang.Object getSource()
      • setSource

        public void setSource​(java.lang.Object source)
      • traceThrowable

        public static void traceThrowable​(java.lang.Throwable e)
        Write the exception to the driver manager log writer if configured.
        Parameters:
        e - the exception