activerecord-jdbc-alt-adapter 61.2.0-java → 70.0.0.rc2-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 (78) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/main.yml +118 -0
  3. data/.github/workflows/ruby.yml +273 -0
  4. data/.gitignore +1 -0
  5. data/.travis.yml +3 -4
  6. data/Gemfile +9 -7
  7. data/README.md +5 -1
  8. data/Rakefile +1 -1
  9. data/activerecord-jdbc-adapter.gemspec +2 -2
  10. data/activerecord-jdbc-alt-adapter.gemspec +2 -2
  11. data/lib/arel/visitors/compat.rb +5 -33
  12. data/lib/arel/visitors/h2.rb +1 -13
  13. data/lib/arel/visitors/hsqldb.rb +1 -21
  14. data/lib/arel/visitors/sql_server.rb +2 -103
  15. data/lib/arjdbc/abstract/core.rb +8 -9
  16. data/lib/arjdbc/abstract/database_statements.rb +4 -4
  17. data/lib/arjdbc/discover.rb +0 -67
  18. data/lib/arjdbc/hsqldb/adapter.rb +2 -2
  19. data/lib/arjdbc/jdbc/adapter.rb +3 -3
  20. data/lib/arjdbc/jdbc/adapter_java.jar +0 -0
  21. data/lib/arjdbc/jdbc/adapter_require.rb +3 -1
  22. data/lib/arjdbc/jdbc/column.rb +1 -26
  23. data/lib/arjdbc/jdbc/type_cast.rb +2 -2
  24. data/lib/arjdbc/jdbc.rb +0 -7
  25. data/lib/arjdbc/mssql/adapter.rb +138 -108
  26. data/lib/arjdbc/mssql/quoting.rb +26 -27
  27. data/lib/arjdbc/mssql/schema_creation.rb +1 -1
  28. data/lib/arjdbc/mssql/schema_definitions.rb +32 -17
  29. data/lib/arjdbc/mssql/schema_dumper.rb +13 -1
  30. data/lib/arjdbc/mssql/schema_statements.rb +61 -36
  31. data/lib/arjdbc/mssql/transaction.rb +2 -2
  32. data/lib/arjdbc/mssql/types/date_and_time_types.rb +6 -6
  33. data/lib/arjdbc/mssql/types/numeric_types.rb +2 -2
  34. data/lib/arjdbc/mssql.rb +1 -1
  35. data/lib/arjdbc/mysql/adapter.rb +2 -1
  36. data/lib/arjdbc/oracle/adapter.rb +4 -23
  37. data/lib/arjdbc/postgresql/adapter.rb +152 -4
  38. data/lib/arjdbc/postgresql/oid_types.rb +142 -106
  39. data/lib/arjdbc/sqlite3/adapter.rb +132 -88
  40. data/lib/arjdbc/tasks/database_tasks.rb +0 -12
  41. data/lib/arjdbc/util/serialized_attributes.rb +0 -22
  42. data/lib/arjdbc/util/table_copier.rb +2 -1
  43. data/lib/arjdbc/version.rb +1 -1
  44. data/rakelib/02-test.rake +3 -18
  45. data/src/java/arjdbc/jdbc/RubyJdbcConnection.java +17 -2
  46. data/src/java/arjdbc/postgresql/PostgreSQLRubyJdbcConnection.java +5 -0
  47. data/src/java/arjdbc/sqlite3/SQLite3RubyJdbcConnection.java +33 -0
  48. metadata +9 -40
  49. data/lib/active_record/connection_adapters/as400_adapter.rb +0 -2
  50. data/lib/active_record/connection_adapters/db2_adapter.rb +0 -1
  51. data/lib/active_record/connection_adapters/derby_adapter.rb +0 -1
  52. data/lib/active_record/connection_adapters/informix_adapter.rb +0 -1
  53. data/lib/arel/visitors/db2.rb +0 -137
  54. data/lib/arel/visitors/derby.rb +0 -112
  55. data/lib/arel/visitors/firebird.rb +0 -79
  56. data/lib/arjdbc/db2/adapter.rb +0 -808
  57. data/lib/arjdbc/db2/as400.rb +0 -142
  58. data/lib/arjdbc/db2/column.rb +0 -131
  59. data/lib/arjdbc/db2/connection_methods.rb +0 -48
  60. data/lib/arjdbc/db2.rb +0 -4
  61. data/lib/arjdbc/derby/active_record_patch.rb +0 -13
  62. data/lib/arjdbc/derby/adapter.rb +0 -521
  63. data/lib/arjdbc/derby/connection_methods.rb +0 -20
  64. data/lib/arjdbc/derby/schema_creation.rb +0 -15
  65. data/lib/arjdbc/derby.rb +0 -3
  66. data/lib/arjdbc/firebird/adapter.rb +0 -413
  67. data/lib/arjdbc/firebird/connection_methods.rb +0 -23
  68. data/lib/arjdbc/firebird.rb +0 -4
  69. data/lib/arjdbc/informix/adapter.rb +0 -139
  70. data/lib/arjdbc/informix/connection_methods.rb +0 -9
  71. data/lib/arjdbc/sybase/adapter.rb +0 -47
  72. data/lib/arjdbc/sybase.rb +0 -2
  73. data/lib/arjdbc/tasks/db2_database_tasks.rb +0 -104
  74. data/lib/arjdbc/tasks/derby_database_tasks.rb +0 -95
  75. data/src/java/arjdbc/derby/DerbyModule.java +0 -178
  76. data/src/java/arjdbc/derby/DerbyRubyJdbcConnection.java +0 -152
  77. data/src/java/arjdbc/firebird/FirebirdRubyJdbcConnection.java +0 -174
  78. data/src/java/arjdbc/informix/InformixRubyJdbcConnection.java +0 -75
