aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2005-11-19 10:55:11 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2005-11-19 10:55:11 +0000
commit81c5242f43cb45d97b2a56409f8b39b0dba75ac3 (patch)
tree39b718add2f4ea15a24df9af62148d1574385a83 /activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
parent77e0b7986e56e5d1d607aaa05a460709977c8c34 (diff)
downloadrails-81c5242f43cb45d97b2a56409f8b39b0dba75ac3.tar.gz
rails-81c5242f43cb45d97b2a56409f8b39b0dba75ac3.tar.bz2
rails-81c5242f43cb45d97b2a56409f8b39b0dba75ac3.zip
r3181@asus: jeremy | 2005-11-19 02:52:24 -0800
Mark connections for verification. Retrieve connection verifies before returning a connection. Verification tests whether the connection is marked then reconnects if the connection is inactive. All active connections are marked for verification after a request is handled. References #428. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3096 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
index a20304ea62..5e70930a85 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
@@ -1,4 +1,28 @@
module ActiveRecord
+ module ConnectionAdapters
+ module ConnectionManagement
+ # Check whether the connection should be checked for activity before use.
+ def needs_verification?
+ @needs_verification == true
+ end
+
+ # Flag the connection for an activity check before use.
+ def needs_verification!
+ @needs_verification = true
+ end
+
+ # If the connection is flagged for an activity check, check whether
+ # it is active and reconnect if not.
+ def verify!
+ if needs_verification?
+ reconnect! unless active?
+ @needs_verification = false
+ end
+ self
+ end
+ end
+ end
+
# The root class of all active record objects.
class Base
class ConnectionSpecification #:nodoc:
@@ -78,8 +102,11 @@ module ActiveRecord
ar_super = ActiveRecord::Base.superclass
until klass == ar_super
if conn = active_connections[klass]
+ # Validate the active connection before returning it.
+ conn.verify!
return conn
elsif conn = @@defined_connections[klass]
+ # Activate this connection specification.
klass.connection = conn
return self.connection
end
@@ -125,5 +152,10 @@ module ActiveRecord
establish_connection spec
end
end
+
+ # Mark active connections for verification on next retrieve_connection.
+ def self.mark_active_connections_for_verification! #:nodoc:
+ active_connections.values.each { |conn| conn.needs_verification! }
+ end
end
end