The OCI8AutoRecover class enhances the OCI8 driver with auto-recover and reset functionality. If a call to exec fails, and autocommit is turned on (ie., we’re not in the middle of a longer transaction), it will automatically reconnect and try again. If autocommit is turned off, this would be dangerous (as the earlier part of the implied transaction may have failed silently if the connection died) — so instead the connection is marked as dead, to be reconnected on it’s next use.

Methods
Constants
LOST_CONNECTION_ERROR_CODES = [ 28, 1012, 3113, 3114 ]
  ORA-00028: your session has been killed ORA-01012: not logged on ORA-03113: end-of-file on communication channel ORA-03114: not connected to ORACLE
Attributes
[RW] active
Public Class methods
new(config, factory = OracleConnectionFactory.new)
     # File vendor/rails/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb, line 594
594:     def initialize(config, factory = OracleConnectionFactory.new)
595:       @active = true
596:       @username, @password, @database = config[:username], config[:password], config[:database]
597:       @factory = factory
598:       @connection  = @factory.new_connection @username, @password, @database
599:       super @connection
600:     end
Public Instance methods
exec(sql, *bindvars)

Adds auto-recovery functionality.

See: www.jiubao.org/ruby-oci8/api.en.html#label-11

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb, line 635
635:     def exec(sql, *bindvars)
636:       should_retry = self.class.auto_retry? && autocommit?
637: 
638:       begin
639:         @connection.exec(sql, *bindvars)
640:       rescue OCIException => e
641:         raise unless LOST_CONNECTION_ERROR_CODES.include?(e.code)
642:         @active = false
643:         raise unless should_retry
644:         should_retry = false
645:         reset! rescue nil
646:         retry
647:       end
648:     end
ping()

Checks connection, returns true if active. Note that ping actively checks the connection, while active? simply returns the last known state.

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb, line 605
605:     def ping
606:       @connection.exec("select 1 from dual") { |r| nil }
607:       @active = true
608:     rescue
609:       @active = false
610:       raise
611:     end
reset!()

Resets connection, by logging off and creating a new connection.

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/oracle_adapter.rb, line 614
614:     def reset!
615:       logoff rescue nil
616:       begin
617:         @connection = @factory.new_connection @username, @password, @database
618:         __setobj__ @connection
619:         @active = true
620:       rescue
621:         @active = false
622:         raise
623:       end
624:     end