activerecord-jdbc-adapter 1.3.11 → 1.3.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f03faf8d22c162a753fa8ec38946245c02349313
4
- data.tar.gz: 30303e6bb6a9a6ce48d40bf9d3ff82e9284a28ba
3
+ metadata.gz: 2e7fd59bd6f8be3d2d0da36e413324eea6539846
4
+ data.tar.gz: ca2bb40471a4076ead3ee9476c5edbd53b63a06e
5
5
  SHA512:
6
- metadata.gz: 669950d37ac2e29a1940ceb0fa4105d760593757d14e90e6bb520bf56332c0935238f82eac066a3948c88fc6d330295f357b9eac7d62029ce87d3c4e5354b73a
7
- data.tar.gz: 598604f3136587a838cc500fae9a3b152c5b5a853e29b2bffd5e8e1f4a55c417a6323b4eb1def19cef954fbfa8b2ba5daef827a52e3bba9786e4dd1107edae4e
6
+ metadata.gz: e14b3b99f73a202f4b494f79ee11af3440965a706c3d6e335292d184c3ea2bbf5166e0a2ba8f59a03ceffb8a40bc98eaa54f23448f40c18c7f1b0ae58e988e65
7
+ data.tar.gz: 2833ecd5d304e9d99b80d8efd7e7e2be0061d3fef2db16eee749986602a8b361cbe293453c139426cf51034989c3e388b0c0fd564581178143d196cb25ee0aab
data/Appraisals CHANGED
@@ -17,12 +17,12 @@ end
17
17
 
18
18
  appraise "rails40" do
19
19
  # NOTE: make sure you're using --1.9 with AR-4.0
20
- gem "activerecord", "~> 4.0.8", :require => false
20
+ gem "activerecord", "~> 4.0.10", :require => false
21
21
  end
22
22
 
23
23
  appraise "rails41" do
24
24
  # NOTE: make sure you're using --1.9 with AR-4.0
25
- gem "activerecord", "~> 4.1.4", :require => false
25
+ gem "activerecord", "~> 4.1.7", :require => false
26
26
  end
27
27
 
28
28
  appraise "rails42" do
data/Gemfile CHANGED
@@ -48,6 +48,10 @@ group :rails do
48
48
  gem 'actionpack', :require => nil
49
49
  end
50
50
 
51
+ if sqlite_version = ENV['JDBC_SQLITE_VERSION'] # for testing against different version(s)
52
+ gem 'jdbc-sqlite3', sqlite_version, :require => nil, :platform => :jruby, :group => :test
53
+ end
54
+
51
55
  gem 'mysql2', :require => nil, :platform => :mri, :group => :test
52
56
  gem 'pg', :require => nil, :platform => :mri, :group => :test
53
57
  gem 'sqlite3', :require => nil, :platform => :mri, :group => :test
data/History.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 1.3.12 (11/18/14)
2
+
3
+ - [sqlite] support for latest JDBC 3.8
4
+ - [mysql] correctly map config[:encoding] into Connector-J characterEncoding
5
+ - [mysql] backport rename_index from Rails (corectly handling MariaDB as well)
6
+ - [mysql] core adapter compat - missing initialize_schema_migrations_table
7
+ - `supports_views?` is now a method available in 4.2 (most DBs support VIEWs)
8
+ - [postgres] table_exists? fully compatible with Rails 4.1
9
+ - handle pre JDBC 4 driver abstract method errors somehow gracefully
10
+ - tune ArJdbc scoped warnings/deprecations (can be off -J-Darjdbc.warn=false)
11
+
1
12
  ## 1.3.11 (10/20/14)
2
13
 
3
14
  - arjdbc: performance improvement - avodinng JRuby's impl iface generation
@@ -572,6 +572,9 @@ module ArJdbc
572
572
  tables.each { |table| drop_table("#{table}") }
573
573
  end
574
574
 
575
+ # @override
576
+ def supports_views?; true end
577
+
575
578
  def execute_table_change(sql, table_name, name = nil)
576
579
  outcome = execute(sql, name)
577
580
  reorg_table(table_name, name)
@@ -196,10 +196,13 @@ module ArJdbc
196
196
  end
197
197
  end
198
198
 
