Class: ActiveRecord::JDBCError

Inherits:
WrappedDatabaseException
  • Object
show all
Defined in:
lib/arjdbc/jdbc/error.rb

Overview

Represents exceptions that have propagated up through the JDBC API.

Instance Method Summary collapse

Constructor Details

#initialize(message = nil, cause = $!) ⇒ JDBCError

Returns a new instance of JDBCError.



5
6
7
8
9
10
11
12
# File 'lib/arjdbc/jdbc/error.rb', line 5

def initialize(message = nil, cause = $!)
  super( ( message.nil? && cause ) ? cause.message : message )
  if cause.is_a? Java::JavaSql::SQLException
    @jdbc_exception, @cause = cause, nil
  else
    @cause, @jdbc_exception = cause, nil
  end
end

Instance Method Details

#causeObject Also known as: original_exception

Likely (but not necessarily) the same as #jdbc_exception.



45
# File 'lib/arjdbc/jdbc/error.rb', line 45

def cause; ( @cause ||= nil ) || jdbc_exception end

#errnoObject

Deprecated.

See Also:



26
# File 'lib/arjdbc/jdbc/error.rb', line 26

def errno; error_code end

#error_codeInteger, NilClass

The DB (or JDBC driver implementation specific) vendor error code.

Returns:

  • (Integer, NilClass)

See Also:



17
18
19
20
21
22
23
# File 'lib/arjdbc/jdbc/error.rb', line 17

def error_code
  if ( @error_code ||= nil ).nil?
    @error_code = jdbc_exception ? jdbc_exception.getErrorCode : nil
  else
    @error_code
  end
end

#jdbc_exceptionObject Also known as: sql_exception

Note:

Navigate through chained exceptions using jdbc_exception.next_exception.

The full Java exception (SQLException) object that was raised (if any).



36
# File 'lib/arjdbc/jdbc/error.rb', line 36

def jdbc_exception; @jdbc_exception end

#recoverable?Boolean

true if the current error might be recovered e.g. by re-trying the transaction

Returns:

  • (Boolean)


40
# File 'lib/arjdbc/jdbc/error.rb', line 40

def recoverable?; jdbc_exception.is_a?(Java::JavaSql::SQLRecoverableException) end

#set_backtrace(backtrace) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/arjdbc/jdbc/error.rb', line 51

def set_backtrace(backtrace)
  @raw_backtrace = backtrace
  if ( nested = cause ) && ! nested.equal?(self)
    backtrace = backtrace - ( nested.respond_to?(:raw_backtrace) ? nested.raw_backtrace : nested.backtrace )
    backtrace << "#{nested.backtrace.first}: #{nested.message} (#{nested.class.name})"
    backtrace.concat nested.backtrace[1..-1] || []
  end
  super(backtrace)
end

#sql_stateString, NilClass

SQL code as standardized by ISO/ANSI and Open Group (X/Open), although some codes have been reserved for DB vendors to define for themselves.

Returns:

  • (String, NilClass)

See Also:



32
# File 'lib/arjdbc/jdbc/error.rb', line 32

def sql_state; jdbc_exception ? jdbc_exception.getSQLState : nil end

#transient?Boolean

true when a failed operation might be able to succeed when retried (e.g. timeouts)

Returns:

  • (Boolean)


42
# File 'lib/arjdbc/jdbc/error.rb', line 42

def transient?; jdbc_exception.is_a?(Java::JavaSql::SQLTransientException) end