From 3d61ee3091f610c89fd1a11c9d8ecd1f1f02ccf7 Mon Sep 17 00:00:00 2001 From: kares Date: Fri, 14 Dec 2012 13:35:21 +0100 Subject: [PATCH] JDBC driver names should be on one (re-usable) place --- jdbc-derby/lib/jdbc/derby.rb | 4 ++++ jdbc-h2/lib/jdbc/h2.rb | 4 ++++ jdbc-hsqldb/lib/jdbc/hsqldb.rb | 4 ++++ jdbc-jtds/lib/jdbc/jtds.rb | 4 ++++ jdbc-mysql/lib/jdbc/mysql.rb | 4 ++++ jdbc-postgres/lib/jdbc/postgres.rb | 4 ++++ jdbc-sqlite3/lib/jdbc/sqlite3.rb | 3 +++ lib/arjdbc/derby/connection_methods.rb | 2 +- lib/arjdbc/h2/connection_methods.rb | 2 +- lib/arjdbc/hsqldb/connection_methods.rb | 2 +- lib/arjdbc/mssql/connection_methods.rb | 25 ++++++++++----------- lib/arjdbc/mysql/connection_methods.rb | 2 +- lib/arjdbc/postgresql/connection_methods.rb | 2 +- lib/arjdbc/sqlite3/connection_methods.rb | 2 +- 14 files changed, 45 insertions(+), 19 deletions(-) diff --git a/jdbc-derby/lib/jdbc/derby.rb b/jdbc-derby/lib/jdbc/derby.rb index 66a272976..292e4674d 100644 --- a/jdbc-derby/lib/jdbc/derby.rb +++ b/jdbc-derby/lib/jdbc/derby.rb @@ -9,6 +9,10 @@ def self.driver_jar def self.load_driver(method = :load) send method, driver_jar end + + def self.driver_name + 'org.apache.derby.jdbc.EmbeddedDriver' + end end end diff --git a/jdbc-h2/lib/jdbc/h2.rb b/jdbc-h2/lib/jdbc/h2.rb index 5c5ce4617..951d6c72d 100644 --- a/jdbc-h2/lib/jdbc/h2.rb +++ b/jdbc-h2/lib/jdbc/h2.rb @@ -9,6 +9,10 @@ def self.driver_jar def self.load_driver(method = :load) send method, driver_jar end + + def self.driver_name + 'org.h2.Driver' + end end end diff --git a/jdbc-hsqldb/lib/jdbc/hsqldb.rb b/jdbc-hsqldb/lib/jdbc/hsqldb.rb index 1706544a7..df4617977 100644 --- a/jdbc-hsqldb/lib/jdbc/hsqldb.rb +++ b/jdbc-hsqldb/lib/jdbc/hsqldb.rb @@ -9,6 +9,10 @@ def self.driver_jar def self.load_driver(method = :load) send method, driver_jar end + + def self.driver_name + 'org.hsqldb.jdbcDriver' + end end end diff --git a/jdbc-jtds/lib/jdbc/jtds.rb b/jdbc-jtds/lib/jdbc/jtds.rb index 2c82e83ed..7fcddd102 100644 --- a/jdbc-jtds/lib/jdbc/jtds.rb +++ b/jdbc-jtds/lib/jdbc/jtds.rb @@ -9,6 +9,10 @@ def self.driver_jar def self.load_driver(method = :load) send method, driver_jar end + + def self.driver_name + 'net.sourceforge.jtds.jdbc.Driver' + end end end diff --git a/jdbc-mysql/lib/jdbc/mysql.rb b/jdbc-mysql/lib/jdbc/mysql.rb index eb0b54f26..112fe4f47 100644 --- a/jdbc-mysql/lib/jdbc/mysql.rb +++ b/jdbc-mysql/lib/jdbc/mysql.rb @@ -9,6 +9,10 @@ def self.driver_jar def self.load_driver(method = :load) send method, driver_jar end + + def self.driver_name + 'com.mysql.jdbc.Driver' + end end end diff --git a/jdbc-postgres/lib/jdbc/postgres.rb b/jdbc-postgres/lib/jdbc/postgres.rb index 6666668b3..8e6f8320c 100644 --- a/jdbc-postgres/lib/jdbc/postgres.rb +++ b/jdbc-postgres/lib/jdbc/postgres.rb @@ -12,6 +12,10 @@ def self.load_driver(method = :load) send method, driver_jar end + def self.driver_name + 'org.postgresql.Driver' + end + private # JDBC version 4 if Java >=1.6, else 3 diff --git a/jdbc-sqlite3/lib/jdbc/sqlite3.rb b/jdbc-sqlite3/lib/jdbc/sqlite3.rb index 1b3ae6ee0..bed75df9c 100644 --- a/jdbc-sqlite3/lib/jdbc/sqlite3.rb +++ b/jdbc-sqlite3/lib/jdbc/sqlite3.rb @@ -10,6 +10,9 @@ def self.load_driver(method = :load) send method, driver_jar end + def self.driver_name + 'org.sqlite.JDBC' + end end end diff --git a/lib/arjdbc/derby/connection_methods.rb b/lib/arjdbc/derby/connection_methods.rb index aa8a66db1..d409e53ee 100644 --- a/lib/arjdbc/derby/connection_methods.rb +++ b/lib/arjdbc/derby/connection_methods.rb @@ -5,7 +5,7 @@ def derby_connection(config) require 'active_record/connection_adapters/jdbcderby_adapter' config[:url] ||= "jdbc:derby:#{config[:database]};create=true" - config[:driver] ||= "org.apache.derby.jdbc.EmbeddedDriver" + config[:driver] ||= ::Jdbc::Derby.driver_name # org.apache.derby.jdbc.EmbeddedDriver config[:adapter_spec] = ::ArJdbc::Derby conn = embedded_driver(config) md = conn.jdbc_connection.meta_data diff --git a/lib/arjdbc/h2/connection_methods.rb b/lib/arjdbc/h2/connection_methods.rb index 439fe6277..aeba1cff2 100644 --- a/lib/arjdbc/h2/connection_methods.rb +++ b/lib/arjdbc/h2/connection_methods.rb @@ -5,7 +5,7 @@ def h2_connection(config) require 'active_record/connection_adapters/jdbch2_adapter' config[:url] ||= "jdbc:h2:#{config[:database]}" - config[:driver] ||= "org.h2.Driver" + config[:driver] ||= ::Jdbc::H2.driver_name # org.h2.Driver config[:adapter_spec] = ::ArJdbc::H2 embedded_driver(config) end diff --git a/lib/arjdbc/hsqldb/connection_methods.rb b/lib/arjdbc/hsqldb/connection_methods.rb index 1187cec93..ce92c7188 100644 --- a/lib/arjdbc/hsqldb/connection_methods.rb +++ b/lib/arjdbc/hsqldb/connection_methods.rb @@ -5,7 +5,7 @@ def hsqldb_connection(config) require 'active_record/connection_adapters/jdbchsqldb_adapter' config[:url] ||= "jdbc:hsqldb:#{config[:database]}" - config[:driver] ||= "org.hsqldb.jdbcDriver" + config[:driver] ||= ::Jdbc::HSQLDB.driver_name # org.hsqldb.jdbcDriver config[:adapter_spec] = ::ArJdbc::HSQLDB embedded_driver(config) end diff --git a/lib/arjdbc/mssql/connection_methods.rb b/lib/arjdbc/mssql/connection_methods.rb index 3168cab7a..c426cfb2e 100644 --- a/lib/arjdbc/mssql/connection_methods.rb +++ b/lib/arjdbc/mssql/connection_methods.rb @@ -5,21 +5,20 @@ def mssql_connection(config) config[:host] ||= "localhost" config[:port] ||= 1433 - config[:driver] ||= "net.sourceforge.jtds.jdbc.Driver" + config[:driver] ||= ::Jdbc::JTDS.driver_name # net.sourceforge.jtds.jdbc.Driver config[:adapter_spec] = ::ArJdbc::MsSQL - url = "jdbc:jtds:sqlserver://#{config[:host]}:#{config[:port]}/#{config[:database]}" - - # Instance is often a preferrable alternative to port when dynamic ports are used. - # If instance is specified then port is essentially ignored. - url << ";instance=#{config[:instance]}" if config[:instance] - - # This will enable windows domain-based authentication and will require the JTDS native libraries be available. - url << ";domain=#{config[:domain]}" if config[:domain] - - # AppName is shown in sql server as additional information against the connection. - url << ";appname=#{config[:appname]}" if config[:appname] - config[:url] ||= url + config[:url] ||= begin + url = "jdbc:jtds:sqlserver://#{config[:host]}:#{config[:port]}/#{config[:database]}" + # Instance is often a preferrable alternative to port when dynamic ports are used. + # If instance is specified then port is essentially ignored. + url << ";instance=#{config[:instance]}" if config[:instance] + # This will enable windows domain-based authentication and will require the JTDS native libraries be available. + url << ";domain=#{config[:domain]}" if config[:domain] + # AppName is shown in sql server as additional information against the connection. + url << ";appname=#{config[:appname]}" if config[:appname] + url + end unless config[:domain] config[:username] ||= "sa" diff --git a/lib/arjdbc/mysql/connection_methods.rb b/lib/arjdbc/mysql/connection_methods.rb index 99d0456db..5dc353ffc 100644 --- a/lib/arjdbc/mysql/connection_methods.rb +++ b/lib/arjdbc/mysql/connection_methods.rb @@ -14,7 +14,7 @@ def mysql_connection(config) options['useUnicode'] ||= 'true' options['characterEncoding'] = config[:encoding] || 'utf8' config[:url] ||= "jdbc:mysql://#{config[:host]}:#{config[:port]}/#{config[:database]}" - config[:driver] ||= "com.mysql.jdbc.Driver" + config[:driver] ||= ::Jdbc::MySQL.driver_name # com.mysql.jdbc.Driver config[:adapter_class] = ActiveRecord::ConnectionAdapters::MysqlAdapter config[:adapter_spec] = ::ArJdbc::MySQL connection = jdbc_connection(config) diff --git a/lib/arjdbc/postgresql/connection_methods.rb b/lib/arjdbc/postgresql/connection_methods.rb index fa786bbc7..3a8c9fe71 100644 --- a/lib/arjdbc/postgresql/connection_methods.rb +++ b/lib/arjdbc/postgresql/connection_methods.rb @@ -10,7 +10,7 @@ def postgresql_connection(config) config[:port] ||= 5432 config[:url] ||= "jdbc:postgresql://#{config[:host]}:#{config[:port]}/#{config[:database]}" config[:url] << config[:pg_params] if config[:pg_params] - config[:driver] ||= "org.postgresql.Driver" + config[:driver] ||= ::Jdbc::Postgres.driver_name # org.postgresql.Driver config[:adapter_class] = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter config[:adapter_spec] = ::ArJdbc::PostgreSQL conn = jdbc_connection(config) diff --git a/lib/arjdbc/sqlite3/connection_methods.rb b/lib/arjdbc/sqlite3/connection_methods.rb index fead884ee..87d3791ed 100644 --- a/lib/arjdbc/sqlite3/connection_methods.rb +++ b/lib/arjdbc/sqlite3/connection_methods.rb @@ -11,7 +11,7 @@ def sqlite3_connection(config) database = config[:database] database = '' if database == ':memory:' config[:url] ||= "jdbc:sqlite:#{database}" - config[:driver] ||= "org.sqlite.JDBC" + config[:driver] ||= ::Jdbc::SQLite3.driver_name # org.sqlite.JDBC config[:adapter_class] = ActiveRecord::ConnectionAdapters::SQLite3Adapter config[:adapter_spec] = ::ArJdbc::SQLite3 jdbc_connection(config)