199
+ # @override
200
+ def supports_views?; true end
201
+
199
202
  # EXPLAIN support :
200
203
 
201
204
  # @override
202
- def supports_explain?; true; end
205
+ def supports_explain?; true end
203
206
 
204
207
  # @override
205
208
  def explain(arel, binds = [])
@@ -237,6 +237,9 @@ module ArJdbc
237
237
  execute "DROP INDEX #{quote_column_name(index_name(table_name, options))}"
238
238
  end
239
239
 
240
+ # @override
241
+ def supports_views?; true end
242
+
240
243
  # @override
241
244
  def structure_dump
242
245
  execute('SCRIPT').map do |result|
@@ -281,6 +284,6 @@ module ActiveRecord::ConnectionAdapters
281
284
  class HsqldbAdapter < JdbcAdapter
282
285
  include ArJdbc::HSQLDB
283
286
  end
284
-
287
+
285
288
  end
286
289
 
@@ -1,4 +1,3 @@
1
- require 'set'
2
1
  require 'active_support/deprecation'
3
2
 
4
3
  module ArJdbc
@@ -9,18 +8,20 @@ module ArJdbc
9
8
  super(message) || true if warn?(message, once)
10
9
  end
11
10
 
12
- def deprecate(message, once = nil)
13
- ActiveSupport::Deprecation.warn(message, caller) || true if warn?(message, once)
11
+ def deprecate(message, once = nil) # adds a "DEPRECATION WARNING: " prefix
12
+ ::ActiveSupport::Deprecation.warn(message, caller) || true if warn?(message, once)
14
13
  end
15
14
 
16
15
  private
17
16
 
18
- @@warns = Set.new
17
+ @@warns = nil
18
+ @@warns = false if ENV_JAVA['arjdbc.warn'].eql? 'false'
19
19
 
20
20
  def warn?(message, once)
21
- return nil unless message
22
- return false if @@warns.include?(message)
23
- @@warns << message.dup if once
21
+ return nil if @@warns.equal?(false) || ! message
22
+ warns = @@warns ||= ( require 'set'; Set.new )
23
+ return false if warns.include?(message)
24
+ warns << message.dup if once
24
25
  true
25
26
  end
26
27
 
@@ -28,7 +29,7 @@ module ArJdbc
28
29
 
29
30
  require 'arjdbc/jdbc/adapter'
30
31
 
31
- if Java::JavaLang::Boolean.getBoolean('arjdbc.extensions.discover')
32
+ if ENV_JAVA['arjdbc.extensions.discover'].eql? 'true'
32
33
  self.discover_extensions
33
34
  else
34
35
  require 'arjdbc/discover'
@@ -106,9 +106,14 @@ module ActiveRecord
106
106
  java_connection = raw_connection.connection
107
107
  return java_connection unless unwrap
108
108
  connection_class = java.sql.Connection.java_class
109
- if java_connection.wrapper_for?(connection_class)
110
- java_connection.unwrap(connection_class) # java.sql.Wrapper.unwrap
111
- elsif java_connection.respond_to?(:connection)
109
+ begin
110
+ if java_connection.wrapper_for?(connection_class)
111
+ return java_connection.unwrap(connection_class) # java.sql.Wrapper.unwrap
112
+ end
113
+ rescue Java::JavaLang::AbstractMethodError => e
114
+ ArJdbc.warn("driver/pool connection impl does not support unwrapping (#{e})")
115
+ end
116
+ if java_connection.respond_to?(:connection)
112
117
  # e.g. org.apache.tomcat.jdbc.pool.PooledConnection
113
118
  java_connection.connection # getConnection
114
119
  else
@@ -413,6 +418,11 @@ module ActiveRecord
413
418
  end
414
419
  end
415
420
 
421
+ # @override
422
+ def supports_views?
423
+ @connection.supports_views?
424
+ end
425
+
416
426
  # Executes a SQL query in the context of this connection using the bind
417
427
  # substitutes.
418
428
  # @param sql the query string (or AREL object)
@@ -680,17 +690,6 @@ module ActiveRecord
680
690
  end
681
691
  end unless defined? ActiveRecord::Result
682
692
 
