activerecord-jdbc-alt-adapter 71.0.0-java → 72.0.0.rc1-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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/activerecord-jdbc-adapter.gemspec +1 -1
  4. data/activerecord-jdbc-alt-adapter.gemspec +1 -1
  5. data/lib/arel/visitors/sqlserver.rb +13 -9
  6. data/lib/arjdbc/abstract/core.rb +10 -1
  7. data/lib/arjdbc/abstract/database_statements.rb +1 -1
  8. data/lib/arjdbc/abstract/transaction_support.rb +3 -1
  9. data/lib/arjdbc/jdbc/adapter.rb +0 -1
  10. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  11. data/lib/arjdbc/mssql/adapter.rb +18 -15
  12. data/lib/arjdbc/mssql/adapter_hash_config.rb +53 -0
  13. data/lib/arjdbc/mssql/column.rb +16 -7
  14. data/lib/arjdbc/mssql/database_statements.rb +7 -2
  15. data/lib/arjdbc/mssql/quoting.rb +56 -36
  16. data/lib/arjdbc/mssql/schema_creation.rb +16 -0
  17. data/lib/arjdbc/mssql/schema_statements.rb +44 -19
  18. data/lib/arjdbc/mssql.rb +1 -1
  19. data/lib/arjdbc/mysql/adapter.rb +8 -11
  20. data/lib/arjdbc/mysql/adapter_hash_config.rb +159 -0
  21. data/lib/arjdbc/mysql.rb +1 -1
  22. data/lib/arjdbc/postgresql/adapter.rb +17 -11
  23. data/lib/arjdbc/postgresql/adapter_hash_config.rb +98 -0
  24. data/lib/arjdbc/postgresql/base/array_encoder.rb +3 -1
  25. data/lib/arjdbc/postgresql/oid_types.rb +2 -2
  26. data/lib/arjdbc/postgresql.rb +1 -1
  27. data/lib/arjdbc/sqlite3/adapter.rb +193 -90
  28. data/lib/arjdbc/sqlite3/adapter_hash_config.rb +91 -0
  29. data/lib/arjdbc/sqlite3/column.rb +17 -3
  30. data/lib/arjdbc/sqlite3/pragmas.rb +105 -0
  31. data/lib/arjdbc/sqlite3.rb +1 -1
  32. data/lib/arjdbc/version.rb +1 -1
  33. data/lib/arjdbc.rb +16 -1
  34. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +5 -0
  35. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +12 -2
  36. metadata +12 -8
  37. 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
@@ -1,3 +1,3 @@
1
1
  require 'arjdbc'
2
2
  require 'arjdbc/sqlite3/adapter'
3
- require 'arjdbc/sqlite3/connection_methods'
3
+ # require 'arjdbc/sqlite3/connection_methods'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ArJdbc
4
- VERSION = "71.0.0"
4
+ VERSION = "72.0.0.rc1"
5
5
  end
data/lib/arjdbc.rb CHANGED
@@ -12,8 +12,23 @@ 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
+ "sqlserver", "ActiveRecord::ConnectionAdapters::MSSQLAdapter", "active_record/connection_adapters/mssql_adapter"
19
+ )
20
+ ActiveRecord::ConnectionAdapters.register(
21
+ "sqlite3", "ActiveRecord::ConnectionAdapters::SQLite3Adapter", "arjdbc/sqlite3/adapter"
22
+ )
23
+ ActiveRecord::ConnectionAdapters.register(
24
+ "postgresql", "ActiveRecord::ConnectionAdapters::PostgreSQLAdapter", "arjdbc/postgresql/adapter"
25
+ )
26
+ ActiveRecord::ConnectionAdapters.register(
27
+ "mysql2", "ActiveRecord::ConnectionAdapters::Mysql2Adapter", "arjdbc/mysql/adapter"
28
+ )
29
+ end
15
30
  else
16
31
  warn "activerecord-jdbc-adapter is for use with JRuby only"
17
32
  end
18
33
 
