Skip to content

Commit fd74fb4

Browse files
committed
[mysql] initial hacks to allow running with non-official JDBC driver
1 parent d3efc91 commit fd74fb4

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

lib/arjdbc/mysql/adapter.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ def self.jdbc_connection_class
1919
# @private
2020
def init_connection(jdbc_connection)
2121
meta = jdbc_connection.meta_data
22-
if meta.driver_major_version < 5
22+
if meta.driver_major_version == 1 # TODO check in driver code
23+
# assumes MariaDB 1.x currently
24+
elsif meta.driver_major_version < 5
2325
raise ::ActiveRecord::ConnectionNotEstablished,
2426
"MySQL adapter requires driver >= 5.0 got: '#{meta.driver_version}'"
2527
elsif meta.driver_major_version == 5 && meta.driver_minor_version < 1

lib/arjdbc/mysql/connection_methods.rb

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ def mysql_connection(config)
55

66
return jndi_connection(config) if jndi_config?(config)
77

8+
driver = config[:driver] ||=
9+
defined?(::Jdbc::MySQL.driver_name) ? ::Jdbc::MySQL.driver_name : 'com.mysql.jdbc.Driver'
10+
811
begin
912
require 'jdbc/mysql'
1013
::Jdbc::MySQL.load_driver(:require) if defined?(::Jdbc::MySQL.load_driver)
1114
rescue LoadError # assuming driver.jar is on the class-path
12-
end
15+
end if mysql_driver = driver[0, 10] == 'com.mysql.'
1316

1417
config[:username] = 'root' unless config.key?(:username)
1518
# jdbc:mysql://[host][,failoverhost...][:port]/[database]
@@ -23,32 +26,33 @@ def mysql_connection(config)
2326
url << "/#{config[:database]}"
2427
config[:url] = url
2528
end
26-
config[:driver] ||= defined?(::Jdbc::MySQL.driver_name) ? ::Jdbc::MySQL.driver_name : 'com.mysql.jdbc.Driver'
2729

2830
properties = ( config[:properties] ||= {} )
29-
properties['zeroDateTimeBehavior'] ||= 'convertToNull'
30-
properties['jdbcCompliantTruncation'] ||= 'false'
31-
properties['useUnicode'] = 'true' unless properties.key?('useUnicode') # otherwise platform default
32-
encoding = config.key?(:encoding) ? config[:encoding] : 'utf8'
33-
properties['characterEncoding'] = encoding if encoding
34-
if ! ( reconnect = config[:reconnect] ).nil?
35-
properties['autoReconnect'] ||= reconnect.to_s
36-
# properties['maxReconnects'] ||= '3'
37-
# with reconnect fail-over sets connection read-only (by default)
38-
# properties['failOverReadOnly'] ||= 'false'
31+
if mysql_driver
32+
properties['zeroDateTimeBehavior'] ||= 'convertToNull'
33+
properties['jdbcCompliantTruncation'] ||= 'false'
34+
properties['useUnicode'] = 'true' unless properties.key?('useUnicode') # otherwise platform default
35+
encoding = config.key?(:encoding) ? config[:encoding] : 'utf8'
36+
properties['characterEncoding'] = encoding if encoding
37+
if ! ( reconnect = config[:reconnect] ).nil?
38+
properties['autoReconnect'] ||= reconnect.to_s
39+
# properties['maxReconnects'] ||= '3'
40+
# with reconnect fail-over sets connection read-only (by default)
41+
# properties['failOverReadOnly'] ||= 'false'
42+
end
3943
end
4044
if config[:sslkey] || sslcert = config[:sslcert] # || config[:use_ssl]
4145
properties['useSSL'] ||= true
42-
properties['requireSSL'] ||= true
46+
properties['requireSSL'] ||= true if mysql_driver
4347
properties['clientCertificateKeyStoreUrl'] ||= begin
4448
java.io.File.new(sslcert).to_url.to_s
45-
end if sslcert
46-
if sslca = config[:sslca]
49+
end if sslcert && mysql_driver
50+
if sslca = config[:sslca] && mysql_driver
4751
properties['trustCertificateKeyStoreUrl'] ||= begin
4852
java.io.File.new(sslca).to_url.to_s
4953
end
5054
else
51-
properties['verifyServerCertificate'] ||= false
55+
properties['verifyServerCertificate'] ||= false if mysql_driver
5256
end
5357
end
5458

0 commit comments

Comments
 (0)