683
- # Helper to easily override #table_definition (on AR 3.x/4.0) as :
684
- # ```
685
- # def table_definition(*args)
686
- # new_table_definition(TableDefinition, *args)
687
- # end
688
- # ```
689
- def new_table_definition(table_definition, *args)
690
- table_definition.new(self) # args ignored only used for 4.0
691
- end
692
- private :new_table_definition
693
-
694
693
  # NOTE: make sure if adapter overrides #table_definition that it will
695
694
  # work on AR 3.x as well as 4.0
696
695
  if ActiveRecord::VERSION::MAJOR > 3
@@ -708,12 +707,19 @@ module ActiveRecord
708
707
  end
709
708
 
710
709
  # @note AR-4x arguments expected: `(name, temporary, options)`
711
- # @private documented above
710
+ # @private documented bellow
712
711
  def new_table_definition(table_definition, *args)
713
712
  table_definition.new native_database_types, *args
714
713
  end
715
714
  private :new_table_definition
716
715
 
716
+ # @private
717
+ def new_index_definition(table, name, unique, columns, lengths,
718
+ orders = nil, where = nil, type = nil, using = nil)
719
+ IndexDefinition.new(table, name, unique, columns, lengths, orders, where, type, using)
720
+ end
721
+ private :new_index_definition
722
+
717
723
  #
718
724
 
719
725
  # Provides backwards-compatibility on ActiveRecord 4.1 for DB adapters
@@ -728,6 +734,31 @@ module ActiveRecord
728
734
  end
729
735
  public :add_column_options!
730
736
 
737
+ else # AR < 4.0
738
+
739
+ # Helper to easily override #table_definition (on AR 3.x/4.0) as :
740
+ # ```
741
+ # def table_definition(*args)
742
+ # new_table_definition(TableDefinition, *args)
743
+ # end
744
+ # ```
745
+ def new_table_definition(table_definition, *args)
746
+ table_definition.new(self) # args ignored only used for 4.0
747
+ end
748
+ private :new_table_definition
749
+
750
+ # @private (:table, :name, :unique, :columns, :lengths, :orders)
751
+ def new_index_definition(table, name, unique, columns, lengths,
752
+ orders = nil, where = nil, type = nil, using = nil)
753
+ IndexDefinition.new(table, name, unique, columns, lengths, orders)
754
+ end
755
+ # @private (:table, :name, :unique, :columns, :lengths)
756
+ def new_index_definition(table, name, unique, columns, lengths,
757
+ orders = nil, where = nil, type = nil, using = nil)
758
+ IndexDefinition.new(table, name, unique, columns, lengths)
759
+ end if ActiveRecord::VERSION::STRING < '3.2'
760
+ private :new_index_definition
761
+
731
762
  end
732
763
 
733
764
  # @return whether `:prepared_statements` are to be used
@@ -61,9 +61,7 @@ module ArJdbc
61
61
  end
62
62
 
63
63
  # @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_column_class
64
- def jdbc_column_class
65
- ::ActiveRecord::ConnectionAdapters::MSSQLColumn
66
- end
64
+ def jdbc_column_class; Column end
67
65
 
68
66
  # @see ActiveRecord::ConnectionAdapters::Jdbc::ArelSupport
69
67
  def self.arel_visitor_type(config)
@@ -255,9 +253,11 @@ module ArJdbc
255
253
  end.join(",")
256
254
  end
257
255
 
258
- def supports_ddl_transactions?
259
- true
260
- end
256
+ # @override
257
+ def supports_ddl_transactions?; true end
258
+
259
+ # @override
260
+ def supports_views?; true end
261
261
 
262
262
  def tables(schema = current_schema)
263
263
  @connection.tables(nil, schema)
@@ -738,3 +738,9 @@ module ActiveRecord::ConnectionAdapters
738
738
  end
739
739
 
740
740
  end
741
+
742
+ module ArJdbc
743
+ module MSSQL
744
+ Column = ::ActiveRecord::ConnectionAdapters::MSSQLColumn
745
+ end
746
+ end
@@ -2,13 +2,18 @@ ArJdbc.load_java_part :MySQL
2
2
 
3
3
  require 'bigdecimal'
4
4
  require 'active_record/connection_adapters/abstract/schema_definitions'