@@ -11,44 +11,6 @@ module Arel
11
11
 
12
12
  private
13
13
 
14
- def visit_Arel_Nodes_SelectStatement(*args) # [o] AR <= 4.0 [o, a] on 4.1
15
- o, a = args.first, args.last
16
-
17
- return _visit_Arel_Nodes_SelectStatement(*args) if ! o.limit && ! o.offset
18
-
19
- unless o.orders.empty?
20
- select_order_by = do_visit_columns o.orders, a, 'ORDER BY '
21
- end
22
-
23
- select_count = false; sql = ''
24
- o.cores.each do |x|
25
- x = x.dup
26
- core_order_by = select_order_by || determine_order_by(x, a)
27
- if select_count? x
28
- x.projections = [
29
- Arel::Nodes::SqlLiteral.new(core_order_by ? over_row_num(core_order_by) : '*')
30
- ]
31
- select_count = true
32
- else
33
- # NOTE: this should really be added here and we should built the
34
- # wrapping SQL but than #replace_limit_offset! assumes it does that
35
- # ... MS-SQL adapter code seems to be 'hacked' by a lot of people
36
- #x.projections << Arel::Nodes::SqlLiteral.new over_row_num(order_by)
37
- end
38
- sql << do_visit_select_core(x, a)
39
- end
40
-
41
- #sql = "SELECT _t.* FROM (#{sql}) as _t WHERE #{get_offset_limit_clause(o)}"
42
- select_order_by ||= "ORDER BY #{@connection.determine_order_clause(sql)}"
43
- replace_limit_offset!(sql, limit_for(o.limit), o.offset && o.offset.value.to_i, select_order_by)
44
-
45
- sql = "SELECT COUNT(*) AS count_id FROM (#{sql}) AS subquery" if select_count
46
-
47
- add_lock!(sql, :lock => o.lock && true)
48
-
49
- sql
50
- end unless ArJdbc::AR42
51
-
52
14
  # @private
