activerecord-jdbc-adapter 71.0-java → 72.1-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +11 -11
- data/README.md +2 -2
- data/activerecord-jdbc-adapter.gemspec +1 -1
- data/lib/arjdbc/abstract/core.rb +10 -1
- data/lib/arjdbc/abstract/database_statements.rb +1 -1
- data/lib/arjdbc/abstract/transaction_support.rb +3 -1
- data/lib/arjdbc/jdbc/adapter.rb +0 -1
- data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
- data/lib/arjdbc/mysql/adapter.rb +8 -11
- data/lib/arjdbc/mysql/adapter_hash_config.rb +160 -0
- data/lib/arjdbc/mysql.rb +1 -1
- data/lib/arjdbc/postgresql/adapter.rb +17 -11
- data/lib/arjdbc/postgresql/adapter_hash_config.rb +98 -0
- data/lib/arjdbc/postgresql/base/array_encoder.rb +3 -1
- data/lib/arjdbc/postgresql/oid_types.rb +2 -2
- data/lib/arjdbc/postgresql.rb +1 -1
- data/lib/arjdbc/sqlite3/adapter.rb +193 -90
- data/lib/arjdbc/sqlite3/adapter_hash_config.rb +91 -0
- data/lib/arjdbc/sqlite3/column.rb +17 -3
- data/lib/arjdbc/sqlite3/pragmas.rb +105 -0
- data/lib/arjdbc/sqlite3.rb +1 -1
- data/lib/arjdbc/version.rb +1 -1
- data/lib/arjdbc.rb +13 -1
- data/rakelib/02-test.rake +1 -1
- data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +5 -0
- data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +1 -5
- data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +12 -2
- metadata +9 -6
- data/lib/arjdbc/jdbc/base_ext.rb +0 -17
@@ -0,0 +1,105 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SQLite3
|
4
|
+
# defines methods to de generate pragma statements
|
5
|
+
module Pragmas
|
6
|
+
class << self
|
7
|
+
# The enumeration of valid synchronous modes.
|
8
|
+
SYNCHRONOUS_MODES = [["full", 2], ["normal", 1], ["off", 0]].freeze
|
9
|
+
|
10
|
+
# The enumeration of valid temp store modes.
|
11
|
+
TEMP_STORE_MODES = [["default", 0], ["file", 1], ["memory", 2]].freeze
|
12
|
+
|
13
|
+
# The enumeration of valid auto vacuum modes.
|
14
|
+
AUTO_VACUUM_MODES = [["none", 0], ["full", 1], ["incremental", 2]].freeze
|
15
|
+
|
16
|
+
# The list of valid journaling modes.
|
17
|
+
JOURNAL_MODES = [["delete"], ["truncate"], ["persist"], ["memory"], ["wal"], ["off"]].freeze
|
18
|
+
|
19
|
+
# The list of valid locking modes.
|
20
|
+
LOCKING_MODES = [["normal"], ["exclusive"]].freeze
|
21
|
+
|
22
|
+
# The list of valid encodings.
|
23
|
+
ENCODINGS = [["utf-8"], ["utf-16"], ["utf-16le"], ["utf-16be"]].freeze
|
24
|
+
|
25
|
+
# The list of valid WAL checkpoints.
|
26
|
+
WAL_CHECKPOINTS = [["passive"], ["full"], ["restart"], ["truncate"]].freeze
|
27
|
+
|
28
|
+
# Enforce foreign key constraints
|
29
|
+
# https://www.sqlite.org/pragma.html#pragma_foreign_keys
|
30
|
+
# https://www.sqlite.org/foreignkeys.html
|
31
|
+
def foreign_keys(value)
|
32
|
+
gen_boolean_pragma(:foreign_keys, value)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Journal mode WAL allows for greater concurrency (many readers + one writer)
|
36
|
+
# https://www.sqlite.org/pragma.html#pragma_journal_mode
|
37
|
+
def journal_mode(value)
|
38
|
+
gen_enum_pragma(:journal_mode, value, JOURNAL_MODES)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Set more relaxed level of database durability
|
42
|
+
# 2 = "FULL" (sync on every write), 1 = "NORMAL" (sync every 1000 written pages) and 0 = "NONE"
|
43
|
+
# https://www.sqlite.org/pragma.html#pragma_synchronous
|
44
|
+
def synchronous(value)
|
45
|
+
gen_enum_pragma(:synchronous, value, SYNCHRONOUS_MODES)
|
46
|
+
end
|
47
|
+
|
48
|
+
def temp_store(value)
|
49
|
+
gen_enum_pragma(:temp_store, value, TEMP_STORE_MODES)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Set the global memory map so all processes can share some data
|
53
|
+
# https://www.sqlite.org/pragma.html#pragma_mmap_size
|
54
|
+
# https://www.sqlite.org/mmap.html
|
55
|
+
def mmap_size(value)
|
56
|
+
"PRAGMA mmap_size = #{value.to_i}"
|
57
|
+
end
|
58
|
+
|
59
|
+
# Impose a limit on the WAL file to prevent unlimited growth
|
60
|
+
# https://www.sqlite.org/pragma.html#pragma_journal_size_limit
|
61
|
+
def journal_size_limit(value)
|
62
|
+
"PRAGMA journal_size_limit = #{value.to_i}"
|
63
|
+
end
|
64
|
+
|
65
|
+
# Set the local connection cache to 2000 pages
|
66
|
+
# https://www.sqlite.org/pragma.html#pragma_cache_size
|
67
|
+
def cache_size(value)
|
68
|
+
"PRAGMA cache_size = #{value.to_i}"
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def gen_boolean_pragma(name, mode)
|
74
|
+
case mode
|
75
|
+
when String
|
76
|
+
case mode.downcase
|
77
|
+
when "on", "yes", "true", "y", "t" then mode = "'ON'"
|
78
|
+
when "off", "no", "false", "n", "f" then mode = "'OFF'"
|
79
|
+
else
|
80
|
+
raise ActiveRecord::JDBCError, "unrecognized pragma parameter #{mode.inspect}"
|
81
|
+
end
|
82
|
+
when true, 1
|
83
|
+
mode = "ON"
|
84
|
+
when false, 0, nil
|
85
|
+
mode = "OFF"
|
86
|
+
else
|
87
|
+
raise ActiveRecord::JDBCError, "unrecognized pragma parameter #{mode.inspect}"
|
88
|
+
end
|
89
|
+
|
90
|
+
"PRAGMA #{name} = #{mode}"
|
91
|
+
end
|
92
|
+
|
93
|
+
def gen_enum_pragma(name, mode, enums)
|
94
|
+
match = enums.find { |p| p.find { |i| i.to_s.downcase == mode.to_s.downcase } }
|
95
|
+
|
96
|
+
unless match
|
97
|
+
# Unknown pragma value
|
98
|
+
raise ActiveRecord::JDBCError, "unrecognized #{name} #{mode.inspect}"
|
99
|
+
end
|
100
|
+
|
101
|
+
"PRAGMA #{name} = '#{match.first.upcase}'"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
data/lib/arjdbc/sqlite3.rb
CHANGED
data/lib/arjdbc/version.rb
CHANGED
data/lib/arjdbc.rb
CHANGED
@@ -12,8 +12,20 @@ if defined?(JRUBY_VERSION)
|
|
12
12
|
rescue LoadError => e
|
13
13
|
warn "activerecord-jdbc-adapter failed to load railtie: #{e.inspect}"
|
14
14
|
end if defined?(Rails) && ActiveRecord::VERSION::MAJOR >= 3
|
15
|
+
|
16
|
+
ActiveSupport.on_load(:active_record) do
|
17
|
+
ActiveRecord::ConnectionAdapters.register(
|
18
|
+
"sqlite3", "ActiveRecord::ConnectionAdapters::SQLite3Adapter", "arjdbc/sqlite3/adapter"
|
19
|
+
)
|
20
|
+
ActiveRecord::ConnectionAdapters.register(
|
21
|
+
"postgresql", "ActiveRecord::ConnectionAdapters::PostgreSQLAdapter", "arjdbc/postgresql/adapter"
|
22
|
+
)
|
23
|
+
ActiveRecord::ConnectionAdapters.register(
|
24
|
+
"mysql2", "ActiveRecord::ConnectionAdapters::Mysql2Adapter", "arjdbc/mysql/adapter"
|
25
|
+
)
|
26
|
+
end
|
15
27
|
else
|
16
28
|
warn "activerecord-jdbc-adapter is for use with JRuby only"
|
17
29
|
end
|
18
30
|
|
19
|
-
require 'arjdbc/version'
|
31
|
+
require 'arjdbc/version'
|
data/rakelib/02-test.rake
CHANGED
@@ -36,7 +36,7 @@ def test_task_for(adapter, options = {})
|
|
36
36
|
test_task.libs = []
|
37
37
|
if defined?(JRUBY_VERSION)
|
38
38
|
test_task.libs << 'lib'
|
39
|
-
test_task.libs << "jdbc-#{driver}/lib" if driver && File.
|
39
|
+
test_task.libs << "jdbc-#{driver}/lib" if driver && File.exist?("jdbc-#{driver}/lib")
|
40
40
|
test_task.libs.push *FileList["activerecord-jdbc#{adapter}*/lib"]
|
41
41
|
end
|
42
42
|
test_task.libs << 'test'
|
@@ -126,6 +126,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
126
126
|
private IRubyObject adapter; // the AbstractAdapter instance we belong to
|
127
127
|
private volatile boolean connected = true;
|
128
128
|
private RubyClass attributeClass;
|
129
|
+
private RubyClass timeZoneClass;
|
129
130
|
|
130
131
|
private boolean lazy = false; // final once set on initialize
|
131
132
|
private boolean jndi; // final once set on initialize
|
@@ -135,6 +136,7 @@ public class RubyJdbcConnection extends RubyObject {
|
|
135
136
|
protected RubyJdbcConnection(Ruby runtime, RubyClass metaClass) {
|
136
137
|
super(runtime, metaClass);
|
137
138
|
attributeClass = runtime.getModule("ActiveModel").getClass("Attribute");
|
139
|
+
timeZoneClass = runtime.getModule("ActiveSupport").getClass("TimeWithZone");
|
138
140
|
}
|
139
141
|
|
140
142
|
private static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
|
@@ -2441,6 +2443,9 @@ public class RubyJdbcConnection extends RubyObject {
|
|
2441
2443
|
if (attributeClass.isInstance(attribute)) {
|
2442
2444
|
type = jdbcTypeForAttribute(context, attribute);
|
2443
2445
|
value = valueForDatabase(context, attribute);
|
2446
|
+
} else if (timeZoneClass.isInstance(attribute)) {
|
2447
|
+
type = jdbcTypeFor("timestamp");
|
2448
|
+
value = attribute;
|
2444
2449
|
} else {
|
2445
2450
|
type = jdbcTypeForPrimitiveAttribute(context, attribute);
|
2446
2451
|
value = attribute;
|
@@ -74,11 +74,7 @@ public class MySQLRubyJdbcConnection extends RubyJdbcConnection {
|
|
74
74
|
return createMySQLJdbcConnectionClass(runtime, jdbcConnection);
|
75
75
|
}
|
76
76
|
|
77
|
-
protected static final ObjectAllocator ALLOCATOR = new
|
78
|
-
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
79
|
-
return new MySQLRubyJdbcConnection(runtime, klass);
|
80
|
-
}
|
81
|
-
};
|
77
|
+
protected static final ObjectAllocator ALLOCATOR = MySQLRubyJdbcConnection::new;
|
82
78
|
|
83
79
|
@JRubyMethod
|
84
80
|
public IRubyObject query(final ThreadContext context, final IRubyObject sql) throws SQLException {
|
@@ -473,7 +473,10 @@ public class SQLite3RubyJdbcConnection extends RubyJdbcConnection {
|
|
473
473
|
// Assume we will only call this with an array.
|
474
474
|
final RubyArray statements = (RubyArray) statementsArg;
|
475
475
|
return withConnection(context, connection -> {
|
476
|
+
final Ruby runtime = context.runtime;
|
477
|
+
|
476
478
|
Statement statement = null;
|
479
|
+
|
477
480
|
try {
|
478
481
|
statement = createStatement(context, connection);
|
479
482
|
|
@@ -481,8 +484,15 @@ public class SQLite3RubyJdbcConnection extends RubyJdbcConnection {
|
|
481
484
|
for (int i = 0; i < length; i++) {
|
482
485
|
statement.addBatch(sqlString(statements.eltOk(i)));
|
483
486
|
}
|
484
|
-
|
485
|
-
|
487
|
+
|
488
|
+
int[] rows = statement.executeBatch();
|
489
|
+
|
490
|
+
RubyArray rowsAffected = runtime.newArray();
|
491
|
+
|
492
|
+
for (int i = 0; i < rows.length; i++) {
|
493
|
+
rowsAffected.append(runtime.newFixnum(rows[i]));
|
494
|
+
}
|
495
|
+
return rowsAffected;
|
486
496
|
} catch (final SQLException e) {
|
487
497
|
// Generate list semicolon list of statements which should match AR error formatting more.
|
488
498
|
debugErrorSQL(context, sqlString(statements.join(context, context.runtime.newString(";\n"))));
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-jdbc-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '
|
4
|
+
version: '72.1'
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Nick Sieger, Ola Bini, Karol Bucek and JRuby contributors
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-09-26 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: activerecord
|
@@ -15,14 +15,14 @@ dependencies:
|
|
15
15
|
requirements:
|
16
16
|
- - "~>"
|
17
17
|
- !ruby/object:Gem::Version
|
18
|
-
version: 7.
|
18
|
+
version: 7.2.2
|
19
19
|
type: :runtime
|
20
20
|
prerelease: false
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
22
22
|
requirements:
|
23
23
|
- - "~>"
|
24
24
|
- !ruby/object:Gem::Version
|
25
|
-
version: 7.
|
25
|
+
version: 7.2.2
|
26
26
|
description: 'AR-JDBC is a database adapter for Rails'' ActiveRecord component designed
|
27
27
|
to be used with JRuby built upon Java''s JDBC API for database access. Provides
|
28
28
|
(ActiveRecord) built-in adapters: MySQL, PostgreSQL, and SQLite3.'
|
@@ -85,7 +85,6 @@ files:
|
|
85
85
|
- lib/arjdbc/jdbc/adapter.rb
|
86
86
|
- lib/arjdbc/jdbc/adapter_java.jar
|
87
87
|
- lib/arjdbc/jdbc/adapter_require.rb
|
88
|
-
- lib/arjdbc/jdbc/base_ext.rb
|
89
88
|
- lib/arjdbc/jdbc/callbacks.rb
|
90
89
|
- lib/arjdbc/jdbc/column.rb
|
91
90
|
- lib/arjdbc/jdbc/connection.rb
|
@@ -100,10 +99,12 @@ files:
|
|
100
99
|
- lib/arjdbc/jdbc/type_converter.rb
|
101
100
|
- lib/arjdbc/mysql.rb
|
102
101
|
- lib/arjdbc/mysql/adapter.rb
|
102
|
+
- lib/arjdbc/mysql/adapter_hash_config.rb
|
103
103
|
- lib/arjdbc/mysql/connection_methods.rb
|
104
104
|
- lib/arjdbc/oracle/adapter.rb
|
105
105
|
- lib/arjdbc/postgresql.rb
|
106
106
|
- lib/arjdbc/postgresql/adapter.rb
|
107
|
+
- lib/arjdbc/postgresql/adapter_hash_config.rb
|
107
108
|
- lib/arjdbc/postgresql/base/array_decoder.rb
|
108
109
|
- lib/arjdbc/postgresql/base/array_encoder.rb
|
109
110
|
- lib/arjdbc/postgresql/base/array_parser.rb
|
@@ -117,8 +118,10 @@ files:
|
|
117
118
|
- lib/arjdbc/railtie.rb
|
118
119
|
- lib/arjdbc/sqlite3.rb
|
119
120
|
- lib/arjdbc/sqlite3/adapter.rb
|
121
|
+
- lib/arjdbc/sqlite3/adapter_hash_config.rb
|
120
122
|
- lib/arjdbc/sqlite3/column.rb
|
121
123
|
- lib/arjdbc/sqlite3/connection_methods.rb
|
124
|
+
- lib/arjdbc/sqlite3/pragmas.rb
|
122
125
|
- lib/arjdbc/tasks.rb
|
123
126
|
- lib/arjdbc/tasks/database_tasks.rb
|
124
127
|
- lib/arjdbc/tasks/databases.rake
|
@@ -200,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
203
|
- !ruby/object:Gem::Version
|
201
204
|
version: '0'
|
202
205
|
requirements: []
|
203
|
-
rubygems_version: 3.6.
|
206
|
+
rubygems_version: 3.6.2
|
204
207
|
specification_version: 4
|
205
208
|
summary: JDBC adapter for ActiveRecord, for use within JRuby on Rails.
|
206
209
|
test_files: []
|
data/lib/arjdbc/jdbc/base_ext.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
class << Base
|
5
|
-
m = Module.new do
|
6
|
-
# Allow adapters to provide their own {#reset_column_information} method.
|
7
|
-
# @note This only affects the current thread's connection.
|
8
|
-
def reset_column_information # :nodoc:
|
9
|
-
# invoke the adapter-specific reset_column_information method
|
10
|
-
connection.reset_column_information if connection.respond_to?(:reset_column_information)
|
11
|
-
super
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
self.prepend(m)
|
16
|
-
end
|
17
|
-
end
|