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

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  require 'arjdbc'
2
2
  require 'arjdbc/postgresql/adapter'
3
- require 'arjdbc/postgresql/connection_methods'
3
+ # require 'arjdbc/postgresql/connection_methods'
@@ -17,6 +17,9 @@ require "active_record/connection_adapters/sqlite3/schema_dumper"
17
17
  require "active_record/connection_adapters/sqlite3/schema_statements"
18
18
  require "active_support/core_ext/class/attribute"
19
19
  require "arjdbc/sqlite3/column"
20
+ require "arjdbc/sqlite3/adapter_hash_config"
21
+
22
+ require "arjdbc/abstract/relation_query_attribute_monkey_patch"
20
23
 
21
24
  module SQLite3
22
25
  module Constants
@@ -61,13 +64,6 @@ module ArJdbc
61
64
  SchemaCreation = ConnectionAdapters::SQLite3::SchemaCreation
62
65
  SQLite3Adapter = ConnectionAdapters::AbstractAdapter
63
66
 
64
- ADAPTER_NAME = 'SQLite'
65
-
66
- # DIFFERENCE: FQN
67
- include ::ActiveRecord::ConnectionAdapters::SQLite3::Quoting
68
- include ::ActiveRecord::ConnectionAdapters::SQLite3::SchemaStatements
69
- include ::ActiveRecord::ConnectionAdapters::SQLite3::DatabaseStatements
70
-
71
67
  NATIVE_DATABASE_TYPES = {
72
68
  primary_key: "integer PRIMARY KEY AUTOINCREMENT NOT NULL",
73
69
  string: { name: "varchar" },
@@ -82,7 +78,7 @@ module ArJdbc
82
78
  boolean: { name: "boolean" },
83
79
  json: { name: "json" },
84
80
  }
85
-
81
+
86
82
  class StatementPool < ConnectionAdapters::StatementPool # :nodoc:
87
83
  private
88
84
  def dealloc(stmt)
@@ -669,6 +665,14 @@ module ArJdbc
669
665
  StatementPool.new(self.class.type_cast_config_to_integer(@config[:statement_limit]))
670
666
  end
671
667
 
668
+ def reconnect
669
+ if active?
670
+ @raw_connection.rollback rescue nil
671
+ else
672
+ connect
673
+ end
674
+ end
675
+
672
676
  def configure_connection
673
677
  if @config[:timeout] && @config[:retries]
674
678
  raise ArgumentError, "Cannot specify both timeout and retries arguments"
@@ -719,13 +723,41 @@ module ActiveRecord::ConnectionAdapters
719
723
  # ActiveRecord::ConnectionAdapters::SQLite3Adapter. Once we can do that we can remove the
720
724
  # module SQLite3 above and remove a majority of this file.
721
725
  class SQLite3Adapter < AbstractAdapter
726
+ ADAPTER_NAME = "SQLite"
727
+
728
+ class << self
729
+ def new_client(conn_params, adapter_instance)
730
+ jdbc_connection_class.new(conn_params, adapter_instance)
731
+ end
732
+
733
+ def dbconsole(config, options = {})
734
+ args = []
735
+
736
+ args << "-#{options[:mode]}" if options[:mode]
737
+ args << "-header" if options[:header]
738
+ args << File.expand_path(config.database, const_defined?(:Rails) && Rails.respond_to?(:root) ? Rails.root : nil)
739
+
740
+ find_cmd_and_exec("sqlite3", *args)
741
+ end
742
+
743
+ def jdbc_connection_class
744
+ ::ActiveRecord::ConnectionAdapters::SQLite3JdbcConnection
745
+ end
746
+ end
747
+
722
748
  include ArJdbc::Abstract::Core
723
749
  include ArJdbc::SQLite3
750
+ include ArJdbc::SQLite3Config
751
+
724
752
  include ArJdbc::Abstract::ConnectionManagement
725
753
  include ArJdbc::Abstract::DatabaseStatements
726
754
  include ArJdbc::Abstract::StatementCache
727
755
  include ArJdbc::Abstract::TransactionSupport
728
756
 
