activerecord-jdbc-adapter 52.8-java → 60.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -2
  3. data/.travis.yml +58 -37
  4. data/Gemfile +9 -2
  5. data/README.md +25 -9
  6. data/Rakefile +1 -1
  7. data/Rakefile.jdbc +8 -1
  8. data/activerecord-jdbc-adapter.gemspec +5 -8
  9. data/lib/arjdbc/abstract/connection_management.rb +7 -0
  10. data/lib/arjdbc/abstract/core.rb +16 -23
  11. data/lib/arjdbc/abstract/database_statements.rb +26 -2
  12. data/lib/arjdbc/abstract/statement_cache.rb +2 -5
  13. data/lib/arjdbc/abstract/transaction_support.rb +5 -3
  14. data/lib/arjdbc/db2/column.rb +0 -39
  15. data/lib/arjdbc/derby/adapter.rb +1 -20
  16. data/lib/arjdbc/firebird/adapter.rb +0 -21
  17. data/lib/arjdbc/h2/adapter.rb +0 -15
  18. data/lib/arjdbc/hsqldb/adapter.rb +0 -14
  19. data/lib/arjdbc/informix/adapter.rb +0 -23
  20. data/lib/arjdbc/jdbc/adapter.rb +3 -1
  21. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  22. data/lib/arjdbc/jdbc/adapter_require.rb +3 -1
  23. data/lib/arjdbc/jdbc/base_ext.rb +3 -1
  24. data/lib/arjdbc/jdbc/callbacks.rb +2 -0
  25. data/lib/arjdbc/jdbc/column.rb +2 -0
  26. data/lib/arjdbc/jdbc/connection.rb +2 -0
  27. data/lib/arjdbc/jdbc/connection_methods.rb +2 -0
  28. data/lib/arjdbc/jdbc/error.rb +2 -0
  29. data/lib/arjdbc/jdbc/extension.rb +2 -0
  30. data/lib/arjdbc/jdbc/java.rb +3 -1
  31. data/lib/arjdbc/jdbc/railtie.rb +3 -1
  32. data/lib/arjdbc/jdbc/rake_tasks.rb +3 -1
  33. data/lib/arjdbc/jdbc/serialized_attributes_helper.rb +3 -1
  34. data/lib/arjdbc/jdbc/type_cast.rb +2 -0
  35. data/lib/arjdbc/jdbc/type_converter.rb +2 -0
  36. data/lib/arjdbc/mysql/adapter.rb +47 -18
  37. data/lib/arjdbc/mysql/connection_methods.rb +0 -1
  38. data/lib/arjdbc/postgresql/adapter.rb +220 -213
  39. data/lib/arjdbc/postgresql/base/array_decoder.rb +2 -0
  40. data/lib/arjdbc/postgresql/base/array_encoder.rb +4 -2
  41. data/lib/arjdbc/postgresql/base/array_parser.rb +4 -2
  42. data/lib/arjdbc/postgresql/base/pgconn.rb +2 -0
  43. data/lib/arjdbc/postgresql/column.rb +6 -4
  44. data/lib/arjdbc/postgresql/connection_methods.rb +0 -1
  45. data/lib/arjdbc/postgresql/name.rb +2 -0
  46. data/lib/arjdbc/postgresql/oid_types.rb +2 -0
  47. data/lib/arjdbc/sqlite3/adapter.rb +175 -180
  48. data/lib/arjdbc/sqlite3/connection_methods.rb +15 -5
  49. data/lib/arjdbc/tasks/databases.rake +13 -10
  50. data/lib/arjdbc/util/quoted_cache.rb +3 -1
  51. data/lib/arjdbc/util/serialized_attributes.rb +3 -1
  52. data/lib/arjdbc/util/table_copier.rb +3 -1
  53. data/lib/arjdbc/version.rb +1 -1
  54. data/pom.xml +4 -4
  55. data/rakelib/01-tomcat.rake +2 -2
  56. data/rakelib/rails.rake +1 -1
  57. data/src/java/arjdbc/ArJdbcModule.java +5 -5
  58. data/src/java/arjdbc/jdbc/DriverWrapper.java +1 -9
  59. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +434 -701
  60. data/src/java/arjdbc/mssql/MSSQLRubyJdbcConnection.java +0 -51
  61. data/src/java/arjdbc/mysql/MySQLRubyJdbcConnection.java +13 -23
  62. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +31 -24
  63. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +94 -99
  64. metadata +7 -9
@@ -28,11 +28,6 @@ module ArJdbc
28
28
  end
29
29
  end
30
30
 
