Class DatabaseException

All Implemented Interfaces:
Serializable

Thrown when an error occurs when interacting with a Database.

If the cause of this exception is a SQLException, the getErrorCode() and getSqlState() accessors are shorthand for retrieving the corresponding SQLException values.

Since:
1.0.0
Author:
Mark Allen
See Also:
  • Constructor Details

    • DatabaseException

      Creates a DatabaseException with the given message.
      Parameters:
      message - a message describing this exception
    • DatabaseException

      Creates a DatabaseException which wraps the given cause.
      Parameters:
      cause - the cause of this exception
    • DatabaseException

      Creates a DatabaseException which wraps the given cause.
      Parameters:
      message - a message describing this exception
      cause - the cause of this exception
  • Method Details

    • toString

      public String toString()
      Renders general diagnostics without automatically appending server detail, hint, internal query or context. Explicit diagnostic accessors retain those fields; messages and original causes can still contain data.
      Overrides:
      toString in class Throwable
      Returns:
      a diagnostic description
    • getErrorCode

      Shorthand for SQLException.getErrorCode() if this exception was caused by a SQLException.
      Returns:
      the value of SQLException.getErrorCode(), or empty if not available
    • getSqlState

      Shorthand for SQLException.getSQLState() if this exception was caused by a SQLException. The available operational code is preserved verbatim; secure-parameter literal scrubbing does not modify it.
      Returns:
      the value of SQLException.getSQLState(), or empty if not available
    • isUniqueConstraintViolation

      Determines if this exception is recognized as a unique constraint violation.

      This method is intentionally conservative: it returns true only when Pyranid recognizes a database-specific error code or SQLState as a unique or primary-key uniqueness violation.

      Returns:
      true if this exception is recognized as a unique constraint violation
      Since:
      4.3.0
    • isForeignKeyViolation

      Determines if this exception is recognized as a foreign-key violation.

      This method is intentionally conservative: it returns true only when Pyranid recognizes a database-specific error code or SQLState as a foreign-key violation. For example, SQL Server error 547 is not classified as a foreign-key violation by code alone because the same error code also covers other constraint failures, such as CHECK constraints.

      Returns:
      true if this exception is recognized as a foreign-key violation
      Since:
      4.3.0
    • isDeadlock

      Determines if this exception is recognized as a deadlock.

      This method is intentionally conservative: it returns true only when Pyranid recognizes a database-specific error code or SQLState as a deadlock.

      Returns:
      true if this exception is recognized as a deadlock
      Since:
      4.3.0
    • isTransient

      Determines if this exception is recognized as transient.

      This method is intentionally conservative: it returns true for JDBC transient/recoverable exception classes, SQLState classes for connection exceptions and transaction rollbacks, or database-specific deadlock/lock-timeout signals recognized by Pyranid. A true result does not guarantee that retrying the operation will succeed.

      Returns:
      true if this exception is recognized as transient
      Since:
      4.3.0
    • isSerializationFailure

      Determines if this exception is recognized as a serialization failure.

      This method is intentionally conservative: it returns true only when Pyranid recognizes a database-specific error code or SQLState as a serialization failure.

      Returns:
      true if this exception is recognized as a serialization failure
      Since:
      4.4.0
    • isTimeout

      Determines if this exception is recognized as a timeout or cancellation.

      This method is intentionally conservative: it returns true only when Pyranid recognizes a JDBC timeout, database-specific timeout, or database-specific cancellation signal. A true result does not mean the operation is automatically safe to retry.

      Returns:
      true if this exception is recognized as a timeout or cancellation
      Since:
      4.4.0
    • getColumn

      Returns:
      the value of the offending column, or empty if not available
      Since:
      1.0.12
    • getConstraint

      Returns:
      the value of the offending constraint, or empty if not available
      Since:
      1.0.12
    • getDatatype

      Returns:
      the value of the offending datatype, or empty if not available
      Since:
      1.0.12
    • getDetail

      Returns:
      the value of the offending detail, or empty if not available
      Since:
      1.0.12
    • getFile

      Returns:
      the value of the offending file, or empty if not available
      Since:
      1.0.12
    • getHint

      Returns:
      the value of the error hint, or empty if not available
      Since:
      1.0.12
    • getInternalPosition

      Returns:
      the positive, one-based character position within the internal query, or empty if the server supplied none
      Since:
      1.0.12
    • getInternalQuery

      Returns:
      the value of the offending internalQuery, or empty if not available
      Since:
      1.0.12
    • getLine

      Returns:
      the value of the offending line, or empty if not available
      Since:
      1.0.12
    • getDbmsMessage

      Returns:
      the value of the error dbmsMessage, or empty if not available
      Since:
      1.0.12
    • getPosition

      Returns:
      the positive, one-based character position within the submitted query, or empty if the server supplied none
      Since:
      1.0.12
    • getRoutine

      Returns:
      the value of the offending routine, or empty if not available
      Since:
      1.0.12
    • getSchema

      Returns:
      the value of the offending schema, or empty if not available
      Since:
      1.0.12
    • getSeverity

      Returns:
      the error severity, or empty if not available
      Since:
      1.0.12
    • getTable

      Returns:
      the value of the offending table, or empty if not available
      Since:
      1.0.12
    • getWhere

      Returns:
      the value of the offending where, or empty if not available
      Since:
      1.0.12