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.



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

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.



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

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

#errnoObject

Deprecated.

See Also:



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

def errno; error_code end

#error_codeInteger, NilClass

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

Returns:

  • (Integer, NilClass)

See Also:



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

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).



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

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)


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

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

#set_backtrace(backtrace) ⇒ Object



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

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:



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

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)


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

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