31
- # @see ActiveRecord::ConnectionAdapters::JdbcColumn#column_types
32
- def self.column_selector
33
- [ /informix/i, lambda { |cfg, column| column.extend(ColumnMethods) } ]
34
- end
35
-
36
31
  JdbcConnection = ::ActiveRecord::ConnectionAdapters::InformixJdbcConnection
37
32
 
38
33
  # @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
@@ -45,20 +40,6 @@ module ArJdbc
45
40
  ::ActiveRecord::ConnectionAdapters::InformixColumn
46
41
  end
47
42
 
48
- module ColumnMethods
49
-
50
- private
51
- # TODO: Test all Informix column types.
52
- def simplified_type(field_type)
53
- if field_type =~ /serial/i
54
- :primary_key
55
- else
56
- super
57
- end
58
- end
59
-
60
- end
61
-
62
43
  def modify_types(types)
63
44
  super(types)
64
45
  types[:primary_key] = "SERIAL PRIMARY KEY"
@@ -152,10 +133,6 @@ module ArJdbc
152
133
  end # module ::ArJdbc
153
134
 
154
135
  module ActiveRecord::ConnectionAdapters
155
- class InformixColumn < JdbcColumn
156
- include ::ArJdbc::Informix::ColumnMethods
157
- end
158
-
159
136
  class InformixAdapter < JdbcAdapter
160
137
  include ::ArJdbc::Informix
161
138
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_record/version'
2
4
  require 'active_record/connection_adapters/abstract_adapter'
3
5
 
@@ -94,7 +96,7 @@ module ActiveRecord
94
96
  nil
95
97
  end
96
98
 
97
- ADAPTER_NAME = 'JDBC'.freeze
99
+ ADAPTER_NAME = 'JDBC'
98
100
 
99
101
  # @return [String] the 'JDBC' adapter name.
100
102
  def adapter_name
Binary file
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
 
3
5
  if defined? ConnectionAdapters::ConnectionSpecification::Resolver # 4.0
@@ -43,4 +45,4 @@ module ActiveRecord
43
45
 
44
46
  end
45
47
 
46
- end
48
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  class << Base
3
5
  m = Module.new do
@@ -12,4 +14,4 @@ module ActiveRecord
12
14
 
13
15
  self.prepend(m)
14
16
  end
15
- end
17
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord::ConnectionAdapters
2
4
  module Jdbc
3
5
  # ActiveRecord connection pool callbacks for JDBC.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  module ConnectionAdapters
3
5
  module Jdbc
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  module ConnectionAdapters
3
5
  # JDBC (connection) base class, custom adapters we support likely extend
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ArJdbc
2
4
  ConnectionMethods = ::ActiveRecord::ConnectionHandling
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  # Represents exceptions that have propagated up through the JDBC API.
3
5
  class JDBCError < WrappedDatabaseException
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ArJdbc
2
4
 
3
5
  # Defines an AR-JDBC extension. An extension consists of a declaration using
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'java'
2
4
  require 'arjdbc/jdbc/adapter_java'
3
5
 
@@ -10,4 +12,4 @@ module ActiveRecord
10
12
  Types = ::Java::JavaSql::Types
11
13
  end
12
14
  end
13
- end
15
+ end
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'arjdbc/railtie'
2
- ArJdbc.deprecate "require 'arjdbc/railtie' instead of 'arjdbc/jdbc/railtie'"
4
+ ArJdbc.deprecate "require 'arjdbc/railtie' instead of 'arjdbc/jdbc/railtie'"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  load 'arjdbc/tasks.rb'
2
4
 
3
- ArJdbc.deprecate "load 'arjdbc/tasks.rb' instead of 'arjdbc/jdbc/rake_tasks.rb'"
5
+ ArJdbc.deprecate "load 'arjdbc/tasks.rb' instead of 'arjdbc/jdbc/rake_tasks.rb'"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'arjdbc/util/serialized_attributes'
2
4
 
3
- ArJdbc.deprecate "require 'arjdbc/util/serialized_attributes' instead of 'arjdbc/jdbc/serialized_attributes_helper'"
5
+ ArJdbc.deprecate "require 'arjdbc/util/serialized_attributes' instead of 'arjdbc/jdbc/serialized_attributes_helper'"
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_record/connection_adapters/column'
2
4
 
3
5
  module ActiveRecord::ConnectionAdapters
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveRecord
2
4
  module ConnectionAdapters
3
5
  # I want to use JDBC's DatabaseMetaData#getTypeInfo to choose the best native types to
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  ArJdbc.load_java_part :MySQL
2
4
 
