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.
| 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 | ||
| [RW] | active |
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/oci_adapter.rb, line 542
542: def initialize(config, factory = OCIConnectionFactory.new)
543: @active = true
544: @username, @password, @host = config[:username], config[:password], config[:host]
545: @factory = factory
546: @connection = @factory.new_connection @username, @password, @host
547: super @connection
548: end
Adds auto-recovery functionality.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/oci_adapter.rb, line 583
583: def exec(sql, *bindvars)
584: should_retry = self.class.auto_retry? && autocommit?
585:
586: begin
587: @connection.exec(sql, *bindvars)
588: rescue OCIError => e
589: raise unless LOST_CONNECTION_ERROR_CODES.include?(e.code)
590: @active = false
591: raise unless should_retry
592: should_retry = false
593: reset! rescue nil
594: retry
595: end
596: end
Checks connection, returns true if active. Note that ping actively checks the connection, while active? simply returns the last known state.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/oci_adapter.rb, line 553
553: def ping
554: @connection.exec("select 1 from dual") { |r| nil }
555: @active = true
556: rescue
557: @active = false
558: raise
559: end
Resets connection, by logging off and creating a new connection.
[ show source ]
# File vendor/rails/activerecord/lib/active_record/connection_adapters/oci_adapter.rb, line 562
562: def reset!
563: logoff rescue nil
564: begin
565: @connection = @factory.new_connection @username, @password, @host
566: __setobj__ @connection
567: @active = true
568: rescue
569: @active = false
570: raise
571: end
572: end