Permalink
Browse files

r3847@asus: jeremy | 2006-02-26 15:26:53 -0800

 Apply [3674] to stable. Closes #3591.


git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/stable@3676 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
jeremy committed Feb 26, 2006
1 parent fba571a commit ec20838381dc26b68142c84c0e03f523765b4aae
View
@@ -1,5 +1,7 @@
*SVN*
* ActiveRecord::Base.remove_connection explicitly closes database connections and doesn't corrupt the connection cache. Introducing the disconnect! instance method for the PostgreSQL, MySQL, and SQL Server adapters; implementations for the others are welcome. #3591 [Simon Stapleton, Tom Ward]
* PostgreSQL: correctly parse negative integer column defaults. #3776 [bellis@deepthought.org]
* Show a meaningful error when the DB2 adapter cannot be loaded due to missing dependencies. [Nicholas Seckar]
@@ -129,12 +129,13 @@ def self.connected?
# can be used as argument for establish_connection, for easy
# re-establishing of the connection.
def self.remove_connection(klass=self)
conn = @@defined_connections[klass.name]
@@defined_connections.delete(klass.name)
@@connection_cache[Thread.current.object_id].delete(klass.name)
active_connections.delete(klass.name)
@connection = nil
conn.config if conn
spec = @@defined_connections[klass.name]
konn = active_connections[klass.name]
@@defined_connections.delete_if { |key, value| value == spec }
@@connection_cache[Thread.current.object_id].delete_if { |key, value| value == konn }
active_connections.delete_if { |key, value| value == konn }
konn.disconnect! if konn
spec.config if spec
end
# Set the connection for the class.
@@ -57,11 +57,17 @@ def reset_runtime #:nodoc:
# Is this connection active and ready to perform queries?
def active?
true
@active != false
end
# Close this connection and open a new one in its place.
def reconnect!
@active = true
end
# Close this connection
def disconnect!
@active = false
end
@@ -160,9 +160,13 @@ def active?
end
def reconnect!
@connection.close rescue nil
disconnect!
connect
end
def disconnect!
@connection.close rescue nil
end
# DATABASE STATEMENTS ======================================
@@ -75,6 +75,11 @@ def reconnect!
configure_connection
end
end
def disconnect!
# Both postgres and postgres-pr respond to :close
@connection.close rescue nil
end
def native_database_types
{
@@ -216,12 +216,18 @@ def active?
# Reconnects to the database, returns false if no connection could be made.
def reconnect!
@connection.disconnect rescue nil
disconnect!
@connection = DBI.connect(*@connection_options)
rescue DBI::DatabaseError => e
@logger.warn "#{adapter_name} reconnection failed: #{e.message}" if @logger
false
end
# Disconnects from the database
def disconnect!
@connection.disconnect rescue nil
end
def select_all(sql, name = nil)
select(sql, name)
@@ -7,19 +7,26 @@ class TestUnconnectedAdaptor < Test::Unit::TestCase
self.use_transactional_fixtures = false
def setup
@connection = ActiveRecord::Base.remove_connection
@underlying = ActiveRecord::Base.connection
@specification = ActiveRecord::Base.remove_connection
end
def teardown
ActiveRecord::Base.establish_connection(@connection)
@underlying = nil
ActiveRecord::Base.establish_connection(@specification)
end
def test_unconnected
def test_connection_no_longer_established
assert_raise(ActiveRecord::ConnectionNotEstablished) do
TestRecord.find(1)
TestRecord.find(1)
end
assert_raise(ActiveRecord::ConnectionNotEstablished) do
TestRecord.new.save
TestRecord.new.save
end
end
def test_underlying_adapter_no_longer_active
assert !@underlying.active?, "Removed adapter should no longer be active"
end
end

0 comments on commit ec20838

Please sign in to comment.