757
+ include ::ActiveRecord::ConnectionAdapters::SQLite3::Quoting
758
+ include ::ActiveRecord::ConnectionAdapters::SQLite3::SchemaStatements
759
+ include ::ActiveRecord::ConnectionAdapters::SQLite3::DatabaseStatements
760
+
729
761
  ##
730
762
  # :singleton-method:
731
763
  # Configure the SQLite3Adapter to be used in a strict strings mode.
@@ -739,7 +771,8 @@ module ActiveRecord::ConnectionAdapters
739
771
  def initialize(...)
740
772
  super
741
773
 
742
- conn_params = @config.compact
774
+ # assign arjdbc extra connection params
775
+ conn_params = build_connection_config(@config.compact)
743
776
 
744
777
  # NOTE: strict strings is not supported by the jdbc driver yet,
745
778
  # hope it will supported soon, I open a issue in their repository.
@@ -810,24 +843,6 @@ module ActiveRecord::ConnectionAdapters
810
843
  ::ActiveRecord::Type.register(:integer, SQLite3Integer, adapter: :sqlite3)
811
844
 
812
845
  class << self
813
- def jdbc_connection_class
814
- ::ActiveRecord::ConnectionAdapters::SQLite3JdbcConnection
815
- end
816
-
817
- def new_client(conn_params, adapter_instance)
818
- jdbc_connection_class.new(conn_params, adapter_instance)
819
- end
820
-
821
- def dbconsole(config, options = {})
822
- args = []
823
-
824
- args << "-#{options[:mode]}" if options[:mode]
825
- args << "-header" if options[:header]
826
- args << File.expand_path(config.database, const_defined?(:Rails) && Rails.respond_to?(:root) ? Rails.root : nil)
827
-
828
- find_cmd_and_exec("sqlite3", *args)
829
- end
830
-
831
846
  private
832
847
  def initialize_type_map(m)
833
848
  super
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ArJdbc
4
+ module SQLite3Config
5
+ def build_connection_config(config)
6
+ config = config.deep_dup
7
+
8
+ load_jdbc_driver
9
+
10
+ config[:driver] ||= "org.sqlite.JDBC"
11
+
12
+ parse_sqlite3_config!(config)
13
+
14
+ database = config[:database]
15
+
16
+ # NOTE: "jdbc:sqlite::memory:" syntax is supported
17
+ config[:url] ||= "jdbc:sqlite:#{database == ':memory:' ? '' : database}"
18
+ config[:connection_alive_sql] ||= "SELECT 1"
19
+
20
+ config[:properties] = build_properties(config)
21
+
22
+ config
23
+ end
24
+
25
+ private
26
+
27
+ def load_jdbc_driver
28
+ require "jdbc/sqlite3"
29
+
30
+ ::Jdbc::SQLite3.load_driver(:require) if defined?(::Jdbc::SQLite3.load_driver)
31
+ rescue LoadError
32
+ # assuming driver.jar is on the class-path
33
+ end
34
+
35
+ def build_properties(config)
36
+ properties = config[:properties] || {}
37
+
38
+ if config[:readonly]
39
+ # See
40
+ # * http://sqlite.org/c3ref/open.html
41
+ # * http://sqlite.org/c3ref/c_open_autoproxy.html
42
+ # => 0x01 = readonly, 0x40 = uri (default in JDBC)
43
+ properties[:open_mode] =
44
+ ::SQLite3::Constants::Open::READONLY | ::SQLite3::Constants::Open::URI
45
+ end
46
+
47
+ if config[:flags]
48
+ properties[:open_mode] ||= 0
49
+ properties[:open_mode] |= config[:flags]
50
+
51
+ # JDBC driver has an extra flag for it
52
+ if config[:flags] & ::SQLite3::Constants::Open::SHAREDCACHE != 0
53
+ properties[:shared_cache] = true
54
+ end
55
+ end
56
+
57
+ timeout = config[:timeout]
58
+ if timeout && timeout.to_s !~ /\A\d+\Z/
59
+ raise ActiveRecord::StatementInvalid.new(
60
+ "TypeError: Timeout must be nil or a number (got: #{timeout}).",
61
+ connection_pool: ActiveRecord::ConnectionAdapters::NullPool.new
62
+ )
63
+ end
64
+
65
+ properties["busy_timeout"] ||= timeout unless timeout.nil?
66
+
67
+ properties
68
+ end
69
+
70
+ def parse_sqlite3_config!(config)
71
+ database = (config[:database] ||= config[:dbfile])
72
+
73
+ if database != ":memory:"
74
+ # make sure to have an absolute path. Ruby and Java don't agree
75
+ # on working directory
76
+ base_dir = defined?(Rails.root) ? Rails.root : nil
77
+ config[:database] = File.expand_path(database, base_dir)
78
+ dirname = File.dirname(config[:database])
79
+ Dir.mkdir(dirname) unless File.directory?(dirname)
80
+ end
81
+ rescue Errno::ENOENT => e
82
+ if e.message.include?("No such file or directory")
83
+ raise ActiveRecord::NoDatabaseError.new(
84
+ connection_pool: ActiveRecord::ConnectionAdapters::NullPool.new
85
+ )
86
+ end
87
+
88
+ raise
89
+ end
90
+ end
91
+ 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.alpha2'
4
+ VERSION = "72.0.0.alpha1"
5
5
  end
