activerecord-jdbc-alt-adapter 71.0.0.alpha1-java → 71.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ArJdbc
4
+ module PostgreSQL
5
+ module SchemaStatements
6
+ ForeignKeyDefinition = ActiveRecord::ConnectionAdapters::ForeignKeyDefinition
7
+ Utils = ActiveRecord::ConnectionAdapters::PostgreSQL::Utils
8
+
9
+ def foreign_keys(table_name)
10
+ scope = quoted_scope(table_name)
11
+ fk_info = internal_exec_query(<<~SQL, "SCHEMA", allow_retry: true, materialize_transactions: false)
12
+ SELECT t2.oid::regclass::text AS to_table, a1.attname AS column, a2.attname AS primary_key, c.conname AS name, c.confupdtype AS on_update, c.confdeltype AS on_delete, c.convalidated AS valid, c.condeferrable AS deferrable, c.condeferred AS deferred, c.conkey, c.confkey, c.conrelid, c.confrelid
13
+ FROM pg_constraint c
14
+ JOIN pg_class t1 ON c.conrelid = t1.oid
15
+ JOIN pg_class t2 ON c.confrelid = t2.oid
16
+ JOIN pg_attribute a1 ON a1.attnum = c.conkey[1] AND a1.attrelid = t1.oid
17
+ JOIN pg_attribute a2 ON a2.attnum = c.confkey[1] AND a2.attrelid = t2.oid
18
+ JOIN pg_namespace t3 ON c.connamespace = t3.oid
19
+ WHERE c.contype = 'f'
20
+ AND t1.relname = #{scope[:name]}
21
+ AND t3.nspname = #{scope[:schema]}
22
+ ORDER BY c.conname
23
+ SQL
24
+
25
+ fk_info.map do |row|
26
+ to_table = Utils.unquote_identifier(row["to_table"])
27
+ # conkey = row["conkey"].scan(/\d+/).map(&:to_i)
28
+ # confkey = row["confkey"].scan(/\d+/).map(&:to_i)
29
+ conkey = row["conkey"]
30
+ confkey = row["confkey"]
31
+
32
+ if conkey.size > 1
33
+ column = column_names_from_column_numbers(row["conrelid"], conkey)
34
+ primary_key = column_names_from_column_numbers(row["confrelid"], confkey)
35
+ else
36
+ column = Utils.unquote_identifier(row["column"])
37
+ primary_key = row["primary_key"]
38
+ end
39
+
40
+ options = {
41
+ column: column,
42
+ name: row["name"],
43
+ primary_key: primary_key
44
+ }
45
+
46
+ options[:on_delete] = extract_foreign_key_action(row["on_delete"])
47
+ options[:on_update] = extract_foreign_key_action(row["on_update"])
48
+ options[:deferrable] = extract_constraint_deferrable(row["deferrable"], row["deferred"])
49
+
50
+ options[:validate] = row["valid"]
51
+
52
+ ForeignKeyDefinition.new(table_name, to_table, options)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -18,6 +18,8 @@ require "active_record/connection_adapters/sqlite3/schema_statements"
18
18
  require "active_support/core_ext/class/attribute"
19
19
  require "arjdbc/sqlite3/column"
20
20
 
21
+ require "arjdbc/abstract/relation_query_attribute_monkey_patch"
22
+
21
23
  module SQLite3
22
24
  module Constants
23
25
  module Open
@@ -669,50 +671,20 @@ module ArJdbc
669
671
  StatementPool.new(self.class.type_cast_config_to_integer(@config[:statement_limit]))
670
672
  end
671
673
 
