activerecord-jdbc-adapter 52.7-java → 60.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -2
- data/.travis.yml +58 -37
- data/Gemfile +9 -2
- data/README.md +25 -9
- data/Rakefile +1 -1
- data/Rakefile.jdbc +8 -1
- data/activerecord-jdbc-adapter.gemspec +5 -8
- data/lib/arjdbc/abstract/connection_management.rb +7 -0
- data/lib/arjdbc/abstract/core.rb +16 -23
- data/lib/arjdbc/abstract/database_statements.rb +26 -2
- data/lib/arjdbc/abstract/statement_cache.rb +2 -5
- data/lib/arjdbc/abstract/transaction_support.rb +5 -3
- data/lib/arjdbc/db2/column.rb +0 -39
- data/lib/arjdbc/derby/adapter.rb +1 -20
- data/lib/arjdbc/firebird/adapter.rb +0 -21
- data/lib/arjdbc/h2/adapter.rb +0 -15
- data/lib/arjdbc/hsqldb/adapter.rb +0 -14
- data/lib/arjdbc/informix/adapter.rb +0 -23
- data/lib/arjdbc/jdbc/adapter.rb +3 -1
- data/lib/arjdbc/jdbc/adapter_require.rb +3 -1
- data/lib/arjdbc/jdbc/base_ext.rb +3 -1
- data/lib/arjdbc/jdbc/callbacks.rb +2 -0
- data/lib/arjdbc/jdbc/column.rb +2 -0
- data/lib/arjdbc/jdbc/connection.rb +2 -0
- data/lib/arjdbc/jdbc/connection_methods.rb +2 -0
- data/lib/arjdbc/jdbc/error.rb +2 -0
- data/lib/arjdbc/jdbc/extension.rb +2 -0
- data/lib/arjdbc/jdbc/java.rb +3 -1
- data/lib/arjdbc/jdbc/railtie.rb +3 -1
- data/lib/arjdbc/jdbc/rake_tasks.rb +3 -1
- data/lib/arjdbc/jdbc/serialized_attributes_helper.rb +3 -1
- data/lib/arjdbc/jdbc/type_cast.rb +2 -0
- data/lib/arjdbc/jdbc/type_converter.rb +2 -0
- data/lib/arjdbc/mysql/adapter.rb +47 -18
- data/lib/arjdbc/mysql/connection_methods.rb +0 -1
- data/lib/arjdbc/postgresql/adapter.rb +220 -213
- data/lib/arjdbc/postgresql/base/array_decoder.rb +2 -0
- data/lib/arjdbc/postgresql/base/array_encoder.rb +4 -2
- data/lib/arjdbc/postgresql/base/array_parser.rb +4 -2
- data/lib/arjdbc/postgresql/base/pgconn.rb +2 -0
- data/lib/arjdbc/postgresql/column.rb +6 -4
- data/lib/arjdbc/postgresql/connection_methods.rb +0 -1
- data/lib/arjdbc/postgresql/name.rb +2 -0
- data/lib/arjdbc/postgresql/oid_types.rb +2 -0
- data/lib/arjdbc/sqlite3/adapter.rb +175 -180
- data/lib/arjdbc/sqlite3/connection_methods.rb +15 -5
- data/lib/arjdbc/tasks/databases.rake +13 -10
- data/lib/arjdbc/util/quoted_cache.rb +3 -1
- data/lib/arjdbc/util/serialized_attributes.rb +3 -1
- data/lib/arjdbc/util/table_copier.rb +3 -1
- data/lib/arjdbc/version.rb +1 -1
- data/pom.xml +4 -4
- data/rakelib/01-tomcat.rake +2 -2
- data/rakelib/rails.rake +1 -1
- data/src/java/arjdbc/ArJdbcModule.java +5 -5
- data/src/java/arjdbc/jdbc/DriverWrapper.java +1 -9
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +434 -701
- data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +0 -51
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +13 -23
- data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +31 -24
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +94 -99
- metadata +8 -10
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ArJdbc
|
2
4
|
module Abstract
|
3
5
|
|
@@ -22,7 +24,7 @@ module ArJdbc
|
|
22
24
|
# Starts a database transaction.
|
23
25
|
# @override
|
24
26
|
def begin_db_transaction
|
25
|
-
log('BEGIN TRANSACTION'
|
27
|
+
log('BEGIN TRANSACTION', nil) { @connection.begin }
|
26
28
|
end
|
27
29
|
|
28
30
|
# Starts a database transaction.
|
@@ -34,14 +36,14 @@ module ArJdbc
|
|
34
36
|
# Commits the current database transaction.
|
35
37
|
# @override
|
36
38
|
def commit_db_transaction
|
37
|
-
log('COMMIT TRANSACTION'
|
39
|
+
log('COMMIT TRANSACTION', nil) { @connection.commit }
|
38
40
|
end
|
39
41
|
|
40
42
|
# Rolls back the current database transaction.
|
41
43
|
# Called from 'rollback_db_transaction' in the AbstractAdapter
|
42
44
|
# @override
|
43
45
|
def exec_rollback_db_transaction
|
44
|
-
log('ROLLBACK TRANSACTION'
|
46
|
+
log('ROLLBACK TRANSACTION', nil) { @connection.rollback }
|
45
47
|
end
|
46
48
|
|
47
49
|
########################## Savepoint Interface ############################
|
data/lib/arjdbc/db2/column.rb
CHANGED
@@ -80,45 +80,6 @@ module ArJdbc
|
|
80
80
|
|
81
81
|
private
|
82
82
|
|
83
|
-
def simplified_type(field_type)
|
84
|
-
case field_type
|
85
|
-
when /^decimal\(1\)$/i then DB2.emulate_booleans? ? :boolean : :integer
|
86
|
-
when /smallint/i then DB2.emulate_booleans? ? :boolean : :integer
|
87
|
-
when /boolean/i then :boolean
|
88
|
-
when /^real|double/i then :float
|
89
|
-
when /int|serial/i then :integer
|
90
|
-
# if a numeric column has no scale, lets treat it as an integer.
|
91
|
-
# The AS400 rpg guys do this ALOT since they have no integer datatype ...
|
92
|
-
when /decimal|numeric|decfloat/i
|
93
|
-
extract_scale(field_type) == 0 ? :integer : :decimal
|
94
|
-
when /timestamp/i then :timestamp
|
95
|
-
when /datetime/i then :datetime
|
96
|
-
when /time/i then :time
|
97
|
-
when /date/i then :date
|
98
|
-
# DB2 provides three data types to store these data objects as strings of up to 2 GB in size:
|
99
|
-
# Character large objects (CLOBs)
|
100
|
-
# Use the CLOB data type to store SBCS or mixed data, such as documents that contain
|
101
|
-
# single character set. Use this data type if your data is larger (or might grow larger)
|
102
|
-
# than the VARCHAR data type permits.
|
103
|
-
# Double-byte character large objects (DBCLOBs)
|
104
|
-
# Use the DBCLOB data type to store large amounts of DBCS data, such as documents that
|
105
|
-
# use a DBCS character set.
|
106
|
-
# Binary large objects (BLOBs)
|
107
|
-
# Use the BLOB data type to store large amounts of noncharacter data, such as pictures,
|
108
|
-
# voice, and mixed media.
|
109
|
-
when /clob|text/i then :text # handles DBCLOB
|
110
|
-
when /^long varchar/i then :text # :limit => 32700
|
111
|
-
when /blob|binary/i then :binary
|
112
|
-
# varchar () for bit data, char () for bit data, long varchar for bit data
|
113
|
-
when /for bit data/i then :binary
|
114
|
-
when /xml/i then :xml
|
115
|
-
when /graphic/i then :graphic # vargraphic, long vargraphic
|
116
|
-
when /rowid/i then :rowid # rowid is a supported datatype on z/OS and i/5
|
117
|
-
else
|
118
|
-
super
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
83
|
# Post process default value from JDBC into a Rails-friendly format (columns{-internal})
|
123
84
|
def default_value(value)
|
124
85
|
# IBM i (AS400) will return an empty string instead of null for no default
|
data/lib/arjdbc/derby/adapter.rb
CHANGED
@@ -65,25 +65,6 @@ module ArJdbc
|
|
65
65
|
limit
|
66
66
|
end
|
67
67
|
|
68
|
-
def simplified_type(field_type)
|
69
|
-
case field_type
|
70
|
-
when /^smallint/i then Derby.emulate_booleans? ? :boolean : :integer
|
71
|
-
when /^bigint|int/i then :integer
|
72
|
-
when /^real|double/i then :float
|
73
|
-
when /^dec/i then # DEC is a DECIMAL alias
|
74
|
-
extract_scale(field_type) == 0 ? :integer : :decimal
|
75
|
-
when /^timestamp/i then :datetime
|
76
|
-
when /^xml/i then :xml
|
77
|
-
when 'long varchar' then :text
|
78
|
-
when /for bit data/i then :binary
|
79
|
-
# :name=>"long varchar for bit data", :limit=>32700
|
80
|
-
# :name=>"varchar() for bit data", :limit=>32672
|
81
|
-
# :name=>"char() for bit data", :limit=>254}
|
82
|
-
else
|
83
|
-
super
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
68
|
# Post process default value from JDBC into a Rails-friendly format (columns{-internal})
|
88
69
|
def default_value(value)
|
89
70
|
# JDBC returns column default strings with actual single quotes around the value.
|
@@ -420,7 +401,7 @@ module ArJdbc
|
|
420
401
|
|
421
402
|
# @override
|
422
403
|
def supports_ddl_transactions?; true end
|
423
|
-
|
404
|
+
|
424
405
|
# @override
|
425
406
|
def supports_foreign_keys?; true end
|
426
407
|
|
@@ -38,27 +38,6 @@ module ArJdbc
|
|
38
38
|
return $1 unless $1.upcase == 'NULL'
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def simplified_type(field_type)
|
45
|
-
case field_type
|
46
|
-
when /timestamp/i then :datetime
|
47
|
-
when /^smallint/i then :integer
|
48
|
-
when /^bigint|int/i then :integer
|
49
|
-
when /^double/i then :float # double precision
|
50
|
-
when /^decimal/i then
|
51
|
-
extract_scale(field_type) == 0 ? :integer : :decimal
|
52
|
-
when /^char\(1\)$/i then Firebird.emulate_booleans? ? :boolean : :string
|
53
|
-
when /^char/i then :string
|
54
|
-
when /^blob\ssub_type\s(\d)/i
|
55
|
-
return :binary if $1 == '0'
|
56
|
-
return :text if $1 == '1'
|
57
|
-
else
|
58
|
-
super
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
41
|
end
|
63
42
|
|
64
43
|
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_column_class
|
data/lib/arjdbc/h2/adapter.rb
CHANGED
@@ -47,21 +47,6 @@ module ArJdbc
|
|
47
47
|
limit
|
48
48
|
end
|
49
49
|
|
50
|
-
def simplified_type(field_type)
|
51
|
-
case field_type
|
52
|
-
when /^bit|bool/i then :boolean
|
53
|
-
when /^signed|year/i then :integer
|
54
|
-
when /^real|double/i then :float
|
55
|
-
when /^varchar/i then :string
|
56
|
-
when /^longvarchar/i then :text
|
57
|
-
when /^binary|raw|bytea/i then :binary
|
58
|
-
when /varbinary/i then :binary # longvarbinary, varbinary
|
59
|
-
when /^blob|image|oid/i then :binary
|
60
|
-
else
|
61
|
-
super
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
50
|
# Post process default value from JDBC into a Rails-friendly format (columns{-internal})
|
66
51
|
def default_value(value)
|
67
52
|
# H2 auto-generated key default value
|
@@ -42,20 +42,6 @@ module ArJdbc
|
|
42
42
|
limit
|
43
43
|
end
|
44
44
|
|
45
|
-
def simplified_type(field_type)
|
46
|
-
case field_type
|
47
|
-
when /^nvarchar/i then :string
|
48
|
-
when /^character/i then :string
|
49
|
-
when /^longvarchar/i then :text
|
50
|
-
when /int/i then :integer # TINYINT, SMALLINT, BIGINT, INT
|
51
|
-
when /real|double/i then :float
|
52
|
-
when /^bit/i then :boolean
|
53
|
-
when /binary/i then :binary # VARBINARY, LONGVARBINARY
|
54
|
-
else
|
55
|
-
super
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
45
|
# Post process default value from JDBC into a Rails-friendly format (columns{-internal})
|
60
46
|
def default_value(value)
|
61
47
|
# JDBC returns column default strings with actual single quotes around the value.
|
@@ -28,11 +28,6 @@ module ArJdbc
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
# @see ActiveRecord::ConnectionAdapters::JdbcColumn#column_types
|
32
|
-
def self.column_selector
|
33
|
-
[ /informix/i, lambda { |cfg, column| column.extend(ColumnMethods) } ]
|
34
|
-
end
|
35
|
-
|
36
31
|
JdbcConnection = ::ActiveRecord::ConnectionAdapters::InformixJdbcConnection
|
37
32
|
|
38
33
|
# @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
|
@@ -45,20 +40,6 @@ module ArJdbc
|
|
45
40
|
::ActiveRecord::ConnectionAdapters::InformixColumn
|
46
41
|
end
|
47
42
|
|
48
|
-
module ColumnMethods
|
49
|
-
|
50
|
-
private
|
51
|
-
# TODO: Test all Informix column types.
|
52
|
-
def simplified_type(field_type)
|
53
|
-
if field_type =~ /serial/i
|
54
|
-
:primary_key
|
55
|
-
else
|
56
|
-
super
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
|
62
43
|
def modify_types(types)
|
63
44
|
super(types)
|
64
45
|
types[:primary_key] = "SERIAL PRIMARY KEY"
|
@@ -152,10 +133,6 @@ module ArJdbc
|
|
152
133
|
end # module ::ArJdbc
|
153
134
|
|
154
135
|
module ActiveRecord::ConnectionAdapters
|
155
|
-
class InformixColumn < JdbcColumn
|
156
|
-
include ::ArJdbc::Informix::ColumnMethods
|
157
|
-
end
|
158
|
-
|
159
136
|
class InformixAdapter < JdbcAdapter
|
160
137
|
include ::ArJdbc::Informix
|
161
138
|
end
|
data/lib/arjdbc/jdbc/adapter.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'active_record/version'
|
2
4
|
require 'active_record/connection_adapters/abstract_adapter'
|
3
5
|
|
@@ -94,7 +96,7 @@ module ActiveRecord
|
|
94
96
|
nil
|
95
97
|
end
|
96
98
|
|
97
|
-
ADAPTER_NAME = 'JDBC'
|
99
|
+
ADAPTER_NAME = 'JDBC'
|
98
100
|
|
99
101
|
# @return [String] the 'JDBC' adapter name.
|
100
102
|
def adapter_name
|
data/lib/arjdbc/jdbc/base_ext.rb
CHANGED
data/lib/arjdbc/jdbc/column.rb
CHANGED
data/lib/arjdbc/jdbc/error.rb
CHANGED
data/lib/arjdbc/jdbc/java.rb
CHANGED
data/lib/arjdbc/jdbc/railtie.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'arjdbc/util/serialized_attributes'
|
2
4
|
|
3
|
-
ArJdbc.deprecate "require 'arjdbc/util/serialized_attributes' instead of 'arjdbc/jdbc/serialized_attributes_helper'"
|
5
|
+
ArJdbc.deprecate "require 'arjdbc/util/serialized_attributes' instead of 'arjdbc/jdbc/serialized_attributes_helper'"
|
data/lib/arjdbc/mysql/adapter.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
ArJdbc.load_java_part :MySQL
|
2
4
|
|
3
5
|
require 'bigdecimal'
|
@@ -19,7 +21,7 @@ module ActiveRecord
|
|
19
21
|
remove_const(:Mysql2Adapter) if const_defined?(:Mysql2Adapter)
|
20
22
|
|
21
23
|
class Mysql2Adapter < AbstractMysqlAdapter
|
22
|
-
ADAPTER_NAME = 'Mysql2'
|
24
|
+
ADAPTER_NAME = 'Mysql2'
|
23
25
|
|
24
26
|
include Jdbc::ConnectionPoolCallbacks
|
25
27
|
|
@@ -32,21 +34,30 @@ module ActiveRecord
|
|
32
34
|
include ArJdbc::MySQL
|
33
35
|
|
34
36
|
def initialize(connection, logger, connection_parameters, config)
|
35
|
-
# workaround to skip version check on JNDI to be lazy, dummy version is high enough for Rails 5.0 - 6.0
|
36
|
-
is_jndi = ::ActiveRecord::ConnectionAdapters::JdbcConnection.jndi_config?(config)
|
37
|
-
@version = '8.1.5' if is_jndi
|
38
|
-
|
39
37
|
super
|
40
38
|
|
41
|
-
# set to nil to have it lazy-load the real value when required
|
42
|
-
@version = nil if is_jndi
|
43
|
-
|
44
39
|
@prepared_statements = false unless config.key?(:prepared_statements)
|
45
40
|
# configure_connection taken care of at ArJdbc::Abstract::Core
|
46
41
|
end
|
47
42
|
|
43
|
+
def self.database_exists?(config)
|
44
|
+
conn = ActiveRecord::Base.mysql2_connection(config)
|
45
|
+
conn && conn.really_valid?
|
46
|
+
rescue ActiveRecord::NoDatabaseError
|
47
|
+
false
|
48
|
+
ensure
|
49
|
+
conn.disconnect! if conn
|
50
|
+
end
|
51
|
+
|
52
|
+
def check_version
|
53
|
+
# for JNDI, don't check version as the whole connection should be lazy
|
54
|
+
return if ::ActiveRecord::ConnectionAdapters::JdbcConnection.jndi_config?(config)
|
55
|
+
|
56
|
+
super
|
57
|
+
end
|
58
|
+
|
48
59
|
def supports_json?
|
49
|
-
!mariadb? &&
|
60
|
+
!mariadb? && database_version >= '5.7.8'
|
50
61
|
end
|
51
62
|
|
52
63
|
def supports_comments?
|
@@ -61,6 +72,10 @@ module ActiveRecord
|
|
61
72
|
true
|
62
73
|
end
|
63
74
|
|
75
|
+
def supports_lazy_transactions?
|
76
|
+
true
|
77
|
+
end
|
78
|
+
|
64
79
|
def supports_transaction_isolation?
|
65
80
|
true
|
66
81
|
end
|
@@ -71,6 +86,16 @@ module ActiveRecord
|
|
71
86
|
|
72
87
|
# HELPER METHODS ===========================================
|
73
88
|
|
89
|
+
# from MySQL::DatabaseStatements
|
90
|
+
READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(
|
91
|
+
:begin, :commit, :explain, :select, :set, :show, :release, :savepoint, :rollback, :describe, :desc
|
92
|
+
) # :nodoc:
|
93
|
+
private_constant :READ_QUERY
|
94
|
+
|
95
|
+
def write_query?(sql) # :nodoc:
|
96
|
+
!READ_QUERY.match?(sql)
|
97
|
+
end
|
98
|
+
|
74
99
|
# Reloading the type map in abstract/statement_cache.rb blows up postgres
|
75
100
|
def clear_cache!
|
76
101
|
reload_type_map
|
@@ -136,7 +161,13 @@ module ActiveRecord
|
|
136
161
|
private
|
137
162
|
|
138
163
|
# e.g. "5.7.20-0ubuntu0.16.04.1"
|
139
|
-
def full_version
|
164
|
+
def full_version
|
165
|
+
schema_cache.database_version.full_version_string
|
166
|
+
end
|
167
|
+
|
168
|
+
def get_full_version
|
169
|
+
@full_version ||= @connection.full_version
|
170
|
+
end
|
140
171
|
|
141
172
|
def jdbc_connection_class(spec)
|
142
173
|
::ActiveRecord::ConnectionAdapters::MySQLJdbcConnection
|
@@ -152,15 +183,13 @@ module ActiveRecord
|
|
152
183
|
end
|
153
184
|
|
154
185
|
# FIXME: optimize insert_fixtures_set by using JDBC Statement.addBatch()/executeBatch()
|
155
|
-
def combine_multi_statements(total_sql)
|
156
|
-
total_sql
|
157
|
-
end
|
158
|
-
|
159
|
-
def with_multi_statements
|
160
|
-
yield
|
161
|
-
end
|
162
186
|
|
163
|
-
def
|
187
|
+
def combine_multi_statements(total_sql)
|
188
|
+
if total_sql.length == 1
|
189
|
+
total_sql.first
|
190
|
+
else
|
191
|
+
total_sql
|
192
|
+
end
|
164
193
|
end
|
165
194
|
end
|
166
195
|
end
|