From 78fcc5fd1aa5d32fcdf2336d7096249f19931341 Mon Sep 17 00:00:00 2001 From: Yves Senn Date: Mon, 30 Sep 2013 15:44:51 +0200 Subject: [PATCH] extract adapter savepoint implementations into `abstract/savepoints.rb`. --- .../abstract/savepoints.rb | 21 +++++++++++++++++++ .../connection_adapters/abstract_adapter.rb | 1 + .../abstract_mysql_adapter.rb | 19 ++--------------- .../postgresql/database_statements.rb | 12 ----------- .../connection_adapters/postgresql_adapter.rb | 6 +----- .../connection_adapters/sqlite3_adapter.rb | 14 ++----------- 6 files changed, 27 insertions(+), 46 deletions(-) create mode 100644 activerecord/lib/active_record/connection_adapters/abstract/savepoints.rb diff --git a/activerecord/lib/active_record/connection_adapters/abstract/savepoints.rb b/activerecord/lib/active_record/connection_adapters/abstract/savepoints.rb new file mode 100644 index 0000000000..25c17ce971 --- /dev/null +++ b/activerecord/lib/active_record/connection_adapters/abstract/savepoints.rb @@ -0,0 +1,21 @@ +module ActiveRecord + module ConnectionAdapters + module Savepoints #:nodoc: + def supports_savepoints? + true + end + + def create_savepoint(name = current_savepoint_name) + execute("SAVEPOINT #{name}") + end + + def rollback_to_savepoint(name = current_savepoint_name) + execute("ROLLBACK TO SAVEPOINT #{name}") + end + + def release_savepoint(name = current_savepoint_name) + execute("RELEASE SAVEPOINT #{name}") + end + end + end +end diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index f3e4601278..1e1a7323ee 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -33,6 +33,7 @@ module ActiveRecord autoload :Quoting autoload :ConnectionPool autoload :QueryCache + autoload :Savepoints end autoload_at 'active_record/connection_adapters/abstract/transaction' do diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index a73a480003..138ab811dc 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -3,6 +3,8 @@ require 'arel/visitors/bind_visitor' module ActiveRecord module ConnectionAdapters class AbstractMysqlAdapter < AbstractAdapter + include Savepoints + class SchemaCreation < AbstractAdapter::SchemaCreation def visit_AddColumn(o) @@ -194,11 +196,6 @@ module ActiveRecord true end - # Returns true, since this connection adapter supports savepoints. - def supports_savepoints? - true - end - def supports_bulk_alter? #:nodoc: true end @@ -340,18 +337,6 @@ module ActiveRecord # Transactions aren't supported end - def create_savepoint(name = current_savepoint_name) - execute("SAVEPOINT #{name}") - end - - def rollback_to_savepoint(name = current_savepoint_name) - execute("ROLLBACK TO SAVEPOINT #{name}") - end - - def release_savepoint(name = current_savepoint_name) - execute("RELEASE SAVEPOINT #{name}") - end - # In the simple case, MySQL allows us to place JOINs directly into the UPDATE # query. However, this does not allow for LIMIT, OFFSET and ORDER. To support # these, we must use a subquery. diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb index d9838467cd..f470d20372 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/database_statements.rb @@ -218,18 +218,6 @@ module ActiveRecord def rollback_db_transaction execute "ROLLBACK" end - - def create_savepoint(name = current_savepoint_name) - execute("SAVEPOINT #{name}") - end - - def rollback_to_savepoint(name = current_savepoint_name) - execute("ROLLBACK TO SAVEPOINT #{name}") - end - - def release_savepoint(name = current_savepoint_name) - execute("RELEASE SAVEPOINT #{name}") - end end end end diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index af240fab95..f35dda8ffa 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -430,6 +430,7 @@ module ActiveRecord include ReferentialIntegrity include SchemaStatements include DatabaseStatements + include Savepoints # Returns 'PostgreSQL' as adapter name for identification purposes. def adapter_name @@ -620,11 +621,6 @@ module ActiveRecord true end - # Returns true, since this connection adapter supports savepoints. - def supports_savepoints? - true - end - # Returns true. def supports_explain? true diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index 0863055caf..997384daea 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -53,6 +53,8 @@ module ActiveRecord # # * :database - Path to the database file. class SQLite3Adapter < AbstractAdapter + include Savepoints + class Version include Comparable @@ -351,18 +353,6 @@ module ActiveRecord exec_query(sql, name).rows end - def create_savepoint(name = current_savepoint_name) - execute("SAVEPOINT #{name}") - end - - def rollback_to_savepoint(name = current_savepoint_name) - execute("ROLLBACK TO SAVEPOINT #{name}") - end - - def release_savepoint(name = current_savepoint_name) - execute("RELEASE SAVEPOINT #{name}") - end - def begin_db_transaction #:nodoc: log('begin transaction',nil) { @connection.transaction } end