672
- def configure_connection
673
- if @config[:timeout] && @config[:retries]
674
- raise ArgumentError, "Cannot specify both timeout and retries arguments"
675
- elsif @config[:timeout]
676
- # FIXME: missing from adapter
677
- # @raw_connection.busy_timeout(self.class.type_cast_config_to_integer(@config[:timeout]))
678
- elsif @config[:retries]
679
- retries = self.class.type_cast_config_to_integer(@config[:retries])
680
- raw_connection.busy_handler do |count|
681
- count <= retries
682
- end
683
- end
684
-
685
- # Enforce foreign key constraints
686
- # https://www.sqlite.org/pragma.html#pragma_foreign_keys
687
- # https://www.sqlite.org/foreignkeys.html
688
- raw_execute("PRAGMA foreign_keys = ON", "SCHEMA")
689
- unless @memory_database
690
- # Journal mode WAL allows for greater concurrency (many readers + one writer)
691
- # https://www.sqlite.org/pragma.html#pragma_journal_mode
692
- raw_execute("PRAGMA journal_mode = WAL", "SCHEMA")
693
- # Set more relaxed level of database durability
694
- # 2 = "FULL" (sync on every write), 1 = "NORMAL" (sync every 1000 written pages) and 0 = "NONE"
695
- # https://www.sqlite.org/pragma.html#pragma_synchronous
696
- raw_execute("PRAGMA synchronous = NORMAL", "SCHEMA")
697
- # Set the global memory map so all processes can share some data
698
- # https://www.sqlite.org/pragma.html#pragma_mmap_size
699
- # https://www.sqlite.org/mmap.html
700
- raw_execute("PRAGMA mmap_size = #{128.megabytes}", "SCHEMA")
674
+ def reconnect
675
+ if active?
676
+ @raw_connection.rollback rescue nil
677
+ else
678
+ connect
701
679
  end
702
- # Impose a limit on the WAL file to prevent unlimited growth
703
- # https://www.sqlite.org/pragma.html#pragma_journal_size_limit
704
- raw_execute("PRAGMA journal_size_limit = #{64.megabytes}", "SCHEMA")
705
- # Set the local connection cache to 2000 pages
706
- # https://www.sqlite.org/pragma.html#pragma_cache_size
707
- raw_execute("PRAGMA cache_size = 2000", "SCHEMA")
708
680
  end
709
681
 
710
682
  def configure_connection
711
683
  if @config[:timeout] && @config[:retries]
712
684
  raise ArgumentError, "Cannot specify both timeout and retries arguments"
713
685
  elsif @config[:timeout]
714
- # FIXME:
715
- # @raw_connection.busy_timeout(self.class.type_cast_config_to_integer(@config[:timeout]))
686
+ # FIXME: missing from adapter
687
+ # @raw_connection.busy_timeout(self.class.type_cast_config_to_integer(@config[:timeout]))
716
688
  elsif @config[:retries]
717
689
  retries = self.class.type_cast_config_to_integer(@config[:retries])
718
690
  raw_connection.busy_handler do |count|
@@ -742,7 +714,7 @@ module ArJdbc
742
714
  raw_execute("PRAGMA journal_size_limit = #{64.megabytes}", "SCHEMA")
743
715
  # Set the local connection cache to 2000 pages
744
716
  # https://www.sqlite.org/pragma.html#pragma_cache_size
745
- raw_execute("PRAGMA cache_size = 2000", "SCHEMA")
717
+ raw_execute("PRAGMA cache_size = 2000", "SCHEMA")
746
718
  end
747
719
  end
748
720
  # DIFFERENCE: A registration here is moved down to concrete class so we are not registering part of an adapter.
@@ -774,6 +746,20 @@ module ActiveRecord::ConnectionAdapters
774
746
  # config.active_record.sqlite3_adapter_strict_strings_by_default = true
775
747
  class_attribute :strict_strings_by_default, default: false # Does not actually do anything right now
776
748
 
749
+ def initialize(...)
750
+ super
751
+
752
+ conn_params = @config.compact
753
+
754
+ # NOTE: strict strings is not supported by the jdbc driver yet,
755
+ # hope it will supported soon, I open a issue in their repository.
756
+ # https://github.com/xerial/sqlite-jdbc/issues/1153
757
+ #
758
+ # @config[:strict] = ConnectionAdapters::SQLite3Adapter.strict_strings_by_default unless @config.key?(:strict)
759
+
760
+ @connection_parameters = conn_params
761
+ end
762
+
777
763
  def self.represent_boolean_as_integer=(value) # :nodoc:
