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
Binary file
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module ActiveRecord
|
2
|
-
|
2
|
+
|
3
3
|
if defined? ConnectionAdapters::ConnectionSpecification::Resolver # 4.0
|
4
4
|
ConnectionAdapters::ConnectionSpecification::Resolver
|
5
5
|
elsif defined? Base::ConnectionSpecification::Resolver # 3.2
|
@@ -7,17 +7,18 @@ module ActiveRecord
|
|
7
7
|
else class << Base; self; end # 2.3, 3.0, 3.1 :
|
8
8
|
# def self.establish_connection ... on ActiveRecord::Base
|
9
9
|
end.class_eval do
|
10
|
-
|
10
|
+
|
11
|
+
# @private
|
11
12
|
def require(path)
|
12
13
|
# NOTE: we're inspecting resolver.spec connection resolution which does :
|
13
14
|
# `require "active_record/connection_adapters/#{spec[:adapter]}_adapter"`
|
14
15
|
# ...
|
15
16
|
# this {#require} method is only re-defined on a Resolver object and thus
|
16
17
|
# will not hurt performance - it will only be called for a few times (most
|
17
|
-
# likely once), this should still be fine for AR < 3.2 where this patch
|
18
|
+
# likely once), this should still be fine for AR < 3.2 where this patch
|
18
19
|
# ends up on `class << ActiveRecord::Base` since models usually rely on
|
19
20
|
# Rails's auto-loading of (missing) constants and rarely use `require`.
|
20
|
-
#
|
21
|
+
#
|
21
22
|
# other alternative (to make sure we do not need to eager load AR built-in
|
22
23
|
# adapters) would be to mingle with the $LOAD_PATH which seems worse ...
|
23
24
|
case path
|
@@ -39,8 +40,8 @@ module ActiveRecord
|
|
39
40
|
else super
|
40
41
|
end
|
41
42
|
super
|
42
|
-
end
|
43
|
-
|
43
|
+
end
|
44
|
+
|
44
45
|
end
|
45
|
-
|
46
|
+
|
46
47
|
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
module ActiveRecord::ConnectionAdapters
|
2
|
+
module Jdbc
|
3
|
+
# AREL support for the JDBC adapter.
|
4
|
+
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter
|
5
|
+
module ArelSupport
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.extend ClassMethods
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
|
13
|
+
def arel_visitor_name(spec)
|
14
|
+
if spec
|
15
|
+
if spec.respond_to?(:arel_visitor_name)
|
16
|
+
spec.arel_visitor_name # for AREL built-in visitors
|
17
|
+
else
|
18
|
+
spec.name.split('::').last.downcase # ArJdbc::PostgreSQL -> postgresql
|
19
|
+
end
|
20
|
+
else # AR::ConnnectionAdapters::MySQLAdapter => mysql
|
21
|
+
name.split('::').last.sub('Adapter', '').downcase
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# NOTE: it's important to track our own since we might want to override
|
26
|
+
# what AREL setup for us e.g. we do not want `::Arel::Visitors::MSSQL`
|
27
|
+
|
28
|
+
# @private
|
29
|
+
RESOLVED_VISITORS = {} # lazy filled mirror of ::Arel::Visitors::VISITORS
|
30
|
+
|
31
|
+
# @todo document
|
32
|
+
def resolve_visitor_type(config)
|
33
|
+
raise "missing :adapter in #{config.inspect}" unless adapter = config[:adapter]
|
34
|
+
|
35
|
+
unless visitor_type = RESOLVED_VISITORS[ adapter ]
|
36
|
+
if adapter_spec = config[:adapter_spec]
|
37
|
+
if adapter_spec.respond_to?(:arel_visitor_type)
|
38
|
+
visitor_type = adapter_spec.arel_visitor_type(config)
|
39
|
+
elsif adapter_spec.respond_to?(:arel2_visitors) # backwards compat
|
40
|
+
visitor_type = adapter_spec.arel2_visitors(config).values.first
|
41
|
+
else # auto-convention ArJdbc::MySQL -> Arel::Visitors::MySQL
|
42
|
+
const_name = adapter_spec.name.split('::').last
|
43
|
+
visitor_type = ::Arel::Visitors.const_get(const_name) rescue nil
|
44
|
+
end
|
45
|
+
elsif respond_to?(:arel_visitor_type)
|
46
|
+
visitor_type = arel_visitor_type(config) # adapter_class' override
|
47
|
+
end
|
48
|
+
|
49
|
+
visitor_type ||= ::Arel::Visitors::VISITORS[ arel_visitor_name(adapter_spec) ]
|
50
|
+
visitor_type ||= ::Arel::Visitors::ToSql # default (if nothing resolved)
|
51
|
+
|
52
|
+
::Arel::Visitors::VISITORS[ adapter ] = visitor_type
|
53
|
+
RESOLVED_VISITORS[ adapter ] = visitor_type
|
54
|
+
end
|
55
|
+
|
56
|
+
visitor_type
|
57
|
+
end
|
58
|
+
|
59
|
+
# @note called from `ActiveRecord::ConnectionAdapters::ConnectionPool.checkout` (up till AR-3.2)
|
60
|
+
# @override
|
61
|
+
def visitor_for(pool)
|
62
|
+
visitor = resolve_visitor_type(config = pool.spec.config)
|
63
|
+
( prepared_statements?(config) ? visitor : bind_substitution(visitor) ).new(pool)
|
64
|
+
end
|
65
|
+
|
66
|
+
# @private
|
67
|
+
@@bind_substitutions = nil
|
68
|
+
|
69
|
+
# Generates a class for the given visitor type, this new {Class} instance
|
70
|
+
# is a sub-class of `Arel::Visitors::BindVisitor`.
|
71
|
+
# @return [Class] class for given visitor type
|
72
|
+
def bind_substitution(visitor)
|
73
|
+
# NOTE: similar convention as in AR (but no base substitution type) :
|
74
|
+
# class BindSubstitution < ::Arel::Visitors::ToSql
|
75
|
+
# include ::Arel::Visitors::BindVisitor
|
76
|
+
# end
|
77
|
+
return const_get(:BindSubstitution) if const_defined?(:BindSubstitution)
|
78
|
+
|
79
|
+
@@bind_substitutions ||= Java::JavaUtil::HashMap.new
|
80
|
+
unless bind_visitor = @@bind_substitutions.get(visitor)
|
81
|
+
@@bind_substitutions.synchronized do
|
82
|
+
unless @@bind_substitutions.get(visitor)
|
83
|
+
bind_visitor = Class.new(visitor) do
|
84
|
+
include ::Arel::Visitors::BindVisitor
|
85
|
+
end
|
86
|
+
@@bind_substitutions.put(visitor, bind_visitor)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
bind_visitor = @@bind_substitutions.get(visitor)
|
90
|
+
end
|
91
|
+
bind_visitor
|
92
|
+
end
|
93
|
+
|
94
|
+
begin
|
95
|
+
require 'arel/visitors/bind_visitor'
|
96
|
+
rescue LoadError # AR-3.0
|
97
|
+
def bind_substitution(visitor); visitor; end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
if defined? ::Arel::Visitors::VISITORS
|
103
|
+
|
104
|
+
# Instantiates a new AREL visitor for this adapter.
|
105
|
+
# @note On `ActiveRecord` **2.3** this method won't be used.
|
106
|
+
def new_visitor
|
107
|
+
visitor = self.class.resolve_visitor_type(config)
|
108
|
+
( prepared_statements? ? visitor : bind_substitution(visitor) ).new(self)
|
109
|
+
end
|
110
|
+
protected :new_visitor
|
111
|
+
|
112
|
+
def bind_substitution(visitor); self.class.bind_substitution(visitor); end
|
113
|
+
private :bind_substitution
|
114
|
+
|
115
|
+
# @override ActiveRecord's convention
|
116
|
+
def unprepared_visitor
|
117
|
+
# super does self.class::BindSubstitution.new self
|
118
|
+
# we do not require the BindSubstitution constant - auto-generated :
|
119
|
+
visitor = self.class.resolve_visitor_type(config)
|
120
|
+
bind_substitution(visitor).new(self)
|
121
|
+
end
|
122
|
+
|
123
|
+
else # NO-OP when no AREL (AR-2.3)
|
124
|
+
|
125
|
+
# @private documented above
|
126
|
+
def new_visitor; end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
data/lib/arjdbc/jdbc/base_ext.rb
CHANGED
@@ -14,7 +14,7 @@ module ActiveRecord
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
# Represents exceptions that have propagated up through the JDBC API.
|
19
19
|
class JDBCError < ActiveRecordError
|
20
20
|
# The vendor code or error number that came from the database.
|
@@ -23,9 +23,9 @@ module ActiveRecord
|
|
23
23
|
# The full Java SQLException object that was raised.
|
24
24
|
# @note writer being used by the Java API
|
25
25
|
attr_accessor :sql_exception
|
26
|
-
|
26
|
+
|
27
27
|
attr_reader :original_exception, :raw_backtrace
|
28
|
-
|
28
|
+
|
29
29
|
def initialize(message = nil, original_exception = nil) # $!
|
30
30
|
super(message)
|
31
31
|
@original_exception = original_exception
|
@@ -34,19 +34,20 @@ module ActiveRecord
|
|
34
34
|
def set_backtrace(backtrace)
|
35
35
|
@raw_backtrace = backtrace
|
36
36
|
if nested = original_exception
|
37
|
-
backtrace = backtrace - (
|
37
|
+
backtrace = backtrace - (
|
38
38
|
nested.respond_to?(:raw_backtrace) ? nested.raw_backtrace : nested.backtrace )
|
39
39
|
backtrace << "#{nested.backtrace.first}: #{nested.message} (#{nested.class.name})"
|
40
40
|
backtrace += nested.backtrace[1..-1] || []
|
41
41
|
end
|
42
42
|
super(backtrace)
|
43
43
|
end
|
44
|
-
|
45
|
-
end
|
46
44
|
|
47
|
-
|
45
|
+
end
|
46
|
+
|
47
|
+
module ConnectionAdapters
|
48
48
|
# Allows properly re-defining methods that may already be alias-chain-ed.
|
49
49
|
# Query caching works even with overriden alias_method_chain'd methods.
|
50
|
+
# @private
|
50
51
|
module ShadowCoreMethods
|
51
52
|
def alias_chained_method(name, feature, target)
|
52
53
|
# NOTE: aliasing for things such as columns (with feature query_cache)
|
@@ -1,8 +1,9 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
module ActiveRecord::ConnectionAdapters
|
2
|
+
module Jdbc
|
3
|
+
# ActiveRecord connection pool callbacks for JDBC.
|
4
|
+
# @see ActiveRecord::ConnectionAdapters::Jdbc::JndiConnectionPoolCallbacks
|
5
|
+
module ConnectionPoolCallbacks
|
6
|
+
|
6
7
|
def self.included(base)
|
7
8
|
if base.respond_to?(:set_callback) # Rails 3 callbacks
|
8
9
|
base.set_callback :checkin, :after, :on_checkin
|
@@ -20,13 +21,14 @@ module ActiveRecord
|
|
20
21
|
def on_checkout
|
21
22
|
# default implementation does nothing
|
22
23
|
end
|
23
|
-
|
24
|
-
end
|
25
24
|
|
25
|
+
end
|
26
|
+
# JNDI specific connection pool callbacks that make sure the JNDI connection
|
27
|
+
# is disconnected on check-in and looked up (re-connected) on-checkout.
|
26
28
|
module JndiConnectionPoolCallbacks
|
27
|
-
|
29
|
+
|
28
30
|
def self.prepare(adapter, connection)
|
29
|
-
if adapter.is_a?(
|
31
|
+
if adapter.is_a?(ConnectionPoolCallbacks) && connection.jndi?
|
30
32
|
adapter.extend self # extend JndiConnectionPoolCallbacks
|
31
33
|
connection.disconnect! # disconnect initial (JNDI) connection if any
|
32
34
|
end
|
@@ -40,6 +42,10 @@ module ActiveRecord
|
|
40
42
|
reconnect!
|
41
43
|
end
|
42
44
|
end
|
43
|
-
|
45
|
+
|
44
46
|
end
|
47
|
+
# @deprecated use {ActiveRecord::ConnectionAdapters::Jdbc::ConnectionPoolCallbacks}
|
48
|
+
JdbcConnectionPoolCallbacks = Jdbc::ConnectionPoolCallbacks
|
49
|
+
# @deprecated use {ActiveRecord::ConnectionAdapters::Jdbc::JndiConnectionPoolCallbacks}
|
50
|
+
JndiConnectionPoolCallbacks = Jdbc::JndiConnectionPoolCallbacks
|
45
51
|
end
|
data/lib/arjdbc/jdbc/column.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module ConnectionAdapters
|
3
|
+
# The base class for all of {JdbcAdapter}'s returned columns.
|
4
|
+
# Instances of {JdbcColumn} will get extended with "column-spec" modules
|
5
|
+
# (similar to how {JdbcAdapter} gets spec modules in) if the adapter spec
|
6
|
+
# module provided a `column_selector` (matcher) method for it's database
|
7
|
+
# specific type.
|
8
|
+
# @see JdbcAdapter#jdbc_column_class
|
3
9
|
class JdbcColumn < Column
|
4
10
|
attr_writer :limit, :precision
|
5
11
|
|
@@ -21,13 +27,16 @@ module ActiveRecord
|
|
21
27
|
init_column(name, default, *args)
|
22
28
|
end
|
23
29
|
|
30
|
+
# Additional column initialization for sub-classes.
|
24
31
|
def init_column(*args); end
|
25
32
|
|
26
|
-
#
|
33
|
+
# Similar to `ActiveRecord`'s `extract_value_from_default(default)`.
|
34
|
+
# @return default value for a given column
|
27
35
|
def default_value(value); value; end
|
28
36
|
|
29
37
|
protected
|
30
38
|
|
39
|
+
# @private
|
31
40
|
def call_discovered_column_callbacks(config)
|
32
41
|
dialect = (config[:dialect] || config[:driver]).to_s
|
33
42
|
for matcher, block in self.class.column_types
|
@@ -36,7 +45,9 @@ module ActiveRecord
|
|
36
45
|
end
|
37
46
|
|
38
47
|
public
|
39
|
-
|
48
|
+
|
49
|
+
# Returns the available column types
|
50
|
+
# @return [Hash] of (matcher, block) pairs
|
40
51
|
def self.column_types
|
41
52
|
types = {}
|
42
53
|
for mod in ::ArJdbc.modules
|
@@ -47,7 +58,18 @@ module ActiveRecord
|
|
47
58
|
end
|
48
59
|
types
|
49
60
|
end
|
50
|
-
|
61
|
+
|
62
|
+
class << self
|
63
|
+
|
64
|
+
if ActiveRecord::VERSION::MAJOR > 3
|
65
|
+
|
66
|
+
# @private provides compatibility between AR 3.x/4.0 API
|
67
|
+
def string_to_date(value); value_to_date(value) end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
51
73
|
end
|
52
74
|
end
|
53
75
|
end
|
@@ -1,23 +1,18 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module ConnectionAdapters
|
3
|
-
#
|
3
|
+
# JDBC (connection) base class, custom adapters we support likely extend
|
4
|
+
# this class. For maximum performance most of this class and the sub-classes
|
5
|
+
# we ship are implemented in Java, check: *RubyJdbcConnection.java*
|
4
6
|
class JdbcConnection
|
5
7
|
|
6
|
-
#
|
7
|
-
#
|
8
|
-
|
9
|
-
|
10
|
-
# @native_types - This is the default type settings sans any modifications by the
|
11
|
-
# individual adapter. My guess is that if we loaded two adapters of different types
|
12
|
-
# then this is used as a base to be tweaked by each adapter to create @native_database_types
|
13
|
-
|
14
|
-
def initialize(config)
|
15
|
-
self.config = config
|
8
|
+
# Initializer implemented in Ruby.
|
9
|
+
# @note second argument is mandatory, only optional for compatibility
|
10
|
+
def initialize(config, adapter = nil)
|
11
|
+
@config = config; @adapter = adapter
|
16
12
|
@connection = nil; @jndi = nil
|
17
13
|
# @stmts = {} # AR compatibility - statement cache not used
|
18
14
|
setup_connection_factory
|
19
|
-
|
20
|
-
set_native_database_types # so we can set the native types
|
15
|
+
init_connection # @see RubyJdbcConnection.init_connection
|
21
16
|
rescue Java::JavaSql::SQLException => e
|
22
17
|
e = e.cause if defined?(NativeException) && e.is_a?(NativeException) # JRuby-1.6.8
|
23
18
|
error = e.getMessage || e.getSQLState
|
@@ -28,46 +23,26 @@ module ActiveRecord
|
|
28
23
|
raise error
|
29
24
|
end
|
30
25
|
|
31
|
-
attr_reader :
|
32
|
-
|
26
|
+
attr_reader :adapter, :config
|
27
|
+
|
28
|
+
# @deprecated no longer used (pass adapter into #initialize)
|
33
29
|
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#initialize
|
34
|
-
def adapter=(adapter)
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
@adapter.config.replace(config)
|
39
|
-
end
|
40
|
-
|
41
|
-
# Duplicate all native types into new hash structure so it can be modified
|
42
|
-
# without destroying original structure.
|
43
|
-
def dup_native_types
|
44
|
-
types = {}
|
45
|
-
@native_types.each_pair do |k, v|
|
46
|
-
types[k] = v.inject({}) do |memo, kv|
|
47
|
-
last = kv.last
|
48
|
-
memo[kv.first] = last.is_a?(Numeric) ? last : (last.dup rescue last)
|
49
|
-
memo
|
50
|
-
end
|
51
|
-
end
|
52
|
-
types
|
53
|
-
end
|
54
|
-
private :dup_native_types
|
55
|
-
|
56
|
-
def config=(config)
|
57
|
-
@config = config.symbolize_keys
|
58
|
-
# NOTE: JDBC 4.0 drivers support checking if connection isValid
|
59
|
-
# thus no need to @config[:connection_alive_sql] ||= 'SELECT 1'
|
60
|
-
@config[:retry_count] ||= 5
|
61
|
-
@config
|
30
|
+
def adapter=(adapter); @adapter = adapter; end
|
31
|
+
|
32
|
+
def native_database_types
|
33
|
+
JdbcTypeConverter.new(supported_data_types).choose_best_types
|
62
34
|
end
|
63
|
-
|
35
|
+
|
36
|
+
# @deprecated no longer used - only kept for compatibility
|
37
|
+
def set_native_database_types; end
|
38
|
+
|
64
39
|
def jndi?; @jndi; end
|
65
40
|
alias_method :jndi_connection?, :jndi?
|
66
41
|
|
67
42
|
# Sets the connection factory from the available configuration.
|
68
43
|
# @see #setup_jdbc_factory
|
69
44
|
# @see #setup_jndi_factory
|
70
|
-
#
|
45
|
+
#
|
71
46
|
# @note this has nothing to do with the configure_connection implemented
|
72
47
|
# on some of the concrete adapters (e.g. {#ArJdbc::Postgres})
|
73
48
|
def setup_connection_factory
|
@@ -86,28 +61,26 @@ module ActiveRecord
|
|
86
61
|
protected
|
87
62
|
|
88
63
|
def setup_jndi_factory
|
89
|
-
data_source = config[:data_source] ||
|
64
|
+
data_source = config[:data_source] ||
|
90
65
|
Java::JavaxNaming::InitialContext.new.lookup(config[:jndi].to_s)
|
91
|
-
|
66
|
+
|
92
67
|
@jndi = true
|
93
|
-
|
94
|
-
data_source.connection
|
95
|
-
end
|
68
|
+
self.connection_factory = JdbcConnectionFactory.impl { data_source.connection }
|
96
69
|
end
|
97
70
|
|
98
71
|
def setup_jdbc_factory
|
99
72
|
if ! config[:url] || ( ! config[:driver] && ! config[:driver_instance] )
|
100
73
|
raise ::ActiveRecord::ConnectionNotEstablished, "jdbc adapter requires :driver class and :url"
|
101
74
|
end
|
102
|
-
|
75
|
+
|
103
76
|
url = jdbc_url
|
104
77
|
username = config[:username].to_s
|
105
78
|
password = config[:password].to_s
|
106
|
-
jdbc_driver = ( config[:driver_instance] ||=
|
79
|
+
jdbc_driver = ( config[:driver_instance] ||=
|
107
80
|
JdbcDriver.new(config[:driver].to_s, config[:properties]) )
|
108
|
-
|
81
|
+
|
109
82
|
@jndi = false
|
110
|
-
|
83
|
+
self.connection_factory = JdbcConnectionFactory.impl do
|
111
84
|
jdbc_driver.connection(url, username, password)
|
112
85
|
end
|
113
86
|
end
|
@@ -123,7 +96,7 @@ module ActiveRecord
|
|
123
96
|
end
|
124
97
|
url
|
125
98
|
end
|
126
|
-
|
99
|
+
|
127
100
|
end
|
128
101
|
end
|
129
102
|
end
|