@@ -27,6 +27,8 @@ def mysql_connection(config)
2727 config [ :url ] = url
2828 end
2929
30+ mariadb_driver = ! mysql_driver && driver [ 0 , 12 ] == 'org.mariadb.' # org.mariadb.jdbc.Driver
31+
3032 properties = ( config [ :properties ] ||= { } )
3133 if mysql_driver
3234 properties [ 'zeroDateTimeBehavior' ] ||= 'convertToNull'
@@ -42,22 +44,48 @@ def mysql_connection(config)
4244 end
4345 end
4446 if config [ :sslkey ] || sslcert = config [ :sslcert ] # || config[:use_ssl]
45- properties [ 'useSSL' ] ||= true
46- properties [ 'requireSSL' ] ||= true if mysql_driver
47- properties [ 'clientCertificateKeyStoreUrl' ] ||= begin
48- java . io . File . new ( sslcert ) . to_url . to_s
49- end if sslcert && mysql_driver
50- if sslca = config [ :sslca ] && mysql_driver
51- properties [ 'trustCertificateKeyStoreUrl' ] ||= begin
52- java . io . File . new ( sslca ) . to_url . to_s
47+ properties [ 'useSSL' ] ||= true # supported by MariaDB as well
48+ if mysql_driver
49+ properties [ 'requireSSL' ] ||= true if mysql_driver
50+ properties [ 'clientCertificateKeyStoreUrl' ] ||= begin
51+ java . io . File . new ( sslcert ) . to_url . to_s
52+ end if sslcert
53+ if sslca = config [ :sslca ]
54+ properties [ 'trustCertificateKeyStoreUrl' ] ||= begin
55+ java . io . File . new ( sslca ) . to_url . to_s
56+ end
57+ else
58+ properties [ 'verifyServerCertificate' ] ||= false if mysql_driver
5359 end
54- else
55- properties [ 'verifyServerCertificate' ] ||= false if mysql_driver
60+ end
61+ if mariadb_driver
62+ properties [ 'verifyServerCertificate' ] ||= false
5663 end
5764 end
65+ if socket = config [ :socket ]
66+ properties [ 'localSocket' ] ||= socket if mariadb_driver
67+ end
5868
5969 jdbc_connection ( config )
6070 end
6171 alias_method :jdbcmysql_connection , :mysql_connection
6272 alias_method :mysql2_connection , :mysql_connection
73+
74+ def mariadb_connection ( config )
75+ config [ :adapter_spec ] ||= ::ArJdbc ::MySQL
76+ config [ :adapter_class ] = ActiveRecord ::ConnectionAdapters ::MysqlAdapter unless config . key? ( :adapter_class )
77+
78+ return jndi_connection ( config ) if jndi_config? ( config )
79+
80+ begin
81+ require 'jdbc/mariadb'
82+ ::Jdbc ::MariaDB . load_driver ( :require ) if defined? ( ::Jdbc ::MariaDB . load_driver )
83+ rescue LoadError # assuming driver.jar is on the class-path
84+ end
85+
86+ config [ :driver ] ||= 'org.mariadb.jdbc.Driver'
87+
88+ mysql_connection ( config )
89+ end
90+ alias_method :jdbcmariadb_connection , :mariadb_connection
6391end
0 commit comments