778
764
  if value == false
779
765
  raise "`.represent_boolean_as_integer=` is now always true, so make sure your application can work with it and remove this settings."
@@ -817,15 +803,6 @@ module ActiveRecord::ConnectionAdapters
817
803
  ::ActiveRecord::ConnectionAdapters::SQLite3Column
818
804
  end
819
805
 
820
- def jdbc_connection_class(spec)
821
- self.class.jdbc_connection_class
822
- end
823
-
824
- # @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
825
- def self.jdbc_connection_class
826
- ::ActiveRecord::ConnectionAdapters::SQLite3JdbcConnection
827
- end
828
-
829
806
  # Note: This is not an override of ours but a moved line from AR Sqlite3Adapter to register ours vs our copied module (which would be their class).
830
807
  # ActiveSupport.run_load_hooks(:active_record_sqlite3adapter, SQLite3Adapter)
831
808
 
@@ -843,6 +820,14 @@ module ActiveRecord::ConnectionAdapters
843
820
  ::ActiveRecord::Type.register(:integer, SQLite3Integer, adapter: :sqlite3)
844
821
 
845
822
  class << self
823
+ def jdbc_connection_class
824
+ ::ActiveRecord::ConnectionAdapters::SQLite3JdbcConnection
825
+ end
826
+
827
+ def new_client(conn_params, adapter_instance)
828
+ jdbc_connection_class.new(conn_params, adapter_instance)
829
+ end
830
+
846
831
  def dbconsole(config, options = {})
847
832
  args = []
848
833
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ArJdbc
4
- VERSION = '71.0.0.alpha1'
4
+ VERSION = "71.0.0"
5
5
  end
@@ -793,8 +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);
797
- result = mapToRawResult(context, connection, resultSet, false);
796
+ result = mapExecuteResult(context, connection, resultSet);
797
+ // result = mapToRawResult(context, connection, resultSet, false);
798
798
  resultSet.close();
799
799
  } else {
800
800
  result = context.runtime.newFixnum(updateCount);
@@ -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
 
metadata CHANGED
@@ -1,14 +1,14 @@
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.alpha1
4
+ version: 71.0.0
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: 2024-07-24 00:00:00.000000000 Z
11
+ date: 2025-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -78,6 +78,7 @@ files:
78
78
  - lib/arjdbc/abstract/connection_management.rb
79
79
  - lib/arjdbc/abstract/core.rb
80
80
  - lib/arjdbc/abstract/database_statements.rb
81
+ - lib/arjdbc/abstract/relation_query_attribute_monkey_patch.rb
81
82
  - lib/arjdbc/abstract/statement_cache.rb
82
83
  - lib/arjdbc/abstract/transaction_support.rb
83
84
  - lib/arjdbc/discover.rb
@@ -143,8 +144,10 @@ files:
143
144
  - lib/arjdbc/postgresql/base/pgconn.rb
144
145
  - lib/arjdbc/postgresql/column.rb
145
146
  - lib/arjdbc/postgresql/connection_methods.rb
147
+ - lib/arjdbc/postgresql/database_statements.rb
146
148
  - lib/arjdbc/postgresql/name.rb
147
149
  - lib/arjdbc/postgresql/oid_types.rb
150
+ - lib/arjdbc/postgresql/schema_statements.rb
148
151
  - lib/arjdbc/railtie.rb
149
152
  - lib/arjdbc/sqlite3.rb
150
153
  - lib/arjdbc/sqlite3/adapter.rb
@@ -228,9 +231,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
228
231
  version: '0'
229
232
  required_rubygems_version: !ruby/object:Gem::Requirement
230
233
  requirements:
231
- - - ">"
234
+ - - ">="
232
235
  - !ruby/object:Gem::Version
233
- version: 1.3.1
236
+ version: '0'
234
237
  requirements: []
235
238
  rubygems_version: 3.3.26
236
239
  signing_key: