Permalink
Browse files

Adapters keep in_use flag when leased

  • Loading branch information...
tenderlove committed Nov 29, 2011
1 parent 7837574 commit 9bf8bf82b9d8614d9c7ccc31892887f6a79ce2f5
@@ -4,6 +4,7 @@
require 'active_support/core_ext/benchmark'
require 'active_support/deprecation'
require 'active_record/connection_adapters/schema_cache'
+require 'monitor'
module ActiveRecord
module ConnectionAdapters # :nodoc:
@@ -48,13 +49,17 @@ class AbstractAdapter
include DatabaseLimits
include QueryCache
include ActiveSupport::Callbacks
+ include MonitorMixin
define_callbacks :checkout, :checkin
attr_accessor :visitor
- attr_reader :schema_cache
+ attr_reader :schema_cache, :last_use, :in_use
+ alias :in_use? :in_use
def initialize(connection, logger = nil) #:nodoc:
+ super()
+
@active = nil
@connection, @logger = connection, logger
@query_cache_enabled = false
@@ -63,6 +68,14 @@ def initialize(connection, logger = nil) #:nodoc:
@instrumenter = ActiveSupport::Notifications.instrumenter
@visitor = nil
@schema_cache = SchemaCache.new self
+ @in_use = false
+ end
+
+ def lease
+ synchronize do
+ @in_use = true
+ @last_use = Time.now
+ end
end
# Returns the human-readable name of the adapter. Use mixed case - one
@@ -0,0 +1,16 @@
+require "cases/helper"
+
+module ActiveRecord
+ module ConnectionAdapters
+ class AbstractAdapterTest < ActiveRecord::TestCase
+ def test_in_use?
+ adapter = AbstractAdapter.new nil, nil
+
+ # FIXME: change to refute in Rails 4.0 / mt
+ assert !adapter.in_use?, 'adapter is not in use'
+ assert adapter.lease, 'lease adapter'
+ assert adapter.in_use?, 'adapter is in use'
+ end
+ end
+ end
+end

0 comments on commit 9bf8bf8

Please sign in to comment.