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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +135 -21
  3. data/.github/workflows/ruby.yml +10 -10
  4. data/.gitignore +1 -0
  5. data/.solargraph.yml +15 -0
  6. data/Gemfile +17 -4
  7. data/README.md +7 -3
  8. data/RUNNING_TESTS.md +36 -0
  9. data/activerecord-jdbc-adapter.gemspec +2 -2
  10. data/activerecord-jdbc-alt-adapter.gemspec +1 -1
  11. data/lib/arjdbc/abstract/connection_management.rb +23 -10
  12. data/lib/arjdbc/abstract/core.rb +5 -6
  13. data/lib/arjdbc/abstract/database_statements.rb +35 -25
  14. data/lib/arjdbc/abstract/statement_cache.rb +1 -6
  15. data/lib/arjdbc/abstract/transaction_support.rb +37 -9
  16. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  17. data/lib/arjdbc/jdbc/column.rb +0 -34
  18. data/lib/arjdbc/jdbc/connection_methods.rb +1 -1
  19. data/lib/arjdbc/mssql/adapter.rb +93 -80
  20. data/lib/arjdbc/mssql/column.rb +1 -0
  21. data/lib/arjdbc/mssql/connection_methods.rb +7 -55
  22. data/lib/arjdbc/mssql/database_statements.rb +182 -71
  23. data/lib/arjdbc/mssql/explain_support.rb +8 -5
  24. data/lib/arjdbc/mssql/schema_creation.rb +1 -1
  25. data/lib/arjdbc/mssql/schema_definitions.rb +10 -0
  26. data/lib/arjdbc/mssql/schema_statements.rb +19 -11
  27. data/lib/arjdbc/mssql/server_version.rb +56 -0
  28. data/lib/arjdbc/mssql/utils.rb +23 -9
  29. data/lib/arjdbc/mysql/adapter.rb +64 -22
  30. data/lib/arjdbc/sqlite3/adapter.rb +218 -135
  31. data/lib/arjdbc/sqlite3/column.rb +103 -0
  32. data/lib/arjdbc/sqlite3/connection_methods.rb +7 -2
  33. data/lib/arjdbc/tasks/mssql_database_tasks.rb +9 -5
  34. data/lib/arjdbc/version.rb +1 -1
  35. data/rakelib/02-test.rake +1 -1
  36. data/rakelib/rails.rake +2 -0
  37. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +4 -2
  38. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +2 -1
  39. metadata +9 -12
  40. data/lib/arel/visitors/sql_server/ng42.rb +0 -294
  41. data/lib/arel/visitors/sql_server.rb +0 -124
  42. data/lib/arjdbc/mssql/limit_helpers.rb +0 -231
  43. data/lib/arjdbc/mssql/lock_methods.rb +0 -77
  44. data/lib/arjdbc/mssql/old_adapter.rb +0 -804
  45. data/lib/arjdbc/mssql/old_column.rb +0 -200
@@ -33,11 +33,19 @@ module ActiveRecord
33
33
 
34
34
  include ArJdbc::MySQL
35
35
 
36
- def initialize(connection, logger, connection_options, config)
37
- superclass_config = config.reverse_merge(prepared_statements: false)
38
- super(connection, logger, connection_options, superclass_config)
36
+ def initialize(...)
37
+ super
38
+
39
+ @config[:flags] ||= 0
39
40
 
40
- # configure_connection taken care of at ArJdbc::Abstract::Core
41
+ # JDBC mysql appears to use found rows by default: https://dev.mysql.com/doc/connector-j/en/connector-j-connp-props-connection.html
42
+ # if @config[:flags].kind_of? Array
43
+ # @config[:flags].push "FOUND_ROWS"
44
+ # else
45
+ # @config[:flags] |= ::Mysql2::Client::FOUND_ROWS
46
+ # end
47
+
48
+ @connection_parameters ||= @config
41
49
  end
42
50
 
43
51
  def self.database_exists?(config)
@@ -49,13 +57,6 @@ module ActiveRecord
49
57
  conn.disconnect! if conn
50
58
  end
51
59
 
52
- def check_version
53
- # for JNDI, don't check version as the whole connection should be lazy
54
- return if ::ActiveRecord::ConnectionAdapters::JdbcConnection.jndi_config?(config)
55
-
56
- super
57
- end
58
-
59
60
  def supports_json?
60
61
  !mariadb? && database_version >= '5.7.8'
61
62
  end
@@ -96,20 +97,25 @@ module ActiveRecord
96
97
  !READ_QUERY.match?(sql)
97
98
  end
98
99
 
99
- def explain(arel, binds = [])
100
- sql = "EXPLAIN #{to_sql(arel, binds)}"
101
- start = Concurrent.monotonic_time
102
- result = exec_query(sql, "EXPLAIN", binds)
103
- elapsed = Concurrent.monotonic_time - start
100
+ def explain(arel, binds = [], options = [])
101
+ sql = build_explain_clause(options) + " " + to_sql(arel, binds)
102
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
103
+ result = internal_exec_query(sql, "EXPLAIN", binds)
104
+ elapsed = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start
104
105
 
105
106
  MySQL::ExplainPrettyPrinter.new.pp(result, elapsed)
106
107
  end
107
108
 
108
- # Reloading the type map in abstract/statement_cache.rb blows up postgres
109
- def clear_cache!
110
- # FIXME: This seems to have disappeared in Rails 7?
111
- # reload_type_map
112
- super
109
+ def build_explain_clause(options = [])
110
+ return "EXPLAIN" if options.empty?
111
+
112
+ explain_clause = "EXPLAIN #{options.join(" ").upcase}"
113
+
114
+ if analyze_without_explain? && explain_clause.include?("ANALYZE")
115
+ explain_clause.sub("EXPLAIN ", "")
116
+ else
117
+ explain_clause
118
+ end
113
119
  end
114
120
 
115
121
  def each_hash(result) # :nodoc:
@@ -164,11 +170,47 @@ module ActiveRecord
164
170
  # CONNECTION MANAGEMENT ====================================
165
171
  #++
166
172
 
173
+ def active?
174
+ !(@raw_connection.nil? || @raw_connection.closed?) && @lock.synchronize { @raw_connection&.execute_query("/* ping */ SELECT 1") } || false
175
+ end
176
+
167
177
  alias :reset! :reconnect!
168
178
 
179
+ # Disconnects from the database if already connected.
180
+ # Otherwise, this method does nothing.
181
+ def disconnect!
182
+ @lock.synchronize do
183
+ super
184
+ @raw_connection&.close
185
+ @raw_connection = nil
186
+ end
187
+ end
188
+
189
+ def discard! # :nodoc:
190
+ @lock.synchronize do
191
+ super
192
+ @raw_connection&.automatic_close = false
193
+ @raw_connection = nil
194
+ end
195
+ end
196
+
169
197
  #
170
198
 
171
199
  private
200
+ # https://mariadb.com/kb/en/analyze-statement/
201
+ def analyze_without_explain?
202
+ mariadb? && database_version >= "10.1.0"
203
+ end
204
+
205
+ def text_type?(type)
206
+ TYPE_MAP.lookup(type).is_a?(Type::String) || TYPE_MAP.lookup(type).is_a?(Type::Text)
207
+ end
208
+
209
+ def configure_connection
210
+ # @raw_connection.query_options[:as] = :array
211
+ # @raw_connection.query_options[:database_timezone] = default_timezone
212
+ super
213
+ end
172
214
 
173
215
  # e.g. "5.7.20-0ubuntu0.16.04.1"
174
216
  def full_version
@@ -176,7 +218,7 @@ module ActiveRecord
176
218
  end
177
219
 
178
220
  def get_full_version
179
- @full_version ||= @connection.full_version
221
+ @full_version ||= any_raw_connection.full_version
180
222
  end
181
223
 
182
224
  def jdbc_connection_class(spec)