19
- require 'arjdbc/version'
34
+ require 'arjdbc/version'
@@ -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;
@@ -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
- statement.executeBatch();
485
- return context.nil;
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,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-jdbc-alt-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 71.0.0
4
+ version: 72.0.0.rc1
5
5
  platform: java
6
6
  authors:
7
7
  - Nick Sieger, Ola Bini, Karol Bucek, Jesse Chavez, and JRuby contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-26 00:00:00.000000000 Z
11
+ date: 2025-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
+ name: activerecord
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
17
  - - "~>"
17
18
  - !ruby/object:Gem::Version
18
- version: 7.1.3
19
- name: activerecord
19
+ version: 7.2.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 7.1.3
26
+ version: 7.2.2
27
27
  description: 'Fork of the ActiveRecord JDBC adapter with support for SQL Server and
28
28
  Azure SQL, for more information and help look at the README file in the github repository.
29
29
  AR-JDBC is a database adapter for Rails'' ActiveRecord component designed to be
@@ -95,7 +95,6 @@ files:
95
95
  - lib/arjdbc/jdbc/adapter.rb
96
96
  - lib/arjdbc/jdbc/adapter_java.jar
97
97
  - lib/arjdbc/jdbc/adapter_require.rb
98
- - lib/arjdbc/jdbc/base_ext.rb
99
98
  - lib/arjdbc/jdbc/callbacks.rb
100
99
  - lib/arjdbc/jdbc/column.rb
101
100
  - lib/arjdbc/jdbc/connection.rb
@@ -110,6 +109,7 @@ files:
110
109
  - lib/arjdbc/jdbc/type_converter.rb
111
110
  - lib/arjdbc/mssql.rb
112
111
  - lib/arjdbc/mssql/adapter.rb
112
+ - lib/arjdbc/mssql/adapter_hash_config.rb
113
113
  - lib/arjdbc/mssql/column.rb
114
114
  - lib/arjdbc/mssql/connection_methods.rb
115
115
  - lib/arjdbc/mssql/database_limits.rb
@@ -134,10 +134,12 @@ files:
134
134
  - lib/arjdbc/mssql/utils.rb
135
135
  - lib/arjdbc/mysql.rb
136
136
  - lib/arjdbc/mysql/adapter.rb
137
+ - lib/arjdbc/mysql/adapter_hash_config.rb
137
138
  - lib/arjdbc/mysql/connection_methods.rb
138
139
  - lib/arjdbc/oracle/adapter.rb
139
140
  - lib/arjdbc/postgresql.rb
140
141
  - lib/arjdbc/postgresql/adapter.rb
142
+ - lib/arjdbc/postgresql/adapter_hash_config.rb
141
143
  - lib/arjdbc/postgresql/base/array_decoder.rb
142
144
  - lib/arjdbc/postgresql/base/array_encoder.rb
143
145
  - lib/arjdbc/postgresql/base/array_parser.rb
@@ -151,8 +153,10 @@ files:
151
153
  - lib/arjdbc/railtie.rb
152
154
  - lib/arjdbc/sqlite3.rb
153
155
  - lib/arjdbc/sqlite3/adapter.rb
156
+ - lib/arjdbc/sqlite3/adapter_hash_config.rb
154
157
  - lib/arjdbc/sqlite3/column.rb
155
158
  - lib/arjdbc/sqlite3/connection_methods.rb
159
+ - lib/arjdbc/sqlite3/pragmas.rb
156
160
  - lib/arjdbc/tasks.rb
157
161
  - lib/arjdbc/tasks/database_tasks.rb
158
162
  - lib/arjdbc/tasks/databases.rake
@@ -231,9 +235,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
231
235
  version: '0'
232
236
  required_rubygems_version: !ruby/object:Gem::Requirement
233
237
  requirements:
234
- - - ">="
238
+ - - ">"
235
239
  - !ruby/object:Gem::Version
236
- version: '0'
240
+ version: 1.3.1
237
241
  requirements: []
238
242
  rubygems_version: 3.3.26
239
243
  signing_key:
@@ -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