activerecord-jdbc-adapter 1.3.0.beta2 → 1.3.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +14 -8
- data/.travis.yml +40 -31
- data/.yardopts +4 -0
- data/Appraisals +2 -5
- data/CONTRIBUTING.md +46 -0
- data/Gemfile +21 -4
- data/Gemfile.lock +42 -17
- data/{History.txt → History.md} +142 -75
- data/README.md +102 -104
- data/RUNNING_TESTS.md +76 -0
- data/Rakefile.jdbc +20 -0
- data/activerecord-jdbc-adapter.gemspec +35 -18
- data/gemfiles/rails23.gemfile +4 -3
- data/gemfiles/rails23.gemfile.lock +9 -6
- data/gemfiles/rails30.gemfile +4 -3
- data/gemfiles/rails30.gemfile.lock +9 -6
- data/gemfiles/rails31.gemfile +4 -3
- data/gemfiles/rails31.gemfile.lock +9 -6
- data/gemfiles/rails32.gemfile +4 -3
- data/gemfiles/rails32.gemfile.lock +17 -14
- data/gemfiles/rails40.gemfile +5 -5
- data/gemfiles/rails40.gemfile.lock +17 -69
- data/lib/active_record/connection_adapters/firebird_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +1 -0
- data/lib/arel/visitors/compat.rb +22 -3
- data/lib/arel/visitors/db2.rb +8 -4
- data/lib/arel/visitors/derby.rb +14 -13
- data/lib/arel/visitors/firebird.rb +5 -4
- data/lib/arel/visitors/hsqldb.rb +11 -9
- data/lib/arel/visitors/sql_server.rb +89 -61
- data/lib/arjdbc.rb +1 -1
- data/lib/arjdbc/db2/adapter.rb +181 -212
- data/lib/arjdbc/db2/as400.rb +31 -18
- data/lib/arjdbc/db2/column.rb +167 -0
- data/lib/arjdbc/db2/connection_methods.rb +2 -0
- data/lib/arjdbc/derby/adapter.rb +206 -107
- data/lib/arjdbc/derby/connection_methods.rb +4 -9
- data/lib/arjdbc/firebird.rb +1 -0
- data/lib/arjdbc/firebird/adapter.rb +202 -64
- data/lib/arjdbc/firebird/connection_methods.rb +20 -0
- data/lib/arjdbc/h2/adapter.rb +56 -36
- data/lib/arjdbc/hsqldb/adapter.rb +99 -68
- data/lib/arjdbc/jdbc/adapter.rb +474 -265
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/adapter_require.rb +8 -7
- data/lib/arjdbc/jdbc/arel_support.rb +132 -0
- data/lib/arjdbc/jdbc/base_ext.rb +8 -7
- data/lib/arjdbc/jdbc/callbacks.rb +16 -10
- data/lib/arjdbc/jdbc/column.rb +25 -3
- data/lib/arjdbc/jdbc/connection.rb +28 -55
- data/lib/arjdbc/jdbc/extension.rb +14 -14
- data/lib/arjdbc/jdbc/java.rb +6 -3
- data/lib/arjdbc/jdbc/jdbc.rake +1 -1
- data/lib/arjdbc/jdbc/quoted_primary_key.rb +2 -2
- data/lib/arjdbc/jdbc/rake_tasks.rb +1 -1
- data/lib/arjdbc/jdbc/type_converter.rb +5 -2
- data/lib/arjdbc/mssql/adapter.rb +160 -280
- data/lib/arjdbc/mssql/column.rb +182 -0
- data/lib/arjdbc/mssql/connection_methods.rb +37 -4
- data/lib/arjdbc/mssql/explain_support.rb +13 -21
- data/lib/arjdbc/mssql/limit_helpers.rb +79 -42
- data/lib/arjdbc/mssql/lock_methods.rb +77 -0
- data/lib/arjdbc/mssql/utils.rb +11 -11
- data/lib/arjdbc/mysql/adapter.rb +165 -247
- data/lib/arjdbc/mysql/column.rb +123 -0
- data/lib/arjdbc/mysql/connection_methods.rb +3 -6
- data/lib/arjdbc/oracle/adapter.rb +282 -288
- data/lib/arjdbc/oracle/column.rb +122 -0
- data/lib/arjdbc/oracle/connection_methods.rb +3 -0
- data/lib/arjdbc/postgresql/adapter.rb +336 -574
- data/lib/arjdbc/postgresql/column.rb +458 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +1 -2
- data/lib/arjdbc/postgresql/schema_creation.rb +38 -0
- data/lib/arjdbc/sqlite3/adapter.rb +189 -145
- data/lib/arjdbc/sqlite3/explain_support.rb +1 -1
- data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +8 -8
- data/lib/arjdbc/util/quoted_cache.rb +60 -0
- data/lib/arjdbc/util/table_copier.rb +110 -0
- data/lib/arjdbc/version.rb +6 -7
- data/pom.xml +56 -2
- data/rakelib/02-test.rake +72 -83
- data/rakelib/db.rake +29 -17
- data/src/java/arjdbc/ArJdbcModule.java +21 -18
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +84 -12
- data/src/java/arjdbc/derby/DerbyModule.java +140 -143
- data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +58 -7
- data/src/java/arjdbc/h2/H2Module.java +43 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +7 -6
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +1223 -648
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +24 -23
- data/src/java/arjdbc/mysql/MySQLModule.java +33 -32
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +147 -30
- data/src/java/arjdbc/oracle/OracleModule.java +13 -13
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +114 -6
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +166 -36
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +101 -19
- data/src/java/arjdbc/util/QuotingUtils.java +19 -19
- metadata +240 -394
- data/bench/bench_attributes.rb +0 -13
- data/bench/bench_attributes_new.rb +0 -14
- data/bench/bench_create.rb +0 -12
- data/bench/bench_find_all.rb +0 -12
- data/bench/bench_find_all_mt.rb +0 -25
- data/bench/bench_model.rb +0 -85
- data/bench/bench_new.rb +0 -12
- data/bench/bench_new_valid.rb +0 -12
- data/bench/bench_valid.rb +0 -13
- data/lib/arel/engines/sql/compilers/db2_compiler.rb +0 -9
- data/lib/arel/engines/sql/compilers/derby_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/h2_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/hsqldb_compiler.rb +0 -15
- data/lib/arel/engines/sql/compilers/jdbc_compiler.rb +0 -6
- data/lib/arel/engines/sql/compilers/mssql_compiler.rb +0 -46
- data/lib/arjdbc/jdbc/missing_functionality_helper.rb +0 -98
- data/lib/arjdbc/mssql/lock_helpers.rb +0 -76
- data/lib/arjdbc/mssql/tsql_methods.rb +0 -58
- data/lib/arjdbc/postgresql/column_cast.rb +0 -134
- data/test/activerecord/connections/native_jdbc_mysql/connection.rb +0 -25
- data/test/activerecord/jall.sh +0 -7
- data/test/activerecord/jtest.sh +0 -3
- data/test/assets/flowers.jpg +0 -0
- data/test/binary.rb +0 -67
- data/test/db/db2.rb +0 -43
- data/test/db/db2/binary_test.rb +0 -6
- data/test/db/db2/has_many_through_test.rb +0 -6
- data/test/db/db2/rake_test.rb +0 -82
- data/test/db/db2/rake_test_data.sql +0 -35
- data/test/db/db2/reset_column_information_test.rb +0 -5
- data/test/db/db2/serialize_test.rb +0 -6
- data/test/db/db2/simple_test.rb +0 -81
- data/test/db/db2/test_helper.rb +0 -6
- data/test/db/db2/unit_test.rb +0 -73
- data/test/db/derby.rb +0 -12
- data/test/db/derby/binary_test.rb +0 -6
- data/test/db/derby/migration_test.rb +0 -74
- data/test/db/derby/rake_test.rb +0 -96
- data/test/db/derby/reset_column_information_test.rb +0 -6
- data/test/db/derby/row_locking_test.rb +0 -20
- data/test/db/derby/schema_dump_test.rb +0 -5
- data/test/db/derby/serialize_test.rb +0 -6
- data/test/db/derby/simple_test.rb +0 -173
- data/test/db/derby/test_helper.rb +0 -6
- data/test/db/derby/unit_test.rb +0 -32
- data/test/db/derby/xml_column_test.rb +0 -17
- data/test/db/h2.rb +0 -11
- data/test/db/h2/binary_test.rb +0 -6
- data/test/db/h2/change_column_test.rb +0 -68
- data/test/db/h2/identity_column_test.rb +0 -35
- data/test/db/h2/offset_test.rb +0 -49
- data/test/db/h2/rake_test.rb +0 -98
- data/test/db/h2/schema_dump_test.rb +0 -29
- data/test/db/h2/serialize_test.rb +0 -6
- data/test/db/h2/simple_test.rb +0 -56
- data/test/db/hsqldb.rb +0 -11
- data/test/db/hsqldb/binary_test.rb +0 -6
- data/test/db/hsqldb/rake_test.rb +0 -101
- data/test/db/hsqldb/schema_dump_test.rb +0 -19
- data/test/db/hsqldb/serialize_test.rb +0 -6
- data/test/db/hsqldb/simple_test.rb +0 -17
- data/test/db/informix.rb +0 -13
- data/test/db/jdbc.rb +0 -16
- data/test/db/jdbc_derby.rb +0 -14
- data/test/db/jdbc_h2.rb +0 -17
- data/test/db/jdbc_mysql.rb +0 -13
- data/test/db/jdbc_postgres.rb +0 -23
- data/test/db/jndi_config.rb +0 -32
- data/test/db/jndi_pooled_config.rb +0 -32
- data/test/db/mssql.rb +0 -11
- data/test/db/mssql/binary_test.rb +0 -6
- data/test/db/mssql/exec_proc_test.rb +0 -46
- data/test/db/mssql/identity_insert_test.rb +0 -18
- data/test/db/mssql/ignore_system_views_test.rb +0 -40
- data/test/db/mssql/limit_offset_test.rb +0 -190
- data/test/db/mssql/multibyte_test.rb +0 -16
- data/test/db/mssql/multiple_connections_test.rb +0 -71
- data/test/db/mssql/rake_test.rb +0 -143
- data/test/db/mssql/reset_column_information_test.rb +0 -6
- data/test/db/mssql/row_locking_test.rb +0 -7
- data/test/db/mssql/serialize_test.rb +0 -6
- data/test/db/mssql/simple_test.rb +0 -140
- data/test/db/mssql/transaction_test.rb +0 -6
- data/test/db/mssql/types_test.rb +0 -205
- data/test/db/mssql/unit_test.rb +0 -249
- data/test/db/mysql.rb +0 -4
- data/test/db/mysql/_rails_test_mysql.32.out +0 -6585
- data/test/db/mysql/binary_test.rb +0 -6
- data/test/db/mysql/connection_test.rb +0 -51
- data/test/db/mysql/index_length_test.rb +0 -58
- data/test/db/mysql/multibyte_test.rb +0 -10
- data/test/db/mysql/nonstandard_primary_key_test.rb +0 -39
- data/test/db/mysql/rake_test.rb +0 -97
- data/test/db/mysql/reset_column_information_test.rb +0 -6
- data/test/db/mysql/schema_dump_test.rb +0 -228
- data/test/db/mysql/serialize_test.rb +0 -6
- data/test/db/mysql/simple_test.rb +0 -187
- data/test/db/mysql/statement_escaping_test.rb +0 -46
- data/test/db/mysql/transaction_test.rb +0 -6
- data/test/db/mysql/types_test.rb +0 -30
- data/test/db/mysql/unit_test.rb +0 -93
- data/test/db/mysql_config.rb +0 -7
- data/test/db/oracle.rb +0 -27
- data/test/db/oracle/binary_test.rb +0 -6
- data/test/db/oracle/limit_test.rb +0 -24
- data/test/db/oracle/multibyte_test.rb +0 -22
- data/test/db/oracle/rake_test.rb +0 -100
- data/test/db/oracle/reset_column_information_test.rb +0 -6
- data/test/db/oracle/serialize_test.rb +0 -6
- data/test/db/oracle/simple_test.rb +0 -140
- data/test/db/oracle/specific_test.rb +0 -180
- data/test/db/oracle/transaction_test.rb +0 -31
- data/test/db/oracle/unit_test.rb +0 -31
- data/test/db/postgres.rb +0 -11
- data/test/db/postgres/_rails_test_postgres.32.out +0 -6405
- data/test/db/postgres/a_custom_primary_key_test.rb +0 -50
- data/test/db/postgres/active_schema_unit_test.rb +0 -68
- data/test/db/postgres/array_type_test.rb +0 -101
- data/test/db/postgres/binary_test.rb +0 -6
- data/test/db/postgres/connection_test.rb +0 -63
- data/test/db/postgres/data_types_test.rb +0 -703
- data/test/db/postgres/hstore_test.rb +0 -200
- data/test/db/postgres/information_schema_leak_test.rb +0 -30
- data/test/db/postgres/json_test.rb +0 -86
- data/test/db/postgres/ltree_test.rb +0 -51
- data/test/db/postgres/mixed_case_test.rb +0 -29
- data/test/db/postgres/native_types_test.rb +0 -124
- data/test/db/postgres/rake_test.rb +0 -117
- data/test/db/postgres/reserved_test.rb +0 -22
- data/test/db/postgres/reset_column_information_test.rb +0 -6
- data/test/db/postgres/row_locking_test.rb +0 -21
- data/test/db/postgres/schema_dump_test.rb +0 -95
- data/test/db/postgres/schema_test.rb +0 -115
- data/test/db/postgres/simple_test.rb +0 -260
- data/test/db/postgres/table_alias_length_test.rb +0 -16
- data/test/db/postgres/transaction_test.rb +0 -6
- data/test/db/postgres/unit_test.rb +0 -31
- data/test/db/postgres_config.rb +0 -10
- data/test/db/sqlite3.rb +0 -6
- data/test/db/sqlite3/_rails_test_sqlite3.32.out +0 -6274
- data/test/db/sqlite3/has_many_though_test.rb +0 -6
- data/test/db/sqlite3/rake_test.rb +0 -71
- data/test/db/sqlite3/reset_column_information_test.rb +0 -6
- data/test/db/sqlite3/schema_dump_test.rb +0 -6
- data/test/db/sqlite3/serialize_test.rb +0 -6
- data/test/db/sqlite3/simple_test.rb +0 -268
- data/test/db/sqlite3/transaction_test.rb +0 -32
- data/test/db/sqlite3/type_conversion_test.rb +0 -104
- data/test/has_many_through.rb +0 -61
- data/test/informix_simple_test.rb +0 -48
- data/test/jdbc/db2.rb +0 -36
- data/test/jdbc/oracle.rb +0 -34
- data/test/jdbc_column_test.rb +0 -23
- data/test/jdbc_common.rb +0 -16
- data/test/jdbc_connection_test.rb +0 -196
- data/test/jndi_callbacks_test.rb +0 -33
- data/test/jndi_test.rb +0 -55
- data/test/manualTestDatabase.rb +0 -191
- data/test/models/add_not_null_column_to_table.rb +0 -9
- data/test/models/auto_id.rb +0 -15
- data/test/models/binary.rb +0 -18
- data/test/models/custom_pk_name.rb +0 -15
- data/test/models/data_types.rb +0 -40
- data/test/models/entry.rb +0 -41
- data/test/models/mixed_case.rb +0 -22
- data/test/models/reserved_word.rb +0 -15
- data/test/models/rights_and_roles.rb +0 -57
- data/test/models/string_id.rb +0 -17
- data/test/models/thing.rb +0 -17
- data/test/models/topic.rb +0 -32
- data/test/models/validates_uniqueness_of_string.rb +0 -19
- data/test/rails/mysql.rb +0 -13
- data/test/rails/sqlite3/version.rb +0 -6
- data/test/rails_stub.rb +0 -31
- data/test/rake_test_support.rb +0 -298
- data/test/row_locking.rb +0 -102
- data/test/schema_dump.rb +0 -182
- data/test/serialize.rb +0 -275
- data/test/shared_helper.rb +0 -35
- data/test/simple.rb +0 -1317
- data/test/sybase_jtds_simple_test.rb +0 -28
- data/test/sybase_reset_column_information_test.rb +0 -6
- data/test/test_helper.rb +0 -304
- data/test/transaction.rb +0 -109
data/test/models/string_id.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
class CreateStringIds < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
create_table "string_ids", :force => true, :id => false do |t|
|
4
|
-
t.string :id, :null => false
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.down
|
9
|
-
drop_table "string_ids"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class StringId < ActiveRecord::Base
|
14
|
-
def self.table_name; "string_ids"; end
|
15
|
-
# Fake out a table without a primary key
|
16
|
-
self.primary_key = "id"
|
17
|
-
end
|
data/test/models/thing.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
class CreateThings < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
create_table :things, :id => false do |t|
|
4
|
-
t.string :name
|
5
|
-
t.timestamps
|
6
|
-
end
|
7
|
-
add_index :things, :name, :unique => true
|
8
|
-
add_index :things, :created_at, :where => 'name IS NOT NULL', :name => "thing_partial_index"
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.down
|
12
|
-
drop_table :things
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
class Thing < ActiveRecord::Base
|
17
|
-
end
|
data/test/models/topic.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
class Topic < ActiveRecord::Base
|
2
|
-
serialize :content
|
3
|
-
end
|
4
|
-
|
5
|
-
class ImportantTopic < Topic
|
6
|
-
serialize :important, Hash
|
7
|
-
end
|
8
|
-
|
9
|
-
class TopicMigration < ActiveRecord::Migration
|
10
|
-
|
11
|
-
def self.up
|
12
|
-
create_table :topics, :force => true do |t|
|
13
|
-
t.string :title
|
14
|
-
# use VARCHAR2(4000) instead of CLOB datatype as CLOB data type has many limitations in
|
15
|
-
# Oracle SELECT WHERE clause which causes many unit test failures
|
16
|
-
#if current_adapter?(:OracleAdapter)
|
17
|
-
#t.string :content, :limit => 4000
|
18
|
-
#t.string :important, :limit => 4000
|
19
|
-
#else
|
20
|
-
t.text :content
|
21
|
-
t.text :important
|
22
|
-
#end
|
23
|
-
t.string :type
|
24
|
-
t.timestamps
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.down
|
29
|
-
drop_table :topics
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
class CreateValidatesUniquenessOf < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
create_table "validates_uniqueness_of", :force => true do |t|
|
4
|
-
t.column :cs_string, :string
|
5
|
-
t.column :ci_string, :string
|
6
|
-
t.column :content, :text
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.down
|
11
|
-
drop_table "validates_uniqueness_of"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
class ValidatesUniquenessOfString < ActiveRecord::Base
|
16
|
-
self.table_name = "validates_uniqueness_of"
|
17
|
-
validates_uniqueness_of :cs_string, :case_sensitive => true
|
18
|
-
validates_uniqueness_of :ci_string, :case_sensitive => false
|
19
|
-
end
|
data/test/rails/mysql.rb
DELETED
data/test/rails_stub.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
|
3
|
-
module Rails
|
4
|
-
class Configuration; end unless const_defined?(:Configuration)
|
5
|
-
Configuration.class_eval do
|
6
|
-
def root
|
7
|
-
defined?(RAILS_ROOT) ? Pathname.new(RAILS_ROOT).realpath : raise("Rails.root not set")
|
8
|
-
end
|
9
|
-
end
|
10
|
-
class Application
|
11
|
-
def self.config
|
12
|
-
@config ||= Configuration.new
|
13
|
-
end
|
14
|
-
def self.paths
|
15
|
-
@paths ||= Hash.new { [] }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
def self.application
|
19
|
-
Rails::Application
|
20
|
-
end
|
21
|
-
def self.configuration
|
22
|
-
application.config
|
23
|
-
end
|
24
|
-
def self.root
|
25
|
-
application && application.config.root
|
26
|
-
end
|
27
|
-
def self.env
|
28
|
-
env = defined?(RAILS_ENV) ? RAILS_ENV : ( ENV["RAILS_ENV"] || "development" )
|
29
|
-
ActiveSupport::StringInquirer.new(env)
|
30
|
-
end
|
31
|
-
end
|
data/test/rake_test_support.rb
DELETED
@@ -1,298 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'pathname'
|
3
|
-
require 'stringio'
|
4
|
-
|
5
|
-
module RakeTestSupport
|
6
|
-
|
7
|
-
def self.included(base)
|
8
|
-
require 'rake'
|
9
|
-
base.module_eval { include Rake::DSL } # if defined?(Rake::DSL)
|
10
|
-
base.extend ClassMethods
|
11
|
-
end
|
12
|
-
|
13
|
-
module ClassMethods
|
14
|
-
|
15
|
-
def startup
|
16
|
-
super
|
17
|
-
load 'rails_stub.rb'
|
18
|
-
end
|
19
|
-
|
20
|
-
def shutdown
|
21
|
-
Object.send(:remove_const, :Rails)
|
22
|
-
super
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
def setup
|
28
|
-
@_prev_application = Rake.application
|
29
|
-
@_prev_configurations = ActiveRecord::Base.configurations
|
30
|
-
@_prev_connection_config = current_connection_config
|
31
|
-
db_config # if not re-defined initialize from current connection's config
|
32
|
-
|
33
|
-
@db_name = db_name unless @db_name ||= nil
|
34
|
-
@rails_env = rails_env unless @rails_env ||= nil
|
35
|
-
|
36
|
-
setup_rails
|
37
|
-
set_rails_env(@rails_env)
|
38
|
-
set_rails_root(".")
|
39
|
-
|
40
|
-
Rake.application = new_application
|
41
|
-
ActiveRecord::Base.connection.disconnect!
|
42
|
-
|
43
|
-
verbose(true)
|
44
|
-
|
45
|
-
load_tasks
|
46
|
-
|
47
|
-
do_setup
|
48
|
-
end
|
49
|
-
|
50
|
-
def do_setup
|
51
|
-
end
|
52
|
-
|
53
|
-
RAILS_4x = ActiveRecord::VERSION::MAJOR >= 4
|
54
|
-
|
55
|
-
def load_tasks
|
56
|
-
if ActiveRecord::VERSION::MAJOR >= 3
|
57
|
-
load "active_record/railties/databases.rake"
|
58
|
-
else # we still support AR-2.3
|
59
|
-
load "tasks/databases.rake" # from rails/railties
|
60
|
-
end
|
61
|
-
load 'arjdbc/tasks.rb' if defined?(JRUBY_VERSION)
|
62
|
-
|
63
|
-
namespace :db do
|
64
|
-
task :load_config do
|
65
|
-
# 4.0 :
|
66
|
-
# ActiveRecord::Base.configurations = ActiveRecord::Tasks::DatabaseTasks.database_configuration || {}
|
67
|
-
# ActiveRecord::Migrator.migrations_paths = ActiveRecord::Tasks::DatabaseTasks.migrations_paths
|
68
|
-
# 3.2 :
|
69
|
-
# ActiveRecord::Base.configurations = Rails.application.config.database_configuration
|
70
|
-
# ActiveRecord::Migrator.migrations_paths = Rails.application.paths['db/migrate'].to_a
|
71
|
-
# 2.3 :
|
72
|
-
# ActiveRecord::Base.configurations = Rails::Configuration.new.database_configuration
|
73
|
-
ActiveRecord::Base.configurations = configurations
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
task :environment do
|
78
|
-
ActiveRecord::Base.configurations = configurations
|
79
|
-
ActiveRecord::Base.establish_connection @rails_env
|
80
|
-
@full_env_loaded = true
|
81
|
-
end
|
82
|
-
|
83
|
-
if RAILS_4x
|
84
|
-
ActiveRecord::Tasks::DatabaseTasks.env = @rails_env
|
85
|
-
ActiveRecord::Tasks::DatabaseTasks.db_dir = 'db'
|
86
|
-
else
|
87
|
-
task(:rails_env) { @rails_env_set = true }
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def teardown
|
92
|
-
verify_and_restore_stdout
|
93
|
-
error = nil
|
94
|
-
begin
|
95
|
-
do_teardown
|
96
|
-
rescue => e
|
97
|
-
error = e
|
98
|
-
end
|
99
|
-
Rake.application = @_prev_application
|
100
|
-
restore_rails
|
101
|
-
ActiveRecord::Base.configurations = @_prev_configurations
|
102
|
-
ActiveRecord::Base.establish_connection @_prev_connection_config
|
103
|
-
@rails_env_set = nil
|
104
|
-
@full_env_loaded = nil
|
105
|
-
raise error if error
|
106
|
-
end
|
107
|
-
|
108
|
-
def do_teardown
|
109
|
-
end
|
110
|
-
|
111
|
-
def new_application
|
112
|
-
Rake::Application.new
|
113
|
-
end
|
114
|
-
|
115
|
-
# (Test) Helpers :
|
116
|
-
|
117
|
-
def create_schema_migrations_table(connection = ActiveRecord::Base.connection)
|
118
|
-
schema_migration = ActiveRecord::Migrator.schema_migrations_table_name
|
119
|
-
return if connection.table_exists?(schema_migration)
|
120
|
-
connection.create_table(schema_migration, :id => false) do |t|
|
121
|
-
t.column :version, :string, :null => false
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
def create_rake_test_database
|
126
|
-
ActiveRecord::Base.establish_connection db_config
|
127
|
-
connection = ActiveRecord::Base.connection
|
128
|
-
connection.create_database(db_name, db_config) if connection.respond_to?(:create_database)
|
129
|
-
if block_given?
|
130
|
-
if db_name
|
131
|
-
config = db_config.merge :database => db_name
|
132
|
-
ActiveRecord::Base.establish_connection config
|
133
|
-
end
|
134
|
-
yield ActiveRecord::Base.connection
|
135
|
-
end
|
136
|
-
ActiveRecord::Base.connection.disconnect!
|
137
|
-
end
|
138
|
-
|
139
|
-
def drop_rake_test_database(silence = false)
|
140
|
-
ActiveRecord::Base.establish_connection db_config
|
141
|
-
begin
|
142
|
-
ActiveRecord::Base.connection.drop_database(db_name)
|
143
|
-
rescue => e
|
144
|
-
raise e unless silence
|
145
|
-
end
|
146
|
-
ActiveRecord::Base.connection.disconnect!
|
147
|
-
end
|
148
|
-
|
149
|
-
def structure_sql_filename
|
150
|
-
ar_version('3.2') ? 'structure.sql' : "#{@rails_env}_structure.sql"
|
151
|
-
end
|
152
|
-
|
153
|
-
def expect_rake_output(matcher)
|
154
|
-
@_stdout, @_stdout_matcher = $stdout, matcher
|
155
|
-
$stdout = StringIO.new
|
156
|
-
end
|
157
|
-
|
158
|
-
def verify_and_restore_stdout
|
159
|
-
if @_stdout ||= nil
|
160
|
-
_stdout = $stdout
|
161
|
-
$stdout = @_stdout
|
162
|
-
|
163
|
-
output = _stdout.string
|
164
|
-
if @_stdout_matcher.is_a?(String)
|
165
|
-
unless @_stdout_matcher.index("\n")
|
166
|
-
output = output.rstrip
|
167
|
-
end
|
168
|
-
assert_equal @_stdout_matcher, output
|
169
|
-
else
|
170
|
-
assert_match @_stdout_matcher, output
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
private :verify_and_restore_stdout
|
175
|
-
|
176
|
-
def rails_env
|
177
|
-
'unittest'
|
178
|
-
end
|
179
|
-
|
180
|
-
def db_name
|
181
|
-
'test_rake_db'
|
182
|
-
end
|
183
|
-
|
184
|
-
@@db_config = nil
|
185
|
-
|
186
|
-
def db_config
|
187
|
-
@@db_config ||= current_connection_config.reject { |key, val| val && key.to_s == 'url' }
|
188
|
-
end
|
189
|
-
|
190
|
-
def current_connection_config
|
191
|
-
if ActiveRecord::Base.respond_to?(:connection_config)
|
192
|
-
ActiveRecord::Base.connection_config
|
193
|
-
else
|
194
|
-
ActiveRecord::Base.connection_pool.spec.config
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
def configurations
|
199
|
-
@configurations ||= begin
|
200
|
-
db_config = self.db_config.dup
|
201
|
-
db_config.merge!(:database => @db_name) if @db_name ||= nil
|
202
|
-
db_config.stringify_keys!
|
203
|
-
raise "Rails.env not set" unless @rails_env ||= nil
|
204
|
-
configurations = { @rails_env => db_config }
|
205
|
-
configurations['test'] = db_config.dup
|
206
|
-
configurations
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
private
|
211
|
-
|
212
|
-
RAILS_2x = ActiveRecord::VERSION::MAJOR < 3
|
213
|
-
|
214
|
-
def setup_rails
|
215
|
-
RAILS_2x ? setup_rails2 : setup_rails3
|
216
|
-
end
|
217
|
-
|
218
|
-
def setup_rails2
|
219
|
-
test = self
|
220
|
-
Rails::Configuration.module_eval do
|
221
|
-
define_method(:database_configuration) { test.configurations }
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
def setup_rails3
|
226
|
-
test = self
|
227
|
-
(class << Rails::Application.config; self ; end).instance_eval do
|
228
|
-
define_method(:database_configuration) { test.configurations }
|
229
|
-
end
|
230
|
-
end
|
231
|
-
|
232
|
-
def set_rails_env(env); set_rails_constant("env", env); end
|
233
|
-
|
234
|
-
def set_rails_root(root = '.'); set_rails_constant("root", root); end
|
235
|
-
|
236
|
-
NO_VALUE = Java::JavaLang::Void rescue NilClass
|
237
|
-
|
238
|
-
def set_rails_constant(name, value)
|
239
|
-
name = name.to_s
|
240
|
-
|
241
|
-
@rails_constants ||= {}
|
242
|
-
begin
|
243
|
-
@rails_constants[name] = Object.const_get(rails_constant_name(name))
|
244
|
-
rescue NameError
|
245
|
-
@rails_constants[name] = NO_VALUE
|
246
|
-
end
|
247
|
-
silence_warnings { Object.const_set(rails_constant_name(name), value) } if RAILS_2x
|
248
|
-
|
249
|
-
case name
|
250
|
-
when 'env'
|
251
|
-
unless value.is_a?(ActiveSupport::StringInquirer)
|
252
|
-
value = ActiveSupport::StringInquirer.new(value)
|
253
|
-
end
|
254
|
-
when 'root'
|
255
|
-
unless value.is_a?(Pathname)
|
256
|
-
value = Pathname.new(value).realpath
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
Rails.instance_eval do
|
261
|
-
if methods(false).map(&:to_s).include?(name)
|
262
|
-
singleton_class = (class << self; self; end)
|
263
|
-
singleton_class.send(:alias_method, "orig_#{name}", name)
|
264
|
-
singleton_class.send(:define_method, name) { value }
|
265
|
-
end
|
266
|
-
end
|
267
|
-
end
|
268
|
-
|
269
|
-
def restore_rails
|
270
|
-
( @rails_constants ||= {} ).each do |name, value|
|
271
|
-
|
272
|
-
if value == NO_VALUE
|
273
|
-
Object.send(:remove_const, rails_constant_name(name)) if RAILS_2x
|
274
|
-
else
|
275
|
-
silence_warnings { Object.const_set(rails_constant_name(name), value) }
|
276
|
-
end
|
277
|
-
|
278
|
-
Rails.instance_eval do
|
279
|
-
if methods(false).map(&:to_s).include?(name)
|
280
|
-
singleton_class = (class << self; self; end)
|
281
|
-
singleton_class.send :remove_method, name
|
282
|
-
singleton_class.send :alias_method, name, "orig_#{name}"
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
def rails_constant_name(name); "RAILS_#{name.upcase}"; end
|
290
|
-
|
291
|
-
def silence_warnings
|
292
|
-
prev, $VERBOSE = $VERBOSE, nil
|
293
|
-
yield
|
294
|
-
ensure
|
295
|
-
$VERBOSE = prev
|
296
|
-
end
|
297
|
-
|
298
|
-
end
|
data/test/row_locking.rb
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'thread'
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
require 'models/entry'
|
5
|
-
|
6
|
-
module RowLockingTestMethods
|
7
|
-
|
8
|
-
# Simple SELECT ... FOR UPDATE test
|
9
|
-
def test_select_all_for_update
|
10
|
-
@row1_id = Entry.create!(:title => "row1").id
|
11
|
-
all_locked = Entry.lock(true)
|
12
|
-
all_locked_ids = all_locked.all.map { |row| row.id }
|
13
|
-
assert all_locked_ids.include?(@row1_id)
|
14
|
-
end if Test::Unit::TestCase.ar_version('3.0')
|
15
|
-
|
16
|
-
def test_row_locking
|
17
|
-
row_locking_test_template
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_row_locking_with_limit
|
21
|
-
row_locking_test_template(:limit => 1)
|
22
|
-
end
|
23
|
-
|
24
|
-
protected
|
25
|
-
|
26
|
-
def row_locking_test_template(options={})
|
27
|
-
# Create two rows that we will work with
|
28
|
-
@row1_id = Entry.create!(:title => "row1").id
|
29
|
-
@row2_id = Entry.create!(:title => "row2").id
|
30
|
-
|
31
|
-
@result_queue = Queue.new
|
32
|
-
signal_queue = Queue.new
|
33
|
-
t1 = Thread.new { thread_helper { thread1_main(signal_queue, options) } }
|
34
|
-
t2 = Thread.new { thread_helper { thread2_main(signal_queue, options) } }
|
35
|
-
t1.join
|
36
|
-
t2.join
|
37
|
-
|
38
|
-
result = []
|
39
|
-
result << @result_queue.shift until @result_queue.empty? # Convert the queue into an array
|
40
|
-
|
41
|
-
expected = [
|
42
|
-
:t1_locking_row2,
|
43
|
-
:t1_locked_row2,
|
44
|
-
|
45
|
-
:t2_locking_row1,
|
46
|
-
:t2_locked_row1,
|
47
|
-
|
48
|
-
:t2_locking_row2, # thread 2 tries to lock row2 ...
|
49
|
-
:t1_committed,
|
50
|
-
:t2_locked_row2, # ... but it doesn't succeed until after thread 1 commits its transaction
|
51
|
-
|
52
|
-
:t2_committed,
|
53
|
-
]
|
54
|
-
|
55
|
-
assert_equal expected, result, "thread2 should lock row1 immediately but wait for thread1 to commit before getting the lock on row2"
|
56
|
-
end
|
57
|
-
|
58
|
-
private
|
59
|
-
|
60
|
-
def thread1_main(signal_queue, options={})
|
61
|
-
Entry.transaction do
|
62
|
-
@result_queue << :t1_locking_row2
|
63
|
-
Entry.find(@row2_id, {:lock=>true}.merge(options)) # acquire a row lock on r2
|
64
|
-
@result_queue << :t1_locked_row2
|
65
|
-
signal_queue << :go # signal thread2 to start
|
66
|
-
sleep 1.5 # Wait for a few seconds, to allow the other thread to race with this thread.
|
67
|
-
@result_queue << :t1_committed
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def thread2_main(signal_queue, options={})
|
72
|
-
Entry.transaction do
|
73
|
-
signal_queue.shift # wait until we get the signal from thread1
|
74
|
-
@result_queue << :t2_locking_row1
|
75
|
-
Entry.find(@row1_id, {:lock=>true}.merge(options)) # should return immediately
|
76
|
-
@result_queue << :t2_locked_row1
|
77
|
-
@result_queue << :t2_locking_row2
|
78
|
-
Entry.find(@row2_id, {:lock=>true}.merge(options)) # should block until thread1 commits its transaction
|
79
|
-
@result_queue << :t2_locked_row2
|
80
|
-
@result_queue << :t2_committed
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def thread_helper
|
85
|
-
yield
|
86
|
-
rescue Exception => exc
|
87
|
-
# Output backtrace, since otherwise we won't see anything until the main thread joins this thread.
|
88
|
-
display_exception(exc)
|
89
|
-
raise
|
90
|
-
ensure
|
91
|
-
# This is needed. Otherwise, the database connections aren't returned to the pool and things break.
|
92
|
-
ActiveRecord::Base.connection_handler.clear_active_connections!
|
93
|
-
end
|
94
|
-
|
95
|
-
def display_exception(exception)
|
96
|
-
lines = []
|
97
|
-
lines << "#{exception.class.name}: #{exception.message}\n"
|
98
|
-
lines += exception.backtrace.map{|line| "\tfrom #{line}"}
|
99
|
-
$stderr.puts lines.join("\n")
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|