53
15
  MAX_LIMIT_VALUE = 9_223_372_036_854_775_807
54
16
 
@@ -60,14 +22,6 @@ module Arel
60
22
  super
61
23
  end
62
24
 
63
- def visit_Arel_Nodes_Lock o, a = nil
64
- # MS-SQL doesn't support "SELECT...FOR UPDATE". Instead, it needs
65
- # WITH(ROWLOCK,UPDLOCK) specified after each table in the FROM clause.
66
- #
67
- # we return nothing here and add the appropriate stuff with #add_lock!
68
- #do_visit o.expr, a
69
- end unless ArJdbc::AR42
70
-
71
25
  def visit_Arel_Nodes_Top o, a = nil
72
26
  # `top` wouldn't really work here:
73
27
  # User.select("distinct first_name").limit(10)
@@ -76,29 +30,6 @@ module Arel
76
30
  a || ''
77
31
  end
78
32
 
79
- def visit_Arel_Nodes_Limit o, a = nil
80
- "TOP (#{do_visit o.expr, a})"
81
- end unless ArJdbc::AR42
82
-
83
- def visit_Arel_Nodes_Ordering o, a = nil
84
- expr = do_visit o.expr, a
85
- if o.respond_to?(:direction)
86
- "#{expr} #{o.ascending? ? 'ASC' : 'DESC'}"
87
- else
88
- expr
89
- end
90
- end unless ArJdbc::AR42
91
-
92
- def visit_Arel_Nodes_Bin o, a = nil
93
- expr = o.expr; sql = do_visit expr, a
94
- if expr.respond_to?(:val) && expr.val.is_a?(Numeric)
95
- sql
96
- else
97
- sql << " #{::ArJdbc::MSSQL.cs_equality_operator} "
98
- sql
99
- end
100
- end unless ArJdbc::AR42
101
-
102
33
  private
103
34
 
104
35
  def self.possibly_private_method_defined?(name)
@@ -140,25 +71,7 @@ module Arel
140
71
  visit(x, sql); sql << ', ' unless i == last
141
72
  end
142
73
  sql.value
143
- end if ArJdbc::AR42
144
-
145
- def do_visit_columns(colls, a, sql)
146
- non_simple_order = /\sASC|\sDESC|\sCASE|\sCOLLATE|[\.,\[\(]/i # MIN(width)
147
-
148
- last = colls.size - 1
149
- colls.each_with_index do |x, i|
150
- coll = do_visit(x, a)
151
-
152
- if coll !~ non_simple_order && coll.to_i == 0
153
- sql << @connection.quote_column_name(coll)
154
- else
155
- sql << coll
156
- end
157
-
158
- sql << ', ' unless i == last
159
- end
160
- sql
161
- end if Arel::VERSION < '4.0.0'
74
+ end
162
75
 
163
76
  def over_row_num order_by
164
77
  "ROW_NUMBER() OVER (#{order_by}) as _row_num"
@@ -174,20 +87,6 @@ module Arel
174
87
  end
175
88
  end
176
89
 
177
- def table_from_select_core core
178
- table_finder = lambda do |x|
179
- case x
180
- when Arel::Table
181
- x
182
- when Arel::Nodes::SqlLiteral
183
- Arel::Table.new(x, @engine)
184
- when Arel::Nodes::Join
185
- table_finder.call(x.left)
186
- end
187
- end
188
- table_finder.call(core.froms)
189
- end if ActiveRecord::VERSION::STRING < '3.2'
190
-
191
90
  def primary_key_from_table t
192
91
  return unless t
193
92
  return t.primary_key if t.primary_key
@@ -219,7 +118,7 @@ module Arel
219
118
  include ArJdbc::MSSQL::LimitHelpers::SqlServer2000ReplaceLimitOffset
220
119
  end
221
120
 
222
- load 'arel/visitors/sql_server/ng42.rb' if ArJdbc::AR42
121
+ load 'arel/visitors/sql_server/ng42.rb'
223
122
 
224
123
  end
225
124
  end
@@ -34,7 +34,7 @@ module ArJdbc
34
34
  raw_connection.jdbc_connection(unwrap)
35
35
  end
36
36
 
37
- protected
37
+ private
38
38
 
39
39
  def translate_exception_class(e, sql, binds)
40
40
  message = "#{e.class.name}: #{e.message}"
@@ -42,16 +42,19 @@ module ArJdbc
42
42
  exception = translate_exception(
43
43
  e, message: message, sql: sql, binds: binds
44
44
  )
45
- exception.set_backtrace e.backtrace
45
+ exception.set_backtrace e.backtrace unless exception.equal?(e)
46
46
  exception
47
47
  end
48
48
 
49
+ Throwable = java.lang.Throwable
50
+ private_constant :Throwable
51
+
49
52
  def translate_exception(exception, message:, sql:, binds:)
50
53
  # override in derived class
51
54
 
52
55
  # we shall not translate native "Java" exceptions as they might
53
56
  # swallow an ArJdbc / driver bug into an AR::StatementInvalid !
54
- return exception if exception.is_a?(Java::JavaLang::Throwable)
57
+ return exception if exception.is_a?(Throwable)
55
58
 
56
59
  case exception
57
60
  when SystemExit, SignalException, NoMemoryError then exception
@@ -61,14 +64,10 @@ module ArJdbc
61
64
  end
62
65
  end
63
66
 
64
- def extract_raw_bind_values(binds)
65
- binds.map(&:value_for_database)
66
- end
67
-
68
67
  # this version of log() automatically fills type_casted_binds from binds if necessary
69
- def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = nil)
68
+ def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = nil, async: false)
70
69
  if binds.any? && (type_casted_binds.nil? || type_casted_binds.empty?)
