Skip to content

Commit 79b488a

Browse files
authored
Merge pull request #1026 from jruby/jdbc-mysql-8
[jdbc-mysql] upgrade to new major version 8.0
2 parents 96317ea + 601219d commit 79b488a

File tree

7 files changed

+28
-17
lines changed

7 files changed

+28
-17
lines changed

jdbc-mysql/lib/jdbc/mysql.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ module Jdbc
55
module MySQL
66

77
def self.driver_jar
8-
"mysql-connector-java-#{DRIVER_VERSION}-bin.jar"
8+
"mysql-connector-java-#{DRIVER_VERSION}.jar"
99
end
1010

1111
def self.load_driver(method = :load)
1212
send method, driver_jar
1313
end
1414

1515
def self.driver_name
16-
'com.mysql.jdbc.Driver'
16+
'com.mysql.cj.jdbc.Driver'
1717
end
1818

1919
if defined?(JRUBY_VERSION) && # enable backwards-compat behavior :

jdbc-mysql/lib/jdbc/mysql/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module Jdbc
22
module MySQL
3-
DRIVER_VERSION = '5.1.47'
3+
DRIVER_VERSION = '8.0.17'
44
VERSION = DRIVER_VERSION
55
end
66
end
Binary file not shown.
2.21 MB
Binary file not shown.

lib/arjdbc/mysql/connection_methods.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def mysql_connection(config)
6868
# with reconnect fail-over sets connection read-only (by default)
6969
# properties['failOverReadOnly'] ||= 'false'
7070
end
71+
properties['noDatetimeStringSync'] = true unless properties.key?('noDatetimeStringSync')
7172
end
7273
if config[:sslkey] || sslcert = config[:sslcert] # || config[:use_ssl]
7374
properties['useSSL'] ||= true # supported by MariaDB as well
@@ -90,11 +91,12 @@ def mysql_connection(config)
9091
properties['localSocket'] ||= socket if mariadb_driver
9192
end
9293

94+
# properties['useJDBCCompliantTimezoneShift'] ||= true
9395
# for the Connector/J 5.1 line this is true by default - but it requires some really nasty
9496
# quirks to get casted Time values extracted properly according for AR's default_timezone
9597
# - thus we're turning it off (should be off in newer driver versions >= 6 anyway)
9698
# + also MariaDB driver is compilant and we would need to branch out based on driver
97-
properties['useLegacyDatetimeCode'] = false
99+
properties['useLegacyDatetimeCode'] = false # disables the effect of 'useTimezone'
98100

99101
jdbc_connection(config)
100102
end

test/db/jndi_mysql_config.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'db/jndi_base'
22

3-
JNDI_MYSQL_CONFIG = { :adapter => 'mysql', :jndi => 'jdbc/MyDB' }
3+
JNDI_MYSQL_CONFIG = { :adapter => 'mysql2', :jndi => 'jdbc/MyDB' }
44

55
unless ( ps = ENV['PREPARED_STATEMENTS'] || ENV['PS'] ).nil?
66
JNDI_MYSQL_CONFIG[:prepared_statements] = ps
@@ -11,7 +11,15 @@
1111

1212
require 'db/mysql_config'
1313

14-
data_source = com.mysql.jdbc.jdbc2.optional.MysqlDataSource.new
14+
old_driver = nil
15+
begin
16+
data_source = com.mysql.cj.jdbc.MysqlDataSource
17+
rescue NameError
18+
data_source = com.mysql.jdbc.jdbc2.optional.MysqlDataSource
19+
old_driver = true
20+
end
21+
22+
data_source = data_source.new
1523
data_source.database_name = MYSQL_CONFIG[:database]
1624
data_source.url = MYSQL_CONFIG[:url] if MYSQL_CONFIG[:url]
1725
data_source.server_name = MYSQL_CONFIG[:host] if MYSQL_CONFIG[:host]
@@ -20,10 +28,10 @@
2028
data_source.password = MYSQL_CONFIG[:password] if MYSQL_CONFIG[:password]
2129

2230
# must set these to match non-jndi setup
23-
data_source.cache_default_timezone = false
31+
data_source.cache_default_timezone = false if data_source.respond_to?(:cache_default_timezone)
2432
data_source.server_timezone = java.util.TimeZone.getDefault.getID
25-
data_source.use_legacy_datetime_code = false
26-
data_source.zero_date_time_behavior = 'convertToNull'
33+
data_source.use_legacy_datetime_code = false if data_source.respond_to?(:use_legacy_datetime_code)
34+
data_source.zero_date_time_behavior = old_driver ? 'convertToNull' : 'CONVERT_TO_NULL'
2735
data_source.jdbc_compliant_truncation = false
2836

2937
javax.naming.InitialContext.new.bind JNDI_MYSQL_CONFIG[:jndi], data_source

test/db/mysql/unit_test.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,16 @@ def initialize; end
148148
assert_equal false, config[:properties]['useSSL']
149149
end
150150

151-
def load_jdbc_mysql
152-
require 'jdbc/mysql'
153-
rescue LoadError
154-
return nil
155-
end
156-
157151
end
158152

159153
context 'connection (Jdbc::MySQL missing)' do
160154

161155
module ::Jdbc; end
162156

163-
@@jdbc_mysql = ::Jdbc::MySQL rescue nil
164-
157+
@@jdbc_mysql = false
165158
def setup
159+
load_jdbc_mysql
160+
@@jdbc_mysql = ::Jdbc::MySQL rescue nil
166161
::Jdbc.send :remove_const, :MySQL if @@jdbc_mysql
167162
end
168163

@@ -224,4 +219,10 @@ def teardown
224219

225220
end
226221

222+
def load_jdbc_mysql
223+
require 'jdbc/mysql'
224+
rescue LoadError
225+
return nil
226+
end
227+
227228
end if defined? JRUBY_VERSION

0 commit comments

Comments
 (0)