Changeset 3218
- Timestamp:
- 12/04/05 05:56:49 (3 years ago)
- Files:
-
- trunk/activerecord/lib/active_record/base.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb (modified) (2 diffs)
- trunk/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb (modified) (3 diffs)
- trunk/activerecord/lib/active_record/fixtures.rb (modified) (1 diff)
- trunk/railties/lib/dispatcher.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/lib/active_record/base.rb
r3213 r3218 244 244 cattr_accessor :logger 245 245 246 @@connection_cache = Hash.new { |h, k| h[k] = Hash.new } 247 246 248 # Returns the connection currently associated with the class. This can 247 249 # also be used to "borrow" the connection to do database work unrelated 248 250 # to any of the specific Active Records. 249 251 def self.connection 250 retrieve_connection 252 @@connection_cache[Thread.current.object_id][name] ||= retrieve_connection 253 end 254 255 def self.clear_connection_cache! 256 @@connection_cache.clear 251 257 end 252 258 trunk/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
r3096 r3218 20 20 # SchemaStatements#remove_column are very useful. 21 21 class AbstractAdapter 22 include Quoting, DatabaseStatements, SchemaStatements , ConnectionManagement22 include Quoting, DatabaseStatements, SchemaStatements 23 23 @@row_even = true 24 24 … … 70 70 end 71 71 rescue Exception => e 72 # Flag connection as possibly dirty; needs verification before use.73 self.needs_verification!74 75 72 # Log message and raise exception. 76 73 message = "#{e.class.name}: #{e.message}: #{sql}" trunk/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
r3182 r3218 1 1 module ActiveRecord 2 module ConnectionAdapters3 module ConnectionManagement4 # Check whether the connection should be checked for activity before use.5 def needs_verification?6 @needs_verification == true7 end8 9 # Flag the connection for an activity check before use.10 def needs_verification!11 @needs_verification = true12 end13 14 # If the connection is flagged for an activity check, check whether15 # it is active and reconnect if not.16 def verify!17 if needs_verification?18 reconnect! unless active?19 @needs_verification = false20 end21 self22 end23 end24 end25 26 2 # The root class of all active record objects. 27 3 class Base … … 103 79 until klass == ar_super 104 80 if conn = active_connections[klass.name] 105 # Validate the active connection before returning it.106 conn. verify!81 # Reconnect if the connection is inactive. 82 conn.reconnect! unless conn.active? 107 83 return conn 108 84 elsif conn = @@defined_connections[klass.name] … … 153 129 end 154 130 end 155 156 # Mark active connections for verification on next retrieve_connection.157 def self.mark_active_connections_for_verification! #:nodoc:158 active_connections.values.each { |conn| conn.needs_verification! }159 end160 131 end 161 132 end trunk/activerecord/lib/active_record/fixtures.rb
r2862 r3218 504 504 505 505 def teardown_with_fixtures 506 ActiveRecord::Base.clear_connection_cache! 507 ensure 506 508 # Rollback changes. 507 509 if use_transactional_fixtures? trunk/railties/lib/dispatcher.rb
r3096 r3218 74 74 def reset_after_dispatch 75 75 reset_application! if Dependencies.load? 76 ActiveRecord::Base. mark_active_connections_for_verification!76 ActiveRecord::Base.clear_connection_cache! 77 77 Breakpoint.deactivate_drb if defined?(BREAKPOINT_SERVER_PORT) 78 78 end