5
- require 'arjdbc/mysql/column'
6
- require 'arjdbc/mysql/bulk_change_table'
7
- require 'arjdbc/mysql/explain_support'
8
- require 'arjdbc/mysql/schema_creation' # AR 4.x
9
5
 
10
6
  module ArJdbc
11
7
  module MySQL
8
+
9
+ # @private
10
+ AR42 = ActiveRecord::VERSION::STRING >= '4.2'
11
+
12
+ require 'arjdbc/mysql/column'
13
+ require 'arjdbc/mysql/bulk_change_table'
14
+ require 'arjdbc/mysql/explain_support'
15
+ require 'arjdbc/mysql/schema_creation' # AR 4.x
16
+
12
17
  include BulkChangeTable if const_defined? :BulkChangeTable
13
18
 
14
19
  # @see ActiveRecord::ConnectionAdapters::JdbcAdapter#jdbc_connection_class
@@ -142,10 +147,40 @@ module ArJdbc
142
147
  Arel::Nodes::Bin.new(node)
143
148
  end
144
149
 
150
+ def case_sensitive_modifier(node, table_attribute)
151
+ node = Arel::Nodes.build_quoted node, table_attribute
152
+ Arel::Nodes::Bin.new(node)
153
+ end if AR42
154
+
145
155
  def limited_update_conditions(where_sql, quoted_table_name, quoted_primary_key)
146
156
  where_sql
147
157
  end
148
158
 
159
+ def initialize_schema_migrations_table
160
+ if @config[:encoding] == 'utf8mb4'
161
+ ActiveRecord::SchemaMigration.create_table(191)
162
+ else
163
+ ActiveRecord::SchemaMigration.create_table
164
+ end
165
+ end if ::ActiveRecord::VERSION::MAJOR > 3
166
+
167
+ # HELPER METHODS ===========================================
168
+
169
+ # @private Only for Rails core compatibility.
170
+ def new_column(field, default, type, null, collation, extra = "")
171
+ Column.new(field, default, type, null, collation, strict_mode?, extra)
172
+ end unless AR42
173
+
174
+ # @private Only for Rails core compatibility.
175
+ def new_column(field, default, cast_type, sql_type = nil, null = true, collation = "", extra = "")
176
+ Column.new(field, default, cast_type, sql_type, null, collation, strict_mode?, extra)
177
+ end if AR42
178
+
179
+ # @private Only for Rails core compatibility.
180
+ def error_number(exception)
181
+ exception.error_code if exception.respond_to?(:error_code)
182
+ end
183
+
149
184
  # QUOTING ==================================================
150
185
 
151
186
  # @override
@@ -203,9 +238,14 @@ module ArJdbc
203
238
  version[0] && version[0] >= 5
204
239
  end
205
240
 
241
+ def supports_rename_index?
242
+ return false if mariadb? || ! version[0]
243
+ (version[0] == 5 && version[1] >= 7) || version[0] >= 6
244
+ end
245
+
206
246
  # @override
207
247
  def supports_transaction_isolation?(level = nil)
208
- version[0] >= 5 # MySQL 5+
248
+ version[0] && version[0] >= 5 # MySQL 5+
209
249
  end
210
250
 
211
251
  # NOTE: handled by JdbcAdapter we override only to have save-point in logs :
@@ -332,16 +372,15 @@ module ArJdbc
332
372
  sql = "SHOW FULL COLUMNS FROM #{quote_table_name(table_name)}"
333
373
  columns = execute(sql, name || 'SCHEMA')
334
374
  strict = strict_mode?
335
- column = ::ActiveRecord::ConnectionAdapters::MysqlAdapter::Column
336
375
  pass_cast_type = respond_to?(:lookup_cast_type)
337
376
  columns.map! do |field|
338
377
  sql_type = field['Type']
339
378
  null = field['Null'] == "YES"
340
379
  if pass_cast_type
341
380
  cast_type = lookup_cast_type(sql_type)
342
- column.new(field['Field'], field['Default'], cast_type, sql_type, null, field['Collation'], strict, field['Extra'])
381
+ Column.new(field['Field'], field['Default'], cast_type, sql_type, null, field['Collation'], strict, field['Extra'])
343
382
  else
