activerecord-jdbc-adapter-ficoh 1.3.21-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +35 -0
- data/.travis.yml +462 -0
- data/.yardopts +4 -0
- data/Appraisals +36 -0
- data/CONTRIBUTING.md +49 -0
- data/Gemfile +68 -0
- data/History.md +1191 -0
- data/LICENSE.txt +25 -0
- data/README.md +277 -0
- data/RUNNING_TESTS.md +88 -0
- data/Rakefile +298 -0
- data/Rakefile.jdbc +20 -0
- data/activerecord-jdbc-adapter.gemspec +63 -0
- data/lib/active_record/connection_adapters/as400_adapter.rb +2 -0
- data/lib/active_record/connection_adapters/db2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/derby_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/firebird_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/h2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/hsqldb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/informix_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jdbc_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/jndi_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mariadb_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mssql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql2_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/mysql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/oracle_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/postgresql_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlite3_adapter.rb +1 -0
- data/lib/active_record/connection_adapters/sqlserver_adapter.rb +1 -0
- data/lib/activerecord-jdbc-adapter.rb +1 -0
- data/lib/arel/visitors/compat.rb +64 -0
- data/lib/arel/visitors/db2.rb +137 -0
- data/lib/arel/visitors/derby.rb +112 -0
- data/lib/arel/visitors/firebird.rb +79 -0
- data/lib/arel/visitors/h2.rb +25 -0
- data/lib/arel/visitors/hsqldb.rb +32 -0
- data/lib/arel/visitors/postgresql_jdbc.rb +6 -0
- data/lib/arel/visitors/sql_server.rb +225 -0
- data/lib/arel/visitors/sql_server/ng42.rb +293 -0
- data/lib/arjdbc.rb +22 -0
- data/lib/arjdbc/db2.rb +4 -0
- data/lib/arjdbc/db2/adapter.rb +802 -0
- data/lib/arjdbc/db2/as400.rb +137 -0
- data/lib/arjdbc/db2/column.rb +177 -0
- data/lib/arjdbc/db2/connection_methods.rb +45 -0
- data/lib/arjdbc/derby.rb +3 -0
- data/lib/arjdbc/derby/active_record_patch.rb +13 -0
- data/lib/arjdbc/derby/adapter.rb +567 -0
- data/lib/arjdbc/derby/connection_methods.rb +16 -0
- data/lib/arjdbc/derby/schema_creation.rb +15 -0
- data/lib/arjdbc/discover.rb +104 -0
- data/lib/arjdbc/firebird.rb +4 -0
- data/lib/arjdbc/firebird/adapter.rb +468 -0
- data/lib/arjdbc/firebird/connection_methods.rb +20 -0
- data/lib/arjdbc/h2.rb +3 -0
- data/lib/arjdbc/h2/adapter.rb +335 -0
- data/lib/arjdbc/h2/connection_methods.rb +22 -0
- data/lib/arjdbc/hsqldb.rb +3 -0
- data/lib/arjdbc/hsqldb/adapter.rb +304 -0
- data/lib/arjdbc/hsqldb/connection_methods.rb +23 -0
- data/lib/arjdbc/hsqldb/explain_support.rb +35 -0
- data/lib/arjdbc/hsqldb/schema_creation.rb +11 -0
- data/lib/arjdbc/informix.rb +5 -0
- data/lib/arjdbc/informix/adapter.rb +160 -0
- data/lib/arjdbc/informix/connection_methods.rb +9 -0
- data/lib/arjdbc/jdbc.rb +62 -0
- data/lib/arjdbc/jdbc/adapter.rb +997 -0
- data/lib/arjdbc/jdbc/adapter_require.rb +46 -0
- data/lib/arjdbc/jdbc/arel_support.rb +149 -0
- data/lib/arjdbc/jdbc/base_ext.rb +34 -0
- data/lib/arjdbc/jdbc/callbacks.rb +52 -0
- data/lib/arjdbc/jdbc/column.rb +83 -0
- data/lib/arjdbc/jdbc/connection.rb +26 -0
- data/lib/arjdbc/jdbc/connection_methods.rb +59 -0
- data/lib/arjdbc/jdbc/driver.rb +44 -0
- data/lib/arjdbc/jdbc/error.rb +75 -0
- data/lib/arjdbc/jdbc/extension.rb +69 -0
- data/lib/arjdbc/jdbc/java.rb +13 -0
- data/lib/arjdbc/jdbc/type_cast.rb +154 -0
- data/lib/arjdbc/jdbc/type_converter.rb +142 -0
- data/lib/arjdbc/mssql.rb +7 -0
- data/lib/arjdbc/mssql/adapter.rb +822 -0
- data/lib/arjdbc/mssql/column.rb +207 -0
- data/lib/arjdbc/mssql/connection_methods.rb +72 -0
- data/lib/arjdbc/mssql/explain_support.rb +99 -0
- data/lib/arjdbc/mssql/limit_helpers.rb +231 -0
- data/lib/arjdbc/mssql/lock_methods.rb +77 -0
- data/lib/arjdbc/mssql/types.rb +343 -0
- data/lib/arjdbc/mssql/utils.rb +82 -0
- data/lib/arjdbc/mysql.rb +3 -0
- data/lib/arjdbc/mysql/adapter.rb +998 -0
- data/lib/arjdbc/mysql/bulk_change_table.rb +150 -0
- data/lib/arjdbc/mysql/column.rb +167 -0
- data/lib/arjdbc/mysql/connection_methods.rb +137 -0
- data/lib/arjdbc/mysql/explain_support.rb +82 -0
- data/lib/arjdbc/mysql/schema_creation.rb +58 -0
- data/lib/arjdbc/oracle.rb +4 -0
- data/lib/arjdbc/oracle/adapter.rb +968 -0
- data/lib/arjdbc/oracle/column.rb +136 -0
- data/lib/arjdbc/oracle/connection_methods.rb +21 -0
- data/lib/arjdbc/postgresql.rb +3 -0
- data/lib/arjdbc/postgresql/_bc_time_cast_patch.rb +21 -0
- data/lib/arjdbc/postgresql/adapter.rb +1498 -0
- data/lib/arjdbc/postgresql/base/array_parser.rb +95 -0
- data/lib/arjdbc/postgresql/base/oid.rb +412 -0
- data/lib/arjdbc/postgresql/base/pgconn.rb +8 -0
- data/lib/arjdbc/postgresql/base/schema_definitions.rb +132 -0
- data/lib/arjdbc/postgresql/column.rb +640 -0
- data/lib/arjdbc/postgresql/connection_methods.rb +44 -0
- data/lib/arjdbc/postgresql/explain_support.rb +53 -0
- data/lib/arjdbc/postgresql/oid/bytea.rb +3 -0
- data/lib/arjdbc/postgresql/oid_types.rb +265 -0
- data/lib/arjdbc/postgresql/schema_creation.rb +60 -0
- data/lib/arjdbc/railtie.rb +11 -0
- data/lib/arjdbc/sqlite3.rb +3 -0
- data/lib/arjdbc/sqlite3/adapter.rb +654 -0
- data/lib/arjdbc/sqlite3/connection_methods.rb +36 -0
- data/lib/arjdbc/sqlite3/explain_support.rb +29 -0
- data/lib/arjdbc/sybase.rb +2 -0
- data/lib/arjdbc/sybase/adapter.rb +47 -0
- data/lib/arjdbc/tasks.rb +13 -0
- data/lib/arjdbc/tasks/database_tasks.rb +66 -0
- data/lib/arjdbc/tasks/databases.rake +91 -0
- data/lib/arjdbc/tasks/databases3.rake +239 -0
- data/lib/arjdbc/tasks/databases4.rake +39 -0
- data/lib/arjdbc/tasks/db2_database_tasks.rb +104 -0
- data/lib/arjdbc/tasks/derby_database_tasks.rb +95 -0
- data/lib/arjdbc/tasks/h2_database_tasks.rb +31 -0
- data/lib/arjdbc/tasks/hsqldb_database_tasks.rb +70 -0
- data/lib/arjdbc/tasks/jdbc_database_tasks.rb +169 -0
- data/lib/arjdbc/tasks/mssql_database_tasks.rb +46 -0
- data/lib/arjdbc/tasks/oracle/enhanced_structure_dump.rb +297 -0
- data/lib/arjdbc/tasks/oracle_database_tasks.rb +65 -0
- data/lib/arjdbc/util/quoted_cache.rb +60 -0
- data/lib/arjdbc/util/serialized_attributes.rb +98 -0
- data/lib/arjdbc/util/table_copier.rb +108 -0
- data/lib/arjdbc/version.rb +8 -0
- data/lib/generators/jdbc/USAGE +9 -0
- data/lib/generators/jdbc/jdbc_generator.rb +17 -0
- data/pom.xml +285 -0
- data/rails_generators/jdbc_generator.rb +15 -0
- data/rails_generators/templates/config/initializers/jdbc.rb +10 -0
- data/rails_generators/templates/lib/tasks/jdbc.rake +11 -0
- data/rakelib/01-tomcat.rake +51 -0
- data/rakelib/02-test.rake +151 -0
- data/rakelib/bundler_ext.rb +11 -0
- data/rakelib/db.rake +58 -0
- data/rakelib/rails.rake +77 -0
- data/src/java/arjdbc/ArJdbcModule.java +288 -0
- data/src/java/arjdbc/db2/DB2Module.java +77 -0
- data/src/java/arjdbc/db2/DB2RubyJdbcConnection.java +128 -0
- data/src/java/arjdbc/derby/DerbyModule.java +180 -0
- data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +153 -0
- data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +190 -0
- data/src/java/arjdbc/h2/H2Module.java +50 -0
- data/src/java/arjdbc/h2/H2RubyJdbcConnection.java +86 -0
- data/src/java/arjdbc/hsqldb/HSQLDBModule.java +74 -0
- data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +76 -0
- data/src/java/arjdbc/jdbc/AdapterJavaService.java +43 -0
- data/src/java/arjdbc/jdbc/Callable.java +44 -0
- data/src/java/arjdbc/jdbc/ConnectionFactory.java +77 -0
- data/src/java/arjdbc/jdbc/DataSourceConnectionFactory.java +156 -0
- data/src/java/arjdbc/jdbc/DriverConnectionFactory.java +63 -0
- data/src/java/arjdbc/jdbc/DriverWrapper.java +128 -0
- data/src/java/arjdbc/jdbc/JdbcConnectionFactory.java +32 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +4541 -0
- data/src/java/arjdbc/jdbc/SQLBlock.java +54 -0
- data/src/java/arjdbc/jdbc/WithResultSet.java +37 -0
- data/src/java/arjdbc/mssql/MSSQLModule.java +91 -0
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +193 -0
- data/src/java/arjdbc/mysql/MySQLModule.java +140 -0
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +456 -0
- data/src/java/arjdbc/oracle/OracleModule.java +81 -0
- data/src/java/arjdbc/oracle/OracleRubyJdbcConnection.java +477 -0
- data/src/java/arjdbc/postgresql/ByteaUtils.java +171 -0
- data/src/java/arjdbc/postgresql/DriverImplementation.java +78 -0
- data/src/java/arjdbc/postgresql/PGDriverImplementation.java +535 -0
- data/src/java/arjdbc/postgresql/PostgreSQLModule.java +189 -0
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +489 -0
- data/src/java/arjdbc/sqlite3/SQLite3Module.java +93 -0
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +405 -0
- data/src/java/arjdbc/util/CallResultSet.java +826 -0
- data/src/java/arjdbc/util/DateTimeUtils.java +517 -0
- data/src/java/arjdbc/util/NumberUtils.java +50 -0
- data/src/java/arjdbc/util/ObjectSupport.java +65 -0
- data/src/java/arjdbc/util/QuotingUtils.java +139 -0
- data/src/java/arjdbc/util/StringCache.java +60 -0
- data/src/java/arjdbc/util/StringHelper.java +155 -0
- metadata +288 -0
@@ -0,0 +1,46 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
|
3
|
+
if defined? ConnectionAdapters::ConnectionSpecification::Resolver # 4.0
|
4
|
+
ConnectionAdapters::ConnectionSpecification::Resolver
|
5
|
+
elsif defined? Base::ConnectionSpecification::Resolver # 3.2
|
6
|
+
Base::ConnectionSpecification::Resolver
|
7
|
+
else class << Base; self; end # 2.3, 3.0, 3.1 :
|
8
|
+
# def self.establish_connection ... on ActiveRecord::Base
|
9
|
+
end.class_eval do
|
10
|
+
|
11
|
+
# @private
|
12
|
+
def require(path)
|
13
|
+
# NOTE: we're inspecting resolver.spec connection resolution which does :
|
14
|
+
# `require "active_record/connection_adapters/#{spec[:adapter]}_adapter"`
|
15
|
+
# ...
|
16
|
+
# this {#require} method is only re-defined on a Resolver object and thus
|
17
|
+
# will not hurt performance - it will only be called for a few times (most
|
18
|
+
# likely once), this should still be fine for AR < 3.2 where this patch
|
19
|
+
# ends up on `class << ActiveRecord::Base` since models usually rely on
|
20
|
+
# Rails's auto-loading of (missing) constants and rarely use `require`.
|
21
|
+
#
|
22
|
+
# other alternative (to make sure we do not need to eager load AR built-in
|
23
|
+
# adapters) would be to mingle with the $LOAD_PATH which seems worse ...
|
24
|
+
case path
|
25
|
+
when 'active_record/connection_adapters/mysql_adapter'
|
26
|
+
$LOADED_FEATURES << 'active_record/connection_adapters/mysql_adapter.rb'
|
27
|
+
super('arjdbc/mysql')
|
28
|
+
when 'active_record/connection_adapters/mysql2_adapter'
|
29
|
+
$LOADED_FEATURES << 'active_record/connection_adapters/mysql2_adapter.rb'
|
30
|
+
super('arjdbc/mysql')
|
31
|
+
when 'active_record/connection_adapters/postgresql_adapter'
|
32
|
+
$LOADED_FEATURES << 'active_record/connection_adapters/postgresql_adapter.rb'
|
33
|
+
super('arjdbc/postgresql')
|
34
|
+
when 'active_record/connection_adapters/sqlite_adapter'
|
35
|
+
$LOADED_FEATURES << 'active_record/connection_adapters/sqlite_adapter.rb'
|
36
|
+
super('arjdbc/sqlite3')
|
37
|
+
when 'active_record/connection_adapters/sqlite3_adapter'
|
38
|
+
$LOADED_FEATURES << 'active_record/connection_adapters/sqlite3_adapter.rb'
|
39
|
+
super('arjdbc/sqlite3')
|
40
|
+
else super
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,149 @@
|
|
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
|
+
visitor_type = RESOLVED_VISITORS[ adapter ]
|
36
|
+
|
37
|
+
if visitor_type.nil? || adapter == 'jdbc'
|
38
|
+
if adapter_spec = config[:adapter_spec]
|
39
|
+
if adapter_spec.respond_to?(:arel_visitor_type)
|
40
|
+
visitor_type = adapter_spec.arel_visitor_type(config)
|
41
|
+
elsif adapter_spec.respond_to?(:arel2_visitors) # backwards compat
|
42
|
+
visitor_type = adapter_spec.arel2_visitors(config).values.first
|
43
|
+
else # auto-convention ArJdbc::MySQL -> Arel::Visitors::MySQL
|
44
|
+
const_name = adapter_spec.name.split('::').last
|
45
|
+
visitor_type = ::Arel::Visitors.const_get(const_name) rescue nil
|
46
|
+
end
|
47
|
+
elsif respond_to?(:arel_visitor_type)
|
48
|
+
visitor_type = arel_visitor_type(config) # adapter_class' override
|
49
|
+
end
|
50
|
+
|
51
|
+
if visitor_type && RESOLVED_VISITORS[ adapter ] # adapter == 'jdbc'
|
52
|
+
if visitor_type != RESOLVED_VISITORS[ adapter ]
|
53
|
+
ArJdbc.warn("overriding visitor for 'adapter: jdbc' (from #{RESOLVED_VISITORS[ adapter ]} to #{visitor_type})")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
visitor_type ||= ::Arel::Visitors::VISITORS[ arel_visitor_name(adapter_spec) ]
|
58
|
+
visitor_type ||= ::Arel::Visitors::ToSql # default (if nothing resolved)
|
59
|
+
|
60
|
+
RESOLVED_VISITORS.to_java.synchronized do
|
61
|
+
RESOLVED_VISITORS[ adapter ] = ::Arel::Visitors::VISITORS[ adapter ] = visitor_type
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
visitor_type
|
66
|
+
end
|
67
|
+
|
68
|
+
# @private
|
69
|
+
def clean_visitor_type(adapter)
|
70
|
+
RESOLVED_VISITORS.to_java.synchronized do
|
71
|
+
RESOLVED_VISITORS.delete(adapter); ::Arel::Visitors::VISITORS.delete(adapter)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
private :clean_visitor_type
|
75
|
+
|
76
|
+
# @note called from `ActiveRecord::ConnectionAdapters::ConnectionPool.checkout` (up till AR-3.2)
|
77
|
+
# @override
|
78
|
+
def visitor_for(pool)
|
79
|
+
visitor = resolve_visitor_type(config = pool.spec.config)
|
80
|
+
( prepared_statements?(config) ? visitor : bind_substitution(visitor) ).new(pool)
|
81
|
+
end
|
82
|
+
|
83
|
+
# @private
|
84
|
+
@@bind_substitutions = nil
|
85
|
+
|
86
|
+
# Generates a class for the given visitor type, this new {Class} instance
|
87
|
+
# is a sub-class of `Arel::Visitors::BindVisitor`.
|
88
|
+
# @return [Class] class for given visitor type
|
89
|
+
def bind_substitution(visitor)
|
90
|
+
# NOTE: similar convention as in AR (but no base substitution type) :
|
91
|
+
# class BindSubstitution < ::Arel::Visitors::ToSql
|
92
|
+
# include ::Arel::Visitors::BindVisitor
|
93
|
+
# end
|
94
|
+
return const_get(:BindSubstitution) if const_defined?(:BindSubstitution)
|
95
|
+
|
96
|
+
@@bind_substitutions ||= Java::JavaUtil::HashMap.new
|
97
|
+
unless bind_visitor = @@bind_substitutions.get(visitor)
|
98
|
+
@@bind_substitutions.synchronized do
|
99
|
+
unless @@bind_substitutions.get(visitor)
|
100
|
+
bind_visitor = Class.new(visitor) do
|
101
|
+
include ::Arel::Visitors::BindVisitor
|
102
|
+
end
|
103
|
+
@@bind_substitutions.put(visitor, bind_visitor)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
bind_visitor = @@bind_substitutions.get(visitor)
|
107
|
+
end
|
108
|
+
bind_visitor
|
109
|
+
end
|
110
|
+
|
111
|
+
begin
|
112
|
+
require 'arel/visitors/bind_visitor'
|
113
|
+
rescue LoadError # AR-3.0
|
114
|
+
def bind_substitution(visitor); visitor; end
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
if defined? ::Arel::Visitors::VISITORS
|
120
|
+
|
121
|
+
# Instantiates a new AREL visitor for this adapter.
|
122
|
+
# @note On `ActiveRecord` **2.3** this method won't be used.
|
123
|
+
def new_visitor
|
124
|
+
visitor = self.class.resolve_visitor_type(config)
|
125
|
+
( prepared_statements? ? visitor : bind_substitution(visitor) ).new(self)
|
126
|
+
end
|
127
|
+
protected :new_visitor
|
128
|
+
|
129
|
+
def bind_substitution(visitor); self.class.bind_substitution(visitor); end
|
130
|
+
private :bind_substitution
|
131
|
+
|
132
|
+
# @override ActiveRecord's convention
|
133
|
+
def unprepared_visitor
|
134
|
+
# super does self.class::BindSubstitution.new self
|
135
|
+
# we do not require the BindSubstitution constant - auto-generated :
|
136
|
+
visitor = self.class.resolve_visitor_type(config)
|
137
|
+
bind_substitution(visitor).new(self)
|
138
|
+
end
|
139
|
+
|
140
|
+
else # NO-OP when no AREL (AR-2.3)
|
141
|
+
|
142
|
+
# @private documented above
|
143
|
+
def new_visitor; end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
# ActiveRecord::Base extensions.
|
3
|
+
Base.class_eval do
|
4
|
+
class << self
|
5
|
+
# Allow adapters to provide their own {#reset_column_information} method.
|
6
|
+
# @note This only affects the current thread's connection.
|
7
|
+
def reset_column_information_with_arjdbc # :nodoc:
|
8
|
+
# invoke the adapter-specific reset_column_information method
|
9
|
+
connection.reset_column_information if connection.respond_to?(:reset_column_information)
|
10
|
+
reset_column_information_without_arjdbc
|
11
|
+
end
|
12
|
+
unless method_defined?("reset_column_information_without_arjdbc")
|
13
|
+
alias_method_chain :reset_column_information, :arjdbc
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module ConnectionAdapters
|
19
|
+
# Allows properly re-defining methods that may already be alias-chain-ed.
|
20
|
+
# Query caching works even with overriden alias_method_chain'd methods.
|
21
|
+
# @private
|
22
|
+
module ShadowCoreMethods
|
23
|
+
def alias_chained_method(name, feature, target)
|
24
|
+
# NOTE: aliasing for things such as columns (with feature query_cache)
|
25
|
+
# seems to only be used for 2.3 since 3.0 methods are not aliased ...
|
26
|
+
if method_defined?(method = "#{name}_without_#{feature}")
|
27
|
+
alias_method method, target
|
28
|
+
else
|
29
|
+
alias_method name, target if name.to_s != target.to_s
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module ActiveRecord::ConnectionAdapters
|
2
|
+
module Jdbc
|
3
|
+
# ActiveRecord connection pool callbacks for JDBC.
|
4
|
+
# @see ActiveRecord::ConnectionAdapters::Jdbc::JndiConnectionPoolCallbacks
|
5
|
+
module ConnectionPoolCallbacks
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
if base.respond_to?(:set_callback) # Rails 3 callbacks
|
9
|
+
base.set_callback :checkin, :after, :on_checkin
|
10
|
+
base.set_callback :checkout, :before, :on_checkout
|
11
|
+
else
|
12
|
+
base.checkin :on_checkin
|
13
|
+
base.checkout :on_checkout
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def on_checkin
|
18
|
+
# default implementation does nothing
|
19
|
+
end
|
20
|
+
|
21
|
+
def on_checkout
|
22
|
+
# default implementation does nothing
|
23
|
+
end
|
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.
|
28
|
+
module JndiConnectionPoolCallbacks
|
29
|
+
|
30
|
+
def self.prepare(adapter, connection)
|
31
|
+
if adapter.is_a?(ConnectionPoolCallbacks) && connection.jndi?
|
32
|
+
adapter.extend self # extend JndiConnectionPoolCallbacks
|
33
|
+
#connection.disconnect! #if connection.open? # close initial (JNDI) connection
|
34
|
+
connection.disconnect! if connection.open? # close initial (JNDI) connection
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def on_checkin
|
39
|
+
disconnect!
|
40
|
+
end
|
41
|
+
|
42
|
+
def on_checkout
|
43
|
+
reconnect!
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
# @deprecated use {ActiveRecord::ConnectionAdapters::Jdbc::ConnectionPoolCallbacks}
|
49
|
+
JdbcConnectionPoolCallbacks = Jdbc::ConnectionPoolCallbacks
|
50
|
+
# @deprecated use {ActiveRecord::ConnectionAdapters::Jdbc::JndiConnectionPoolCallbacks}
|
51
|
+
JndiConnectionPoolCallbacks = Jdbc::JndiConnectionPoolCallbacks
|
52
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
3
|
+
module Jdbc
|
4
|
+
autoload :TypeCast, 'arjdbc/jdbc/type_cast'
|
5
|
+
end
|
6
|
+
# The base class for all of {JdbcAdapter}'s returned columns.
|
7
|
+
# Instances of {JdbcColumn} will get extended with "column-spec" modules
|
8
|
+
# (similar to how {JdbcAdapter} gets spec modules in) if the adapter spec
|
9
|
+
# module provided a `column_selector` (matcher) method for it's database
|
10
|
+
# specific type.
|
11
|
+
# @see JdbcAdapter#jdbc_column_class
|
12
|
+
class JdbcColumn < Column
|
13
|
+
# @deprecated attribute writers will be removed in 1.4
|
14
|
+
attr_writer :limit, :precision # unless ArJdbc::AR42
|
15
|
+
|
16
|
+
def initialize(config, name, *args)
|
17
|
+
if self.class == JdbcColumn
|
18
|
+
# NOTE: extending classes do not want this if they do they shall call
|
19
|
+
call_discovered_column_callbacks(config) if config
|
20
|
+
default = args.shift
|
21
|
+
else # for extending classes allow ignoring first argument :
|
22
|
+
if ! config.nil? && ! config.is_a?(Hash)
|
23
|
+
default = name; name = config # initialize(name, default, *args)
|
24
|
+
else
|
25
|
+
default = args.shift
|
26
|
+
end
|
27
|
+
end
|
28
|
+
default = default_value(default)
|
29
|
+
|
30
|
+
# super <= 4.1: (name, default, sql_type = nil, null = true)
|
31
|
+
# super >= 4.2: (name, default, cast_type, sql_type = nil, null = true)
|
32
|
+
super(name, default, *args)
|
33
|
+
init_column(name, default, *args)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Additional column initialization for sub-classes.
|
37
|
+
def init_column(*args); end
|
38
|
+
|
39
|
+
# Similar to `ActiveRecord`'s `extract_value_from_default(default)`.
|
40
|
+
# @return default value for a column (possibly extracted from driver value)
|
41
|
+
def default_value(value); value; end
|
42
|
+
|
43
|
+
protected
|
44
|
+
|
45
|
+
# @private
|
46
|
+
def call_discovered_column_callbacks(config)
|
47
|
+
dialect = (config[:dialect] || config[:driver]).to_s
|
48
|
+
for matcher, block in self.class.column_types
|
49
|
+
block.call(config, self) if matcher === dialect
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
public
|
54
|
+
|
55
|
+
# Returns the available column types
|
56
|
+
# @return [Hash] of (matcher, block) pairs
|
57
|
+
def self.column_types
|
58
|
+
types = {}
|
59
|
+
for mod in ::ArJdbc.modules
|
60
|
+
if mod.respond_to?(:column_selector)
|
61
|
+
sel = mod.column_selector # [ matcher, block ]
|
62
|
+
types[ sel[0] ] = sel[1]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
types
|
66
|
+
end
|
67
|
+
|
68
|
+
class << self
|
69
|
+
|
70
|
+
include Jdbc::TypeCast if ::ActiveRecord::VERSION::STRING >= '4.2'
|
71
|
+
|
72
|
+
if ActiveRecord::VERSION::MAJOR > 3 && ActiveRecord::VERSION::STRING < '4.2'
|
73
|
+
|
74
|
+
# @private provides compatibility between AR 3.x/4.0 API
|
75
|
+
def string_to_date(value); value_to_date(value) end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module ConnectionAdapters
|
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 "native" Java, check: *RubyJdbcConnection.java*
|
6
|
+
class JdbcConnection
|
7
|
+
|
8
|
+
# @deprecated no longer used (pass adapter into #initialize)
|
9
|
+
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#initialize
|
10
|
+
def adapter=(adapter)
|
11
|
+
ArJdbc.deprecate "adapter= will be removed, please pass adapter on JdbcConnection#initialize(config, adapter)"
|
12
|
+
set_adapter adapter
|
13
|
+
end
|
14
|
+
|
15
|
+
def native_database_types
|
16
|
+
JdbcTypeConverter.new(supported_data_types).choose_best_types
|
17
|
+
end
|
18
|
+
|
19
|
+
# @deprecated no longer used - only kept for compatibility
|
20
|
+
def set_native_database_types
|
21
|
+
ArJdbc.deprecate "set_native_database_types is no longer used and does nothing override native_database_types instead"
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module ArJdbc
|
2
|
+
if ActiveRecord.const_defined? :ConnectionHandling # 4.0
|
3
|
+
ConnectionMethods = ActiveRecord::ConnectionHandling
|
4
|
+
else # 3.x
|
5
|
+
ConnectionMethods = (class << ActiveRecord::Base; self; end)
|
6
|
+
end
|
7
|
+
ConnectionMethods.module_eval do
|
8
|
+
|
9
|
+
def jdbc_connection(config)
|
10
|
+
adapter_class = config[:adapter_class] || begin
|
11
|
+
if config[:adapter] == 'jdbc' && adapter = supported_adapter(config)
|
12
|
+
ArJdbc.deprecate("please update your **adapter: jdbc** configuration to adapter: #{adapter}", true)
|
13
|
+
end
|
14
|
+
::ActiveRecord::ConnectionAdapters::JdbcAdapter
|
15
|
+
end
|
16
|
+
adapter_class.new(nil, logger, config)
|
17
|
+
end
|
18
|
+
|
19
|
+
def jndi_connection(config)
|
20
|
+
if config[:adapter] == 'jndi'
|
21
|
+
ArJdbc.deprecate("please change your **adapter: jndi** configuration to " <<
|
22
|
+
"the concrete adapter you're wish to use with jndi: '#{config[:jndi]}'", true)
|
23
|
+
end
|
24
|
+
jdbc_connection(config)
|
25
|
+
end
|
26
|
+
|
27
|
+
def embedded_driver(config)
|
28
|
+
config[:username] ||= 'sa'
|
29
|
+
config[:password] ||= ''
|
30
|
+
jdbc_connection(config)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def jndi_config?(config)
|
36
|
+
::ActiveRecord::ConnectionAdapters::JdbcConnection.jndi_config?(config)
|
37
|
+
end
|
38
|
+
|
39
|
+
def supported_adapter(config)
|
40
|
+
return unless driver = config[:driver]
|
41
|
+
case driver
|
42
|
+
when 'com.ibm.db2.jcc.DB2Driver' then 'db2'
|
43
|
+
when /derby/ then 'derby' # 'org.apache.derby.jdbc.EmbeddedDriver'
|
44
|
+
when 'org.firebirdsql.jdbc.FBDriver' then 'firebird'
|
45
|
+
when 'org.h2.Driver' then 'h2'
|
46
|
+
when 'org.hsqldb.jdbcDriver' then 'hsqldb'
|
47
|
+
when 'net.sourceforge.jtds.jdbc.Driver' then 'mssql'
|
48
|
+
when 'com.microsoft.sqlserver.jdbc.SQLServerDriver' then 'sqlserver'
|
49
|
+
when /mysql/ then 'mysql' # 'com.mysql.jdbc.Driver/NonRegisteringDriver'
|
50
|
+
when /mariadb/ then 'mariadb' # 'org.mariadb.jdbc.Driver'
|
51
|
+
when /oracle/ then 'oracle' # 'oracle.jdbc.driver.OracleDriver'
|
52
|
+
when /postgre/i then 'postgresql' # 'org.postgresql.Driver'
|
53
|
+
when /sqlite/i then 'sqlite3' # 'org.sqlite.JDBC'
|
54
|
+
else false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|