aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract_adapter.rb15
-rw-r--r--activerecord/test/cases/connection_adapters/abstract_adapter_test.rb16
2 files changed, 30 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
index 75e568b557..4a9653c08c 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
@@ -4,6 +4,7 @@ require 'bigdecimal/util'
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 @@ module ActiveRecord
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 @@ module ActiveRecord
@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
diff --git a/activerecord/test/cases/connection_adapters/abstract_adapter_test.rb b/activerecord/test/cases/connection_adapters/abstract_adapter_test.rb
new file mode 100644
index 0000000000..ef6a57d328
--- /dev/null
+++ b/activerecord/test/cases/connection_adapters/abstract_adapter_test.rb
@@ -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