344
- column.new(field['Field'], field['Default'], sql_type, null, field['Collation'], strict, field['Extra'])
383
+ Column.new(field['Field'], field['Default'], sql_type, null, field['Collation'], strict, field['Extra'])
345
384
  end
346
385
  end
347
386
  columns
@@ -377,6 +416,10 @@ module ArJdbc
377
416
  super(name, {:options => "ENGINE=InnoDB DEFAULT CHARSET=utf8"}.merge(options))
378
417
  end
379
418
 
419
+ def drop_table(table_name, options = {})
420
+ execute "DROP#{' TEMPORARY' if options[:temporary]} TABLE #{quote_table_name(table_name)}"
421
+ end
422
+
380
423
  # @override
381
424
  def rename_table(table_name, new_name)
382
425
  execute "RENAME TABLE #{quote_table_name(table_name)} TO #{quote_table_name(new_name)}"
@@ -389,6 +432,15 @@ module ArJdbc
389
432
  execute "DROP INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)}"
390
433
  end
391
434
 
435
+ # @override
436
+ def rename_index(table_name, old_name, new_name)
437
+ if supports_rename_index?
438
+ execute "ALTER TABLE #{quote_table_name(table_name)} RENAME INDEX #{quote_table_name(old_name)} TO #{quote_table_name(new_name)}"
439
+ else
440
+ super
441
+ end
442
+ end
443
+
392
444
  # @override
393
445
  def add_column(table_name, column_name, type, options = {})
394
446
  add_column_sql = "ALTER TABLE #{quote_table_name(table_name)} ADD #{quote_column_name(column_name)} #{type_to_sql(type, options[:limit], options[:precision], options[:scale])}"
@@ -582,6 +634,8 @@ module ArJdbc
582
634
  column
583
635
  end
584
636
 
637
+ def mariadb?; !! ( full_version =~ /mariadb/i ) end
638
+
585
639
  def version
586
640
  return @version ||= begin
587
641
  version = []
@@ -591,9 +645,7 @@ module ArJdbc
591
645
  version << jdbc_connection.serverMinorVersion
592
646
  version << jdbc_connection.serverSubMinorVersion
593
647
  else
594
- result = execute 'SELECT VERSION()', 'SCHEMA'
595
- result = result.first.values.first # [{"VERSION()"=>"5.5.37-0ubuntu..."}]
596
- if match = result.match(/^(\d)\.(\d+)\.(\d+)/)
648
+ if match = full_version.match(/^(\d)\.(\d+)\.(\d+)/)
597
649
  version << match[1].to_i
598
650
  version << match[2].to_i
599
651
  version << match[3].to_i
@@ -603,6 +655,13 @@ module ArJdbc
603
655
  end
604
656
  end
605
657
 
658
+ def full_version
659
+ @full_version ||= begin
660
+ result = execute 'SELECT VERSION()', 'SCHEMA'
661
+ result.first.values.first # [{"VERSION()"=>"5.5.37-0ubuntu..."}]
662
+ end
663
+ end
664
+
606
665
  end
607
666
  end
608
667
 
@@ -628,7 +687,7 @@ module ActiveRecord
628
687
  include ::ArJdbc::MySQL::Column
629
688
 
630
689
  def initialize(name, default, sql_type = nil, null = true, collation = nil, strict = false, extra = '')
631
- if Hash === name
690
+ if name.is_a?(Hash)
632
691
  super # first arg: config
633
692
  else
634
693
  @strict = strict; @collation = collation; @extra = extra
@@ -638,7 +697,7 @@ module ActiveRecord
638
697
  end
639
698
 
640
699
  def initialize(name, default, cast_type, sql_type = nil, null = true, collation = nil, strict = false, extra = '')
641
- if Hash === name
700
+ if name.is_a?(Hash)
642
701
  super # first arg: config
643
702
  else
644
703
  @strict = strict; @collation = collation; @extra = extra
@@ -686,3 +745,9 @@ module ActiveRecord
686
745
 
687
746
  end
688
747
  end
748
+
749
+ module ArJdbc
750
+ module MySQL
751
+ Column = ::ActiveRecord::ConnectionAdapters::MysqlAdapter::Column
752
+ end
753
+ end