data/lib/arjdbc.rb CHANGED
@@ -12,8 +12,14 @@ 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
+ end
15
21
  else
16
22
  warn "activerecord-jdbc-adapter is for use with JRuby only"
17
23
  end
18
24
 
19
- require 'arjdbc/version'
25
+ require 'arjdbc/version'
metadata CHANGED
@@ -1,21 +1,21 @@
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.alpha2
4
+ version: 72.0.0.alpha1
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-08-06 00:00:00.000000000 Z
11
+ date: 2025-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: 7.1.3
18
+ version: 7.2.2
19
19
  name: activerecord
20
20
  type: :runtime
21
21
  prerelease: false
@@ -23,7 +23,7 @@ dependencies:
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
@@ -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
@@ -109,6 +110,7 @@ files:
109
110
  - lib/arjdbc/jdbc/type_converter.rb
110
111
  - lib/arjdbc/mssql.rb
111
112
  - lib/arjdbc/mssql/adapter.rb
113
+ - lib/arjdbc/mssql/adapter_hash_config.rb
112
114
  - lib/arjdbc/mssql/column.rb
113
115
  - lib/arjdbc/mssql/connection_methods.rb
114
116
  - lib/arjdbc/mssql/database_limits.rb
@@ -133,22 +135,26 @@ files:
133
135
  - lib/arjdbc/mssql/utils.rb
134
136
  - lib/arjdbc/mysql.rb
135
137
  - lib/arjdbc/mysql/adapter.rb
138
+ - lib/arjdbc/mysql/adapter_hash_config.rb
136
139
  - lib/arjdbc/mysql/connection_methods.rb
137
140
  - lib/arjdbc/oracle/adapter.rb
138
141
  - lib/arjdbc/postgresql.rb
139
142
  - lib/arjdbc/postgresql/adapter.rb
143
+ - lib/arjdbc/postgresql/adapter_hash_config.rb
140
144
  - lib/arjdbc/postgresql/base/array_decoder.rb
141
145
  - lib/arjdbc/postgresql/base/array_encoder.rb
142
146
  - lib/arjdbc/postgresql/base/array_parser.rb
143
147
  - lib/arjdbc/postgresql/base/pgconn.rb
144
148
  - lib/arjdbc/postgresql/column.rb
145
149
  - lib/arjdbc/postgresql/connection_methods.rb
150
+ - lib/arjdbc/postgresql/database_statements.rb
146
151
  - lib/arjdbc/postgresql/name.rb
147
152
  - lib/arjdbc/postgresql/oid_types.rb
148
153
  - lib/arjdbc/postgresql/schema_statements.rb
149
154
  - lib/arjdbc/railtie.rb
150
155
  - lib/arjdbc/sqlite3.rb
151
156
  - lib/arjdbc/sqlite3/adapter.rb
157
+ - lib/arjdbc/sqlite3/adapter_hash_config.rb
152
158
  - lib/arjdbc/sqlite3/column.rb
153
159
  - lib/arjdbc/sqlite3/connection_methods.rb
154
160
  - lib/arjdbc/tasks.rb