71
- type_casted_binds = ->{ extract_raw_bind_values(binds) }
70
+ type_casted_binds = ->{ binds.map(&:value_for_database) } # extract_raw_bind_values
72
71
  end
73
72
  super
74
73
  end
@@ -30,7 +30,7 @@ module ArJdbc
30
30
 
31
31
  # It appears that at this point (AR 5.0) "prepare" should only ever be true
32
32
  # if prepared statements are enabled
33
- def exec_query(sql, name = nil, binds = NO_BINDS, prepare: false)
33
+ def exec_query(sql, name = nil, binds = NO_BINDS, prepare: false, async: false)
34
34
  if preventing_writes? && write_query?(sql)
35
35
  raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
36
36
  end
@@ -69,7 +69,7 @@ module ArJdbc
69
69
  end
70
70
  alias :exec_delete :exec_update
71
71
 
72
- def execute(sql, name = nil)
72
+ def execute(sql, name = nil, async: false)
73
73
  if preventing_writes? && write_query?(sql)
74
74
  raise ActiveRecord::ReadOnlyError, "Write query attempted while in readonly mode: #{sql}"
75
75
  end
@@ -77,11 +77,11 @@ module ArJdbc
77
77
  materialize_transactions
78
78
  mark_transaction_written_if_write(sql)
79
79
 
80
- log(sql, name) { @connection.execute(sql) }
80
+ log(sql, name, async: async) { @connection.execute(sql) }
81
81
  end
82
82
 
83
83
  # overridden to support legacy binds
84
- def select_all(arel, name = nil, binds = NO_BINDS, preparable: nil)
84
+ def select_all(arel, name = nil, binds = NO_BINDS, preparable: nil, async: false)
85
85
  binds = convert_legacy_binds_to_attributes(binds) if binds.first.is_a?(Array)
86
86
  super
87
87
  end
@@ -23,26 +23,6 @@ module ArJdbc
23
23
  require('arjdbc/sqlite3') || true if name =~ /sqlite/i
24
24
  end
25
25
 
