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
@@ -73,7 +73,7 @@ module ActiveRecord #:nodoc:
|
|
73
73
|
|
74
74
|
def structure_dump_primary_key(table) #:nodoc:
|
75
75
|
opts = {:name => '', :cols => []}
|
76
|
-
pks = select_all(<<-SQL, "Primary Keys")
|
76
|
+
pks = select_all(<<-SQL, "Primary Keys")
|
77
77
|
SELECT a.constraint_name, a.column_name, a.position
|
78
78
|
FROM user_cons_columns a
|
79
79
|
JOIN user_constraints c
|
@@ -91,7 +91,7 @@ module ActiveRecord #:nodoc:
|
|
91
91
|
|
92
92
|
def structure_dump_unique_keys(table) #:nodoc:
|
93
93
|
keys = {}
|
94
|
-
uks = select_all(<<-SQL, "Primary Keys")
|
94
|
+
uks = select_all(<<-SQL, "Primary Keys")
|
95
95
|
SELECT a.constraint_name, a.column_name, a.position
|
96
96
|
FROM user_cons_columns a
|
97
97
|
JOIN user_constraints c
|
@@ -152,21 +152,21 @@ module ActiveRecord #:nodoc:
|
|
152
152
|
AND name NOT LIKE 'BIN$%'
|
153
153
|
AND owner = SYS_CONTEXT('userenv', 'session_user') ORDER BY type").each do |source|
|
154
154
|
ddl = "CREATE OR REPLACE \n"
|
155
|
-
|
155
|
+
select_all(%Q{
|
156
156
|
SELECT text
|
157
157
|
FROM all_source
|
158
158
|
WHERE name = '#{source['name']}'
|
159
159
|
AND type = '#{source['type']}'
|
160
160
|
AND owner = SYS_CONTEXT('userenv', 'session_user')
|
161
161
|
ORDER BY line
|
162
|
-
}).
|
162
|
+
}).each do |row|
|
163
163
|
ddl << row['text']
|
164
164
|
end
|
165
|
-
ddl << ";" unless ddl.strip[-1,1] ==
|
165
|
+
ddl << ";" unless ddl.strip[-1,1] == ';'
|
166
166
|
structure << ddl
|
167
167
|
end
|
168
168
|
|
169
|
-
# export views
|
169
|
+
# export views
|
170
170
|
select_all("SELECT view_name, text FROM user_views").each do |view|
|
171
171
|
structure << "CREATE OR REPLACE VIEW #{view['view_name']} AS\n #{view['text']}"
|
172
172
|
end
|
@@ -243,14 +243,14 @@ module ActiveRecord #:nodoc:
|
|
243
243
|
|
244
244
|
def execute_structure_dump(string)
|
245
245
|
string.split(STATEMENT_TOKEN).each do |ddl|
|
246
|
-
ddl.chop! if ddl[-1] == ';'
|
246
|
+
ddl.chop! if ddl[-1,1] == ';'
|
247
247
|
execute(ddl) unless ddl.blank?
|
248
248
|
end
|
249
249
|
end
|
250
250
|
|
251
251
|
private
|
252
252
|
|
253
|
-
# virtual columns are an 11g feature. This returns [] if feature is not
|
253
|
+
# virtual columns are an 11g feature. This returns [] if feature is not
|
254
254
|
# present or none are found.
|
255
255
|
# return [{'column_name' => 'FOOS', 'data_default' => '...'}, ...]
|
256
256
|
def virtual_columns_for(table)
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module ArJdbc
|
2
|
+
module Util
|
3
|
+
# Caches table and column name (quoted) outcomes.
|
4
|
+
# Uses {ThreadSafe::Cache} as a concurrent lock free (on JRuby) cache backend.
|
5
|
+
# The thread_safe gem is a dependency since ActiveSupport 4.0, when using
|
6
|
+
# ActiveRecord <= 3.2 one should add `gem 'thread_safe'` into the *Gemfile*
|
7
|
+
# as it is not forced (currently) as an explicit gem dependency.
|
8
|
+
#
|
9
|
+
# Caching can also be disabled by setting the *arjdbc.quoted_cache.disabled*
|
10
|
+
# system property = 'true'.
|
11
|
+
module QuotedCache
|
12
|
+
|
13
|
+
# @private
|
14
|
+
DISABLED = Java::JavaLang::Boolean.getBoolean('arjdbc.quoted_cache.disabled')
|
15
|
+
|
16
|
+
def self.included(base)
|
17
|
+
# the thread_safe gem is an ActiveSupport dependency (since 4.0) :
|
18
|
+
begin; require 'thread_safe'; rescue LoadError; end unless DISABLED
|
19
|
+
if ! DISABLED && defined? ThreadSafe::Cache
|
20
|
+
base.const_set :QUOTED_TABLE_NAMES, ThreadSafe::Cache.new
|
21
|
+
base.const_set :QUOTED_COLUMN_NAMES, ThreadSafe::Cache.new
|
22
|
+
else
|
23
|
+
base.const_set :QUOTED_TABLE_NAMES, nil
|
24
|
+
base.const_set :QUOTED_COLUMN_NAMES, nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Caches quoted table names, the cache is stored in the class'
|
29
|
+
# `QUOTED_TABLE_NAMES` constant.
|
30
|
+
# @return [String]
|
31
|
+
def quote_table_name(name)
|
32
|
+
if cache = self.class::QUOTED_TABLE_NAMES
|
33
|
+
unless quoted = cache[name]
|
34
|
+
quoted = super
|
35
|
+
cache.put_if_absent name, quoted.freeze
|
36
|
+
end
|
37
|
+
quoted
|
38
|
+
else
|
39
|
+
super
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Caches quoted table names, the cache is stored in the class'
|
44
|
+
# `QUOTED_COLUMN_NAMES` constant.
|
45
|
+
# @return [String]
|
46
|
+
def quote_column_name(name)
|
47
|
+
if cache = self.class::QUOTED_COLUMN_NAMES
|
48
|
+
unless quoted = cache[name]
|
49
|
+
quoted = super
|
50
|
+
cache.put_if_absent name, quoted.freeze
|
51
|
+
end
|
52
|
+
quoted
|
53
|
+
else
|
54
|
+
super
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module ArJdbc
|
2
|
+
module Util
|
3
|
+
module TableCopier
|
4
|
+
|
5
|
+
# taken from SQLite adapter, code loosely based on http://git.io/P7tFQA
|
6
|
+
|
7
|
+
# Performs changes for table by first copying (and preserving contents)
|
8
|
+
# into another (temporary) table, than alters and copies all data back.
|
9
|
+
def alter_table(table_name, options = {})
|
10
|
+
table_name = table_name.to_s.downcase
|
11
|
+
altered_table_name = "a#{table_name}"
|
12
|
+
caller = lambda { |definition| yield definition if block_given? }
|
13
|
+
|
14
|
+
transaction do
|
15
|
+
# A temporary table might improve performance here, but
|
16
|
+
# it doesn't seem to maintain indices across the whole move.
|
17
|
+
move_table(table_name, altered_table_name, options)
|
18
|
+
move_table(altered_table_name, table_name, &caller)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Move a table into another while preserving all content.
|
23
|
+
# @see #copy_table
|
24
|
+
def move_table(from, to, options = {}, &block)
|
25
|
+
copy_table(from, to, options, &block)
|
26
|
+
drop_table(from)
|
27
|
+
end
|
28
|
+
|
29
|
+
# @see #copy_table_contents
|
30
|
+
# @see #copy_table_indexes
|
31
|
+
def copy_table(from, to, options = {})
|
32
|
+
from_primary_key = primary_key(from)
|
33
|
+
create_table(to, options.merge(:id => false)) do |definition|
|
34
|
+
@definition = definition
|
35
|
+
@definition.primary_key(from_primary_key) if from_primary_key.present?
|
36
|
+
columns(from).each do |column|
|
37
|
+
column_name = options[:rename] ?
|
38
|
+
(options[:rename][column.name] ||
|
39
|
+
options[:rename][column.name.to_sym] ||
|
40
|
+
column.name) : column.name
|
41
|
+
|
42
|
+
next if column_name == from_primary_key
|
43
|
+
|
44
|
+
@definition.column(column_name, column.type,
|
45
|
+
:limit => column.limit, :default => column.default,
|
46
|
+
:precision => column.precision, :scale => column.scale,
|
47
|
+
:null => column.null)
|
48
|
+
end
|
49
|
+
yield @definition if block_given?
|
50
|
+
end
|
51
|
+
|
52
|
+
copy_table_indexes(from, to, options[:rename] || {})
|
53
|
+
copy_table_contents(from, to,
|
54
|
+
@definition.columns.map {|column| column.name},
|
55
|
+
options[:rename] || {})
|
56
|
+
end
|
57
|
+
|
58
|
+
# Copies indexes for a given table.
|
59
|
+
def copy_table_indexes(from, to, rename = {})
|
60
|
+
indexes(from).each do |index|
|
61
|
+
name = index.name.downcase
|
62
|
+
if to == "a#{from}"
|
63
|
+
name = "t#{name}"
|
64
|
+
elsif from == "a#{to}"
|
65
|
+
name = name[1..-1]
|
66
|
+
end
|
67
|
+
|
68
|
+
to_column_names = columns(to).map(&:name)
|
69
|
+
columns = index.columns.map { |column| rename[column] || column }
|
70
|
+
columns = columns.select { |column| to_column_names.include?(column) }
|
71
|
+
|
72
|
+
unless columns.empty?
|
73
|
+
# index name can't be the same
|
74
|
+
opts = { :name => name.gsub(/(^|_)(#{from})_/, "\\1#{to}_"), :internal => true }
|
75
|
+
opts[:unique] = true if index.unique
|
76
|
+
add_index(to, columns, opts)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# Copies the content of a table into another.
|
82
|
+
def copy_table_contents(from, to, columns, rename = {})
|
83
|
+
column_mappings = Hash[ columns.map { |name| [name, name] } ]
|
84
|
+
rename.each { |a| column_mappings[a.last] = a.first }
|
85
|
+
from_columns = columns(from).collect {|col| col.name}
|
86
|
+
columns = columns.find_all{ |col| from_columns.include?(column_mappings[col]) }
|
87
|
+
quoted_columns = columns.map { |col| quote_column_name(col) } * ','
|
88
|
+
|
89
|
+
quoted_to = quote_table_name(to)
|
90
|
+
|
91
|
+
raw_column_mappings = Hash[ columns(from).map { |c| [c.name, c] } ]
|
92
|
+
|
93
|
+
execute("SELECT * FROM #{quote_table_name(from)}", 'Copy Table').each do |row|
|
94
|
+
sql = "INSERT INTO #{quoted_to} (#{quoted_columns}) VALUES ("
|
95
|
+
|
96
|
+
column_values = columns.map do |col|
|
97
|
+
quote(row[column_mappings[col]], raw_column_mappings[col])
|
98
|
+
end
|
99
|
+
|
100
|
+
sql << column_values * ', '
|
101
|
+
sql << ')'
|
102
|
+
exec_insert sql, 'Copy Table', []
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
# @private @deprecated backwards compatibility
|
109
|
+
MissingFunctionalityHelper = Util::TableCopier
|
110
|
+
end
|
data/lib/arjdbc/version.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
module ArJdbc
|
2
|
-
VERSION = "1.3.0.
|
3
|
-
|
4
|
-
|
2
|
+
VERSION = "1.3.0.rc1"
|
3
|
+
# @deprecated
|
4
|
+
module Version
|
5
|
+
# @private 1.2.x compatibility
|
6
|
+
VERSION = ArJdbc::VERSION
|
5
7
|
end
|
6
|
-
end
|
7
|
-
# Compatibility with older versions of ar-jdbc for other extensions out there
|
8
|
-
JdbcAdapter = ArJdbc # :nodoc:
|
9
|
-
JdbcSpec = ArJdbc # :nodoc:
|
8
|
+
end
|
data/pom.xml
CHANGED
@@ -11,6 +11,10 @@
|
|
11
11
|
</description>
|
12
12
|
<url>http://github.com/jruby/activerecord-jdbc-adapter/wiki</url>
|
13
13
|
|
14
|
+
<properties>
|
15
|
+
<jruby.version>1.6.8</jruby.version>
|
16
|
+
</properties>
|
17
|
+
|
14
18
|
<issueManagement>
|
15
19
|
<system>GitHub</system>
|
16
20
|
<url>http://github.com/jruby/activerecord-jdbc-adapter/issues</url>
|
@@ -28,14 +32,47 @@
|
|
28
32
|
<url>http://www.opensource.org/licenses/bsd-license.php</url>
|
29
33
|
<distribution>repo</distribution>
|
30
34
|
</license>
|
35
|
+
<license>
|
36
|
+
<name>MIT License</name>
|
37
|
+
<url>http://www.opensource.org/licenses/mit-license.php</url>
|
38
|
+
<distribution>repo</distribution>
|
39
|
+
</license>
|
31
40
|
</licenses>
|
41
|
+
<!--
|
42
|
+
<repositories>
|
43
|
+
<repository>
|
44
|
+
<id>codehaus</id>
|
45
|
+
<name>Codehaus Repository</name>
|
46
|
+
<releases>
|
47
|
+
<enabled>true</enabled>
|
48
|
+
</releases>
|
49
|
+
<snapshots>
|
50
|
+
<enabled>false</enabled>
|
51
|
+
</snapshots>
|
52
|
+
<url>http://repository.codehaus.org</url>
|
53
|
+
</repository>
|
54
|
+
</repositories>-->
|
55
|
+
|
56
|
+
<developers>
|
57
|
+
<developer>
|
58
|
+
<id>nicksieger</id>
|
59
|
+
<name>Nick Sieger</name>
|
60
|
+
<email>nicksieger@gmail.com</email>
|
61
|
+
</developer>
|
62
|
+
<developer>
|
63
|
+
<id>kares</id>
|
64
|
+
<name>Karol Bucek</name>
|
65
|
+
<email>self@kares.org</email>
|
66
|
+
</developer>
|
67
|
+
</developers>
|
32
68
|
|
33
69
|
<dependencies>
|
34
70
|
<dependency>
|
35
71
|
<groupId>org.jruby</groupId>
|
36
72
|
<artifactId>jruby-complete</artifactId>
|
37
|
-
<version
|
73
|
+
<version>${jruby.version}</version>
|
38
74
|
</dependency>
|
75
|
+
|
39
76
|
<!-- e.g.
|
40
77
|
mvn install:install-file -DgroupId=org.postgresql -DartifactId=pgjdbc -Dversion=9.2-1002 -Dpackaging=jar -Dfile=./jdbc-postgres/lib/postgresql-9.2-1002.jdbc4.jar
|
41
78
|
-->
|
@@ -47,18 +84,35 @@
|
|
47
84
|
</dependencies>
|
48
85
|
|
49
86
|
<build>
|
50
|
-
|
87
|
+
|
51
88
|
<sourceDirectory>src/java</sourceDirectory>
|
89
|
+
<resources>
|
90
|
+
<resource>
|
91
|
+
<directory>lib</directory>
|
92
|
+
</resource>
|
93
|
+
</resources>
|
94
|
+
<!--
|
95
|
+
<testSourceDirectory>test/java</testSourceDirectory>-->
|
96
|
+
<testResources>
|
97
|
+
<testResource>
|
98
|
+
<directory>test</directory>
|
99
|
+
</testResource>
|
100
|
+
</testResources>
|
101
|
+
|
102
|
+
<outputDirectory>pkg/classes</outputDirectory>
|
103
|
+
|
52
104
|
<plugins>
|
53
105
|
<plugin>
|
54
106
|
<groupId>org.apache.maven.plugins</groupId>
|
55
107
|
<artifactId>maven-compiler-plugin</artifactId>
|
108
|
+
<version>2.5.1</version>
|
56
109
|
<configuration>
|
57
110
|
<source>1.6</source>
|
58
111
|
<target>1.6</target>
|
59
112
|
</configuration>
|
60
113
|
</plugin>
|
61
114
|
</plugins>
|
115
|
+
|
62
116
|
</build>
|
63
117
|
|
64
118
|
</project>
|
data/rakelib/02-test.rake
CHANGED
@@ -14,118 +14,107 @@ else
|
|
14
14
|
task :test => [ :test_mysql ]
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def set_test_task_compat_version(task)
|
18
18
|
task.ruby_opts << '-v' if RUBY_VERSION =~ /1\.8/
|
19
19
|
if defined?(JRUBY_VERSION)
|
20
20
|
task.ruby_opts << "--#{RUBY_VERSION[/^(\d+\.\d+)/, 1]}"
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
24
|
+
def set_task_description(task, desc)
|
25
|
+
unless task.is_a?(Rake::Task)
|
26
|
+
task = task.name if task.is_a?(Rake::TestTask)
|
27
|
+
task = Rake::Task[task]
|
28
|
+
end
|
29
|
+
# reset the desc set-up by TestTask :
|
30
|
+
task.instance_variable_set(:@full_comment, nil)
|
31
|
+
task.add_description(desc)
|
32
|
+
end
|
33
|
+
|
34
|
+
task 'test_appraisal_hint' do
|
35
|
+
next if File.exists?('.disable-appraisal-hint')
|
36
|
+
unless (ENV['BUNDLE_GEMFILE'] rescue '') =~ /gemfiles\/.*?\.gemfile/
|
37
|
+
appraisals = []; Appraisal::File.each { |file| appraisals << file.name }
|
38
|
+
puts "HINT: specify AR version with `rake appraisal:{version} test_{adapter}'" +
|
39
|
+
" where version=(#{appraisals.join('|')}) (`touch .disable-appraisal-hint' to disable)"
|
40
|
+
end
|
32
41
|
end
|
33
42
|
|
34
43
|
Rake::TestTask.class_eval { attr_reader :test_files }
|
35
44
|
|
36
|
-
def
|
37
|
-
|
45
|
+
def test_task_for(adapter, options = {})
|
46
|
+
desc = options[:desc] || options[:comment] ||
|
47
|
+
"Run tests against #{options[:database_name] || adapter}"
|
48
|
+
adapter = adapter.to_s.downcase
|
49
|
+
driver = options.key?(:driver) ? options[:driver] : adapter
|
38
50
|
prereqs = options[:prereqs] || []
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
51
|
+
unless prereqs.frozen?
|
52
|
+
prereqs = [ prereqs ].flatten; prereqs << 'test_appraisal_hint'
|
53
|
+
end
|
54
|
+
name = options[:name] || "test_#{adapter}"
|
55
|
+
test_task = Rake::TestTask.new(name => prereqs) do |test_task|
|
56
|
+
files = options[:files] || begin
|
57
|
+
FileList["test/#{adapter}*_test.rb"] +
|
58
|
+
FileList["test/db/#{adapter}/*_test.rb"]
|
59
|
+
end
|
60
|
+
test_task.test_files = files
|
61
|
+
test_task.libs = []
|
48
62
|
if defined?(JRUBY_VERSION)
|
49
|
-
|
50
|
-
|
63
|
+
test_task.libs << 'lib'
|
64
|
+
test_task.libs << "jdbc-#{driver}/lib" if driver && File.exists?("jdbc-#{driver}/lib")
|
65
|
+
test_task.libs.push *FileList["activerecord-jdbc#{adapter}*/lib"]
|
51
66
|
end
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
yield(
|
67
|
+
test_task.libs << 'test'
|
68
|
+
set_test_task_compat_version test_task
|
69
|
+
test_task.verbose = true if $VERBOSE
|
70
|
+
yield(test_task) if block_given?
|
56
71
|
end
|
72
|
+
set_task_description name, desc
|
73
|
+
test_task
|
57
74
|
end
|
58
75
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
task :
|
66
|
-
task :test_pgsql => :
|
67
|
-
|
76
|
+
test_task_for :Derby, :desc => 'Run tests against (embedded) DerbyDB'
|
77
|
+
test_task_for :H2, :desc => 'Run tests against H2 database engine'
|
78
|
+
test_task_for :HSQLDB, :desc => 'Run tests against HyperSQL (Java) database'
|
79
|
+
test_task_for :MSSQL, :driver => :jtds, :database_name => 'MS-SQL (SQLServer)'
|
80
|
+
test_task_for :MySQL, :prereqs => 'db:mysql'
|
81
|
+
test_task_for :PostgreSQL, :prereqs => 'db:postgresql', :driver => 'postgres'
|
82
|
+
task :test_postgres => :test_postgresql # alias
|
83
|
+
task :test_pgsql => :test_postgresql # alias
|
84
|
+
test_task_for :SQLite3
|
85
|
+
test_task_for :FireBird
|
68
86
|
|
69
87
|
# ensure driver for these DBs is on your class-path
|
70
|
-
[ :
|
71
|
-
|
72
|
-
test_files = FileList["test/#{adapter}*_test.rb"]
|
73
|
-
test_files += FileList["test/db/#{adapter}/*_test.rb"]
|
74
|
-
task.test_files = test_files
|
75
|
-
task.libs = []
|
76
|
-
task.libs << 'lib' if defined?(JRUBY_VERSION)
|
77
|
-
task.libs << 'test'
|
78
|
-
set_compat_version(task)
|
79
|
-
end
|
88
|
+
[ :Oracle, :DB2, :Informix, :CacheDB ].each do |adapter|
|
89
|
+
test_task_for adapter, :desc => "Run tests against #{adapter} (ensure driver is on class-path)"
|
80
90
|
end
|
81
91
|
|
82
|
-
|
83
|
-
test_files = FileList["test/db2*_test.rb"]
|
84
|
-
test_files += FileList["test/db/db2/*_test.rb"]
|
85
|
-
task.test_files = test_files
|
86
|
-
task.libs = []
|
87
|
-
task.libs << 'lib' if defined?(JRUBY_VERSION)
|
88
|
-
task.libs << 'test'
|
89
|
-
set_compat_version(task)
|
90
|
-
end
|
92
|
+
#test_task_for :MSSQL, :name => 'test_sqlserver', :driver => nil, :database_name => 'MS-SQL using SQLJDBC'
|
91
93
|
|
92
|
-
|
93
|
-
|
94
|
-
task.libs << 'test' << 'jdbc-mysql/lib' << 'jdbc-derby/lib'
|
95
|
-
set_compat_version(task)
|
96
|
-
end
|
94
|
+
test_task_for :AS400, :desc => "Run tests against AS400 (DB2) (ensure driver is on class-path)",
|
95
|
+
:files => FileList["test/db2*_test.rb"] + FileList["test/db/db2/*_test.rb"]
|
97
96
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
set_compat_version(task)
|
97
|
+
test_task_for 'JDBC', :desc => 'Run tests against plain JDBC adapter (uses MySQL and Derby)',
|
98
|
+
:files => FileList['test/*jdbc_*test.rb'] do |test_task|
|
99
|
+
test_task.libs << 'jdbc-mysql/lib' << 'jdbc-derby/lib'
|
102
100
|
end
|
103
101
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
set_compat_version(task)
|
102
|
+
test_task_for 'JNDI', :desc => 'Run tests against a JNDI connection (uses Derby)',
|
103
|
+
:prereqs => 'tomcat-jndi:check',
|
104
|
+
:files => FileList['test/*jndi_*test.rb'] do |test_task|
|
105
|
+
test_task.libs << 'jdbc-derby/lib'
|
109
106
|
end
|
110
107
|
|
111
|
-
#
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
end
|
117
|
-
|
118
|
-
# ensure that the jConnect driver is in your class-path
|
119
|
-
Rake::TestTask.new(:test_sybase_jconnect) do |task|
|
120
|
-
task.test_files = FileList['test/sybase_jconnect_simple_test.rb']
|
121
|
-
task.libs << 'test'
|
122
|
-
set_compat_version(task)
|
123
|
-
end
|
108
|
+
# TODO Sybase testing is currently broken, please fix it if you're on Sybase :
|
109
|
+
#test_task_for :Sybase, :desc => "Run tests against Sybase (using jTDS driver)"
|
110
|
+
#task :test_sybase_jtds => :test_sybase # alias
|
111
|
+
#test_task_for :Sybase, :name => 'sybase_jconnect',
|
112
|
+
# :desc => "Run tests against Sybase (ensure jConnect driver is on class-path)"
|
124
113
|
|
125
114
|
Rake::TraceOutput.module_eval do
|
126
115
|
|
127
116
|
# NOTE: avoid TypeError: String can't be coerced into Fixnum
|
128
|
-
# due this method
|
117
|
+
# due this method getting some strings == [ 1 ] argument ...
|
129
118
|
def trace_on(out, *strings)
|
130
119
|
sep = $\ || "\n"
|
131
120
|
if strings.empty?
|
@@ -138,5 +127,5 @@ Rake::TraceOutput.module_eval do
|
|
138
127
|
end
|
139
128
|
out.print(output)
|
140
129
|
end
|
141
|
-
|
130
|
+
|
142
131
|
end
|