3
5
  require 'bigdecimal'
@@ -19,7 +21,7 @@ module ActiveRecord
19
21
  remove_const(:Mysql2Adapter) if const_defined?(:Mysql2Adapter)
20
22
 
21
23
  class Mysql2Adapter < AbstractMysqlAdapter
22
- ADAPTER_NAME = 'Mysql2'.freeze
24
+ ADAPTER_NAME = 'Mysql2'
23
25
 
24
26
  include Jdbc::ConnectionPoolCallbacks
25
27
 
@@ -32,21 +34,30 @@ module ActiveRecord
32
34
  include ArJdbc::MySQL
33
35
 
34
36
  def initialize(connection, logger, connection_parameters, config)
35
- # workaround to skip version check on JNDI to be lazy, dummy version is high enough for Rails 5.0 - 6.0
36
- is_jndi = ::ActiveRecord::ConnectionAdapters::JdbcConnection.jndi_config?(config)
37
- @version = '8.1.5' if is_jndi
38
-
39
37
  super
40
38
 
41
- # set to nil to have it lazy-load the real value when required
42
- @version = nil if is_jndi
43
-
44
39
  @prepared_statements = false unless config.key?(:prepared_statements)
45
40
  # configure_connection taken care of at ArJdbc::Abstract::Core
46
41
  end
47
42
 
43
+ def self.database_exists?(config)
44
+ conn = ActiveRecord::Base.mysql2_connection(config)
45
+ conn && conn.really_valid?
46
+ rescue ActiveRecord::NoDatabaseError
47
+ false
48
+ ensure
49
+ conn.disconnect! if conn
50
+ end
51
+
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
+
48
59
  def supports_json?
49
- !mariadb? && version >= '5.7.8'
60
+ !mariadb? && database_version >= '5.7.8'
50
61
  end
51
62
 
52
63
  def supports_comments?
@@ -61,6 +72,10 @@ module ActiveRecord
61
72
  true
62
73
  end
63
74
 
75
+ def supports_lazy_transactions?
76
+ true
77
+ end
78
+
64
79
  def supports_transaction_isolation?
65
80
  true
66
81
  end
@@ -71,6 +86,16 @@ module ActiveRecord
71
86
 
72
87
  # HELPER METHODS ===========================================
73
88
 
89
+ # from MySQL::DatabaseStatements
90
+ READ_QUERY = ActiveRecord::ConnectionAdapters::AbstractAdapter.build_read_query_regexp(
91
+ :begin, :commit, :explain, :select, :set, :show, :release, :savepoint, :rollback, :describe, :desc
92
+ ) # :nodoc:
93
+ private_constant :READ_QUERY
94
+
95
+ def write_query?(sql) # :nodoc:
96
+ !READ_QUERY.match?(sql)
97
+ end
98
+
74
99
  # Reloading the type map in abstract/statement_cache.rb blows up postgres
75
100
  def clear_cache!
76
101
  reload_type_map
@@ -136,7 +161,13 @@ module ActiveRecord
136
161
  private
137
162
 
138
163
  # e.g. "5.7.20-0ubuntu0.16.04.1"
139
- def full_version; @full_version ||= @connection.full_version end
164
+ def full_version
165
+ schema_cache.database_version.full_version_string
166
+ end
167
+
168
+ def get_full_version
169
+ @full_version ||= @connection.full_version
170
+ end
140
171
 
141
172
  def jdbc_connection_class(spec)
142
173
  ::ActiveRecord::ConnectionAdapters::MySQLJdbcConnection
@@ -152,15 +183,13 @@ module ActiveRecord
152
183
  end
153
184
 
154
185
  # FIXME: optimize insert_fixtures_set by using JDBC Statement.addBatch()/executeBatch()
155
- def combine_multi_statements(total_sql)
156
- total_sql
157
- end
158
-
159
- def with_multi_statements
160
- yield
161
- end
162
186
 
163
- def discard_remaining_results
187
+ def combine_multi_statements(total_sql)
188
+ if total_sql.length == 1
189
+ total_sql.first
190
+ else
191
+ total_sql
192
+ end
164
193
  end
165
194
  end
166
195
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  ArJdbc::ConnectionMethods.module_eval do
3
3
  def mysql_connection(config)
4
- config = config.deep_dup
5
4
  # NOTE: this isn't "really" necessary but Rails (in tests) assumes being able to :
6
5
  # ActiveRecord::Base.mysql2_connection ActiveRecord::Base.configurations['arunit'].merge(database: ...)
7
6
  config = symbolize_keys_if_necessary(config)