26
- # Other supported adapters :
27
-
28
- extension :Derby do |name, config|
29
- if name =~ /derby/i
30
- require 'arjdbc/derby'
31
-
32
- if config && config[:username].nil? # set the database schema name (:username) :
33
- begin
34
- ArJdbc.with_meta_data_from_data_source_if_any(config) do
35
- |meta_data| config[:username] = meta_data.getUserName
36
- end
37
- rescue => e
38
- ArJdbc.warn("failed to set :username from (Derby) database meda-data: #{e.inspect}")
39
- end
40
- end
41
-
42
- true
43
- end
44
- end
45
-
46
26
  extension :H2 do |name|
47
27
  require('arjdbc/h2') || true if name =~ /\.h2\./i
48
28
  end
@@ -54,51 +34,4 @@ module ArJdbc
54
34
  extension :MSSQL do |name|
55
35
  require('arjdbc/mssql') || true if name =~ /sqlserver|tds|Microsoft SQL/i
56
36
  end
57
-
58
- extension :DB2 do |name, config|
59
- if name =~ /db2/i && name !~ /as\/?400/i && config[:url] !~ /^jdbc:derby:net:/
60
- require 'arjdbc/db2'
61
- true
62
- end
63
- end
64
-
65
- extension :AS400 do |name, config|
66
- # The native JDBC driver always returns "DB2 UDB for AS/400"
67
- if name =~ /as\/?400/i
68
- require 'arjdbc/db2'
69
- require 'arjdbc/db2/as400'
70
- true
71
- end
72
- end
73
-
74
- # NOTE: following ones are likely getting deprecated :
75
-
76
- extension :FireBird do |name|
77
- if name =~ /firebird/i
78
- require 'arjdbc/firebird'
79
- true
80
- end
81
- end
82
-
83
- extension :Sybase do |name|
84
- if name =~ /sybase|tds/i
85
- require 'arjdbc/sybase'
86
- true
87
- end
88
- end
89
-
90
- extension :Informix do |name|
91
- if name =~ /informix/i
92
- require 'arjdbc/informix'
93
- true
94
- end
95
- end
96
-
97
- extension :Mimer do |name|
98
- if name =~ /mimer/i
99
- require 'arjdbc/mimer'
100
- true
101
- end
102
- end
103
-
104
37
  end
@@ -111,7 +111,7 @@ module ArJdbc
111
111
  if column_type == :time
112
112
  "'#{value.strftime("%H:%M:%S")}'"
113
113
  #elsif column_type == :timestamp # || column_type == :datetime
114
- #value = ::ActiveRecord::Base.default_timezone == :utc ? value.getutc : value.getlocal
114
+ #value = ::ActiveRecord.default_timezone == :utc ? value.getutc : value.getlocal
115
115
  #"'#{value.strftime("%Y-%m-%d %H:%M:%S")}.#{sprintf("%06d", value.usec)}'"
116
116
  else
117
117
  super
@@ -127,7 +127,7 @@ module ArJdbc
127
127
  def quoted_date(value)
128
128
  if value.acts_like?(:time) && value.respond_to?(:usec)
129
129
  usec = sprintf("%06d", value.usec)
130
- value = ::ActiveRecord::Base.default_timezone == :utc ? value.getutc : value.getlocal
130
+ value = ::ActiveRecord.default_timezone == :utc ? value.getutc : value.getlocal
131
131
  "#{value.strftime("%Y-%m-%d %H:%M:%S")}.#{usec}"
132
132
  else
133
133
  super
@@ -431,12 +431,12 @@ module ActiveRecord
431
431
  private
432
432
 
433
433
  # Helper useful during {#quote} since AREL might pass in it's literals
434
- # to be quoted, fixed since AREL 4.0.0.beta1 : http://git.io/7gyTig
434
+ # to be quoted, fixed since AREL 4.0.0.beta1 : https://github.com/rails/arel/commit/9c514f3
435
435
  def sql_literal?(value); ::Arel::Nodes::SqlLiteral === value; end
