activerecord-jdbc-adapter 70.2-java → 71.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +18 -18
- data/.gitignore +8 -0
- data/Gemfile +17 -4
- data/README.md +8 -3
- data/RUNNING_TESTS.md +36 -0
- data/activerecord-jdbc-adapter.gemspec +2 -2
- data/lib/arjdbc/abstract/connection_management.rb +25 -10
- data/lib/arjdbc/abstract/core.rb +5 -12
- data/lib/arjdbc/abstract/database_statements.rb +35 -35
- data/lib/arjdbc/abstract/relation_query_attribute_monkey_patch.rb +24 -0
- data/lib/arjdbc/abstract/statement_cache.rb +2 -7
- data/lib/arjdbc/abstract/transaction_support.rb +37 -22
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/jdbc/column.rb +0 -34
- data/lib/arjdbc/jdbc/connection_methods.rb +1 -1
- data/lib/arjdbc/mysql/adapter.rb +106 -27
- data/lib/arjdbc/postgresql/adapter.rb +252 -105
- data/lib/arjdbc/postgresql/database_statements.rb +20 -0
- data/lib/arjdbc/postgresql/oid_types.rb +8 -27
- data/lib/arjdbc/postgresql/schema_statements.rb +57 -0
- data/lib/arjdbc/sqlite3/adapter.rb +213 -145
- data/lib/arjdbc/sqlite3/column.rb +103 -0
- data/lib/arjdbc/sqlite3/connection_methods.rb +7 -2
- data/lib/arjdbc/version.rb +1 -1
- data/rakelib/02-test.rake +1 -1
- data/rakelib/rails.rake +2 -0
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +4 -2
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +11 -0
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +2 -1
- metadata +11 -10
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecord::ConnectionAdapters
|
4
|
+
class SQLite3Column < JdbcColumn
|
5
|
+
|
6
|
+
attr_reader :rowid
|
7
|
+
|
8
|
+
def initialize(name, default, sql_type_metadata = nil, null = true, default_function = nil, collation: nil, comment: nil, auto_increment: nil, rowid: false, **)
|
9
|
+
super
|
10
|
+
@auto_increment = auto_increment
|
11
|
+
@default = nil if default =~ /NULL/
|
12
|
+
@rowid = rowid
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.string_to_binary(value)
|
16
|
+
value
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.binary_to_string(value)
|
20
|
+
if value.respond_to?(:encoding) && value.encoding != Encoding::ASCII_8BIT
|
21
|
+
value = value.force_encoding(Encoding::ASCII_8BIT)
|
22
|
+
end
|
23
|
+
value
|
24
|
+
end
|
25
|
+
|
26
|
+
# @override {ActiveRecord::ConnectionAdapters::JdbcColumn#default_value}
|
27
|
+
def default_value(value)
|
28
|
+
# JDBC returns column default strings with actual single quotes :
|
29
|
+
return $1 if value =~ /^'(.*)'$/
|
30
|
+
|
31
|
+
value
|
32
|
+
end
|
33
|
+
|
34
|
+
def auto_increment?
|
35
|
+
@auto_increment
|
36
|
+
end
|
37
|
+
|
38
|
+
def auto_incremented_by_db?
|
39
|
+
auto_increment? || rowid
|
40
|
+
end
|
41
|
+
|
42
|
+
def init_with(coder)
|
43
|
+
@auto_increment = coder["auto_increment"]
|
44
|
+
super
|
45
|
+
end
|
46
|
+
|
47
|
+
def encode_with(coder)
|
48
|
+
coder["auto_increment"] = @auto_increment
|
49
|
+
super
|
50
|
+
end
|
51
|
+
|
52
|
+
def ==(other)
|
53
|
+
other.is_a?(Column) &&
|
54
|
+
super &&
|
55
|
+
auto_increment? == other.auto_increment?
|
56
|
+
end
|
57
|
+
alias :eql? :==
|
58
|
+
|
59
|
+
def hash
|
60
|
+
Column.hash ^
|
61
|
+
super.hash ^
|
62
|
+
auto_increment?.hash ^
|
63
|
+
rowid.hash
|
64
|
+
end
|
65
|
+
|
66
|
+
# @override {ActiveRecord::ConnectionAdapters::Column#type_cast}
|
67
|
+
def type_cast(value)
|
68
|
+
return nil if value.nil?
|
69
|
+
case type
|
70
|
+
when :string then value
|
71
|
+
when :primary_key
|
72
|
+
value.respond_to?(:to_i) ? value.to_i : ( value ? 1 : 0 )
|
73
|
+
when :float then value.to_f
|
74
|
+
when :decimal then self.class.value_to_decimal(value)
|
75
|
+
when :boolean then self.class.value_to_boolean(value)
|
76
|
+
else super
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
# @override {ActiveRecord::ConnectionAdapters::Column#extract_limit}
|
83
|
+
def extract_limit(sql_type)
|
84
|
+
return nil if sql_type =~ /^(real)\(\d+/i
|
85
|
+
super
|
86
|
+
end
|
87
|
+
|
88
|
+
def extract_precision(sql_type)
|
89
|
+
case sql_type
|
90
|
+
when /^(real)\((\d+)(,\d+)?\)/i then $2.to_i
|
91
|
+
else super
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def extract_scale(sql_type)
|
96
|
+
case sql_type
|
97
|
+
when /^(real)\((\d+)\)/i then 0
|
98
|
+
when /^(real)\((\d+)(,(\d+))\)/i then $4.to_i
|
99
|
+
else super
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
ArJdbc::ConnectionMethods.module_eval do
|
3
3
|
def sqlite3_connection(config)
|
4
|
+
raise ArgumentError, 'Configuration must not be empty' if config.blank?
|
5
|
+
|
4
6
|
config = config.deep_dup
|
5
7
|
config[:adapter_spec] ||= ::ArJdbc::SQLite3
|
6
8
|
config[:adapter_class] = ActiveRecord::ConnectionAdapters::SQLite3Adapter unless config.key?(:adapter_class)
|
@@ -18,7 +20,7 @@ ArJdbc::ConnectionMethods.module_eval do
|
|
18
20
|
parse_sqlite3_config!(config)
|
19
21
|
rescue Errno::ENOENT => error
|
20
22
|
if error.message.include?('No such file or directory')
|
21
|
-
raise ActiveRecord::NoDatabaseError
|
23
|
+
raise ActiveRecord::NoDatabaseError.new(connection_pool: ActiveRecord::ConnectionAdapters::NullPool.new)
|
22
24
|
else
|
23
25
|
raise
|
24
26
|
end
|
@@ -50,7 +52,10 @@ ArJdbc::ConnectionMethods.module_eval do
|
|
50
52
|
|
51
53
|
timeout = config[:timeout]
|
52
54
|
if timeout && timeout.to_s !~ /\A\d+\Z/
|
53
|
-
raise
|
55
|
+
raise ActiveRecord::StatementInvalid.new(
|
56
|
+
"TypeError: Timeout must be nil or a number (got: #{timeout}).",
|
57
|
+
connection_pool: ActiveRecord::ConnectionAdapters::NullPool.new
|
58
|
+
)
|
54
59
|
end
|
55
60
|
|
56
61
|
options = config[:properties]
|
data/lib/arjdbc/version.rb
CHANGED
data/rakelib/02-test.rake
CHANGED
@@ -40,7 +40,7 @@ def test_task_for(adapter, options = {})
|
|
40
40
|
test_task.libs.push *FileList["activerecord-jdbc#{adapter}*/lib"]
|
41
41
|
end
|
42
42
|
test_task.libs << 'test'
|
43
|
-
test_task.options = '--use-color=t'
|
43
|
+
test_task.options = '--use-color=t --progress-style=mark'
|
44
44
|
test_task.verbose = true if $VERBOSE
|
45
45
|
yield(test_task) if block_given?
|
46
46
|
end
|
data/rakelib/rails.rake
CHANGED
@@ -34,6 +34,7 @@ namespace :rails do
|
|
34
34
|
File.join(root_dir, 'lib'),
|
35
35
|
File.join(root_dir, driver, 'lib'),
|
36
36
|
File.join(root_dir, 'test/rails'),
|
37
|
+
File.join(root_dir, 'jdbc-sqlite3', 'lib'), # Added for connection management tests which hardcode sqlite3
|
37
38
|
ar_test_dir
|
38
39
|
]
|
39
40
|
|
@@ -51,6 +52,7 @@ namespace :rails do
|
|
51
52
|
ruby_opts_string += " -C \"#{ar_path}\""
|
52
53
|
ruby_opts_string += " -rbundler/setup"
|
53
54
|
ruby_opts_string += " -rminitest -rminitest/excludes" unless ENV['NO_EXCLUDES'].eql?('true')
|
55
|
+
ruby_opts_string += " -rmonkey_patches"
|
54
56
|
file_list = ENV["TEST"] ? FileList[ ENV["TEST"].split(',') ] : test_files_finder.call
|
55
57
|
file_list_string = file_list.map { |fn| "\"#{fn}\"" }.join(' ')
|
56
58
|
# test_loader_code = "-e \"ARGV.each{|f| require f}\"" # :direct
|
@@ -793,7 +793,8 @@ public class RubyJdbcConnection extends RubyObject {
|
|
793
793
|
// Unfortunately the result set gets closed when getMoreResults()
|
794
794
|
// is called, so we have to process the result sets as we get them
|
795
795
|
// this shouldn't be an issue in most cases since we're only getting 1 result set anyways
|
796
|
-
result = mapExecuteResult(context, connection, resultSet);
|
796
|
+
//result = mapExecuteResult(context, connection, resultSet);
|
797
|
+
result = mapToRawResult(context, connection, resultSet, false);
|
797
798
|
resultSet.close();
|
798
799
|
} else {
|
799
800
|
result = context.runtime.newFixnum(updateCount);
|
@@ -2726,8 +2727,9 @@ public class RubyJdbcConnection extends RubyObject {
|
|
2726
2727
|
statement.setDouble(index, ((RubyNumeric) value).getDoubleValue());
|
2727
2728
|
}
|
2728
2729
|
else { // e.g. `BigDecimal '42.00000000000000000001'`
|
2730
|
+
Ruby runtime = context.runtime;
|
2729
2731
|
statement.setBigDecimal(index,
|
2730
|
-
RubyBigDecimal.newInstance(context,
|
2732
|
+
RubyBigDecimal.newInstance(context, runtime.getModule("BigDecimal"), value, RubyFixnum.zero(runtime)).getValue());
|
2731
2733
|
}
|
2732
2734
|
}
|
2733
2735
|
|
@@ -119,6 +119,17 @@ public class MySQLRubyJdbcConnection extends RubyJdbcConnection {
|
|
119
119
|
return driverWrapper;
|
120
120
|
}
|
121
121
|
|
122
|
+
@JRubyMethod(name = "ping")
|
123
|
+
public RubyBoolean db_ping(final ThreadContext context) {
|
124
|
+
final Connection connection = getConnection(true);
|
125
|
+
if (connection == null) return context.fals;
|
126
|
+
|
127
|
+
// NOTE: It seems only `connection.isValid(aliveTimeout)` is needed
|
128
|
+
// for JDBC 4.0 and up. https://jira.mariadb.org/browse/CONJ-51
|
129
|
+
|
130
|
+
return context.runtime.newBoolean(isConnectionValid(context, connection));
|
131
|
+
}
|
132
|
+
|
122
133
|
private static transient Class MYSQL_CONNECTION;
|
123
134
|
private static transient Boolean MYSQL_CONNECTION_FOUND;
|
124
135
|
|
@@ -511,7 +511,8 @@ public class SQLite3RubyJdbcConnection extends RubyJdbcConnection {
|
|
511
511
|
statement.setDouble(index, ((RubyNumeric) value).getDoubleValue());
|
512
512
|
}
|
513
513
|
else { // e.g. `BigDecimal '42.00000000000000000001'`
|
514
|
-
|
514
|
+
Ruby runtime = context.runtime;
|
515
|
+
RubyBigDecimal val = RubyBigDecimal.newInstance(context, runtime.getModule("BigDecimal"), value, RubyFixnum.zero(runtime));
|
515
516
|
statement.setString(index, val.getValue().toString());
|
516
517
|
}
|
517
518
|
}
|
metadata
CHANGED
@@ -1,32 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-jdbc-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '
|
4
|
+
version: '71.0'
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Nick Sieger, Ola Bini, Karol Bucek and JRuby contributors
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-01-24 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
13
|
+
name: activerecord
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
15
15
|
requirements:
|
16
16
|
- - "~>"
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version:
|
19
|
-
name: activerecord
|
18
|
+
version: 7.1.3
|
20
19
|
type: :runtime
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
23
|
- - "~>"
|
25
24
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
25
|
+
version: 7.1.3
|
27
26
|
description: 'AR-JDBC is a database adapter for Rails'' ActiveRecord component designed
|
28
27
|
to be used with JRuby built upon Java''s JDBC API for database access. Provides
|
29
|
-
(ActiveRecord) built-in adapters: MySQL, PostgreSQL,
|
28
|
+
(ActiveRecord) built-in adapters: MySQL, PostgreSQL, and SQLite3.'
|
30
29
|
email:
|
31
30
|
- nick@nicksieger.com
|
32
31
|
- ola.bini@gmail.com
|
@@ -69,6 +68,7 @@ files:
|
|
69
68
|
- lib/arjdbc/abstract/connection_management.rb
|
70
69
|
- lib/arjdbc/abstract/core.rb
|
71
70
|
- lib/arjdbc/abstract/database_statements.rb
|
71
|
+
- lib/arjdbc/abstract/relation_query_attribute_monkey_patch.rb
|
72
72
|
- lib/arjdbc/abstract/statement_cache.rb
|
73
73
|
- lib/arjdbc/abstract/transaction_support.rb
|
74
74
|
- lib/arjdbc/discover.rb
|
@@ -110,11 +110,14 @@ files:
|
|
110
110
|
- lib/arjdbc/postgresql/base/pgconn.rb
|
111
111
|
- lib/arjdbc/postgresql/column.rb
|
112
112
|
- lib/arjdbc/postgresql/connection_methods.rb
|
113
|
+
- lib/arjdbc/postgresql/database_statements.rb
|
113
114
|
- lib/arjdbc/postgresql/name.rb
|
114
115
|
- lib/arjdbc/postgresql/oid_types.rb
|
116
|
+
- lib/arjdbc/postgresql/schema_statements.rb
|
115
117
|
- lib/arjdbc/railtie.rb
|
116
118
|
- lib/arjdbc/sqlite3.rb
|
117
119
|
- lib/arjdbc/sqlite3/adapter.rb
|
120
|
+
- lib/arjdbc/sqlite3/column.rb
|
118
121
|
- lib/arjdbc/sqlite3/connection_methods.rb
|
119
122
|
- lib/arjdbc/tasks.rb
|
120
123
|
- lib/arjdbc/tasks/database_tasks.rb
|
@@ -181,7 +184,6 @@ homepage: https://github.com/jruby/activerecord-jdbc-adapter
|
|
181
184
|
licenses:
|
182
185
|
- BSD-2-Clause
|
183
186
|
metadata: {}
|
184
|
-
post_install_message:
|
185
187
|
rdoc_options:
|
186
188
|
- "--main"
|
187
189
|
- README.md
|
@@ -198,8 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
200
|
- !ruby/object:Gem::Version
|
199
201
|
version: '0'
|
200
202
|
requirements: []
|
201
|
-
rubygems_version: 3.
|
202
|
-
signing_key:
|
203
|
+
rubygems_version: 3.6.0.dev
|
203
204
|
specification_version: 4
|
204
205
|
summary: JDBC adapter for ActiveRecord, for use within JRuby on Rails.
|
205
206
|
test_files: []
|