436
436
 
437
- # Helper to get local/UTC time (based on `ActiveRecord::Base.default_timezone`).
437
+ # Helper to get local/UTC time (based on `ActiveRecord::default_timezone`).
438
438
  def get_time(value)
439
- get = ::ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
439
+ get = ::ActiveRecord.default_timezone == :utc ? :getutc : :getlocal
440
440
  value.respond_to?(get) ? value.send(get) : value
441
441
  end
442
442
 
Binary file
@@ -2,7 +2,9 @@
2
2
 
3
3
  module ActiveRecord
4
4
 
5
- if defined? ConnectionAdapters::ConnectionSpecification::Resolver # 4.0
5
+ if defined? ConnectionAdapters::ConnectionHandler # 6.1
6
+ ConnectionAdapters::ConnectionHandler
7
+ elsif defined? ConnectionAdapters::ConnectionSpecification::Resolver # 4.0, # 5.x, # 6.0
6
8
  ConnectionAdapters::ConnectionSpecification::Resolver
7
9
  elsif defined? Base::ConnectionSpecification::Resolver # 3.2
8
10
  Base::ConnectionSpecification::Resolver
@@ -28,21 +28,6 @@ module ActiveRecord
28
28
  end
29
29
  end
30
30
 
31
- if ArJdbc::AR52
32
- # undefined method `cast' for #<ActiveRecord::ConnectionAdapters::SqlTypeMetadata> on AR52
33
- else
34
- default = args[0].cast(default)
35
-
36
- sql_type = args.delete_at(1)
37
- type = args.delete_at(0)
38
-
39
- args.unshift(SqlTypeMetadata.new(:sql_type => sql_type, :type => type))
40
- end
41
-
42
- # super <= 4.1: (name, default, sql_type = nil, null = true)
43
- # super >= 4.2: (name, default, cast_type, sql_type = nil, null = true)
44
- # super >= 5.0: (name, default, sql_type_metadata = nil, null = true)
45
-
46
31
  super(name, default, *args)
47
32
  init_column(name, default, *args)
48
33
  end
@@ -80,18 +65,8 @@ module ActiveRecord
80
65
  end
81
66
 
82
67
  class << self
83
-
84
- include Jdbc::TypeCast if ::ActiveRecord::VERSION::STRING >= '4.2'
85
-
86
- if ActiveRecord::VERSION::MAJOR > 3 && ActiveRecord::VERSION::STRING < '4.2'
87
-
88
- # @private provides compatibility between AR 3.x/4.0 API
89
- def string_to_date(value); value_to_date(value) end
90
-
91
- end
92
-
68
+ include Jdbc::TypeCast
93
69
  end
94
-
95
70
  end
96
71
  end
97
72
  end
@@ -130,9 +130,9 @@ module ActiveRecord::ConnectionAdapters
130
130
  return nil unless time
131
131
 
132
132
  time -= offset
133
- ActiveRecord::Base.default_timezone == :utc ? time : time.getlocal
133
+ ActiveRecord.default_timezone == :utc ? time : time.getlocal
134
134
  else
135
- timezone = ActiveRecord::Base.default_timezone
135
+ timezone = ActiveRecord.default_timezone
136
136
  Time.public_send(timezone, year, mon, mday, hour, min, sec, microsec) rescue nil
137
137
  end
138
138
  end
data/lib/arjdbc/jdbc.rb CHANGED
@@ -1,13 +1,6 @@
1
1
  require 'active_support/deprecation'
2
2
 
3
3
  module ArJdbc
4
-
5
- # @private
6
- AR42 = ::ActiveRecord::VERSION::STRING >= '4.2'
7
-
8
- # @private
9
- AR52 = ::ActiveRecord::VERSION::STRING >= '5.2'
10
-
11
4
  class << self
12
5
 
13
6
  # @private Internal API