Skip to content

Commit

Permalink
finish updating (explicitly loaded) driver-jars
Browse files Browse the repository at this point in the history
besides we make sure that (jdbc-xxx gem) .jars are only loaded (required) when first connection is attempted this avoids e.g. sqlite-jdbc.jar being always among loaded features when discover AR-JDBC extensions run
  • Loading branch information
kares committed Dec 14, 2012
1 parent c192cb5 commit f15684f
Show file tree
Hide file tree
Showing 22 changed files with 55 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require 'arjdbc/derby'
Jdbc::Derby.load_driver(:require)
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require 'arjdbc/h2'
Jdbc::H2.load_driver(:require)
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require 'arjdbc/hsqldb'
Jdbc::HSQLDB.load_driver(:require)
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
require 'arjdbc/mssql'
# NOTE: the adapter has only support for working with the
# open-source jTDS driver (won't work with MS's driver) !
Jdbc::JTDS.load_driver(:require)
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require 'arjdbc/mysql'
Jdbc::MySQL.load_driver(:require)
4 changes: 2 additions & 2 deletions jdbc-derby/lib/jdbc/derby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Derby
VERSION = "10.6.2.1"

def self.driver_jar
"derby-#{Jdbc::Derby::VERSION}.jar"
"derby-#{VERSION}.jar"
end

def self.load_driver(method = :load)
Expand All @@ -13,5 +13,5 @@ def self.load_driver(method = :load)
end

if $VERBOSE && (JRUBY_VERSION.nil? rescue true)
warn "jdbc-derby is only for use with JRuby"
warn "Jdbc-Derby is only for use with JRuby"
end
4 changes: 2 additions & 2 deletions jdbc-h2/lib/jdbc/h2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module H2
VERSION = "1.3.168"

def self.driver_jar
"h2-#{Jdbc::H2::VERSION}.jar"
"h2-#{VERSION}.jar"
end

def self.load_driver(method = :load)
Expand All @@ -13,5 +13,5 @@ def self.load_driver(method = :load)
end

if $VERBOSE && (JRUBY_VERSION.nil? rescue true)
warn "jdbc-h2 is only for use with JRuby"
warn "Jdbc-H2 is only for use with JRuby"
end
15 changes: 11 additions & 4 deletions jdbc-hsqldb/lib/jdbc/hsqldb.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
module Jdbc
module HSQLDB
VERSION = "2.2.9"

def self.driver_jar
"hsqldb-#{VERSION}.jar"
end

def self.load_driver(method = :load)
send method, driver_jar
end
end
end
if RUBY_PLATFORM =~ /java/
require "hsqldb-#{Jdbc::HSQLDB::VERSION}.jar"
elsif $VERBOSE
warn "jdbc-hsqldb is only for use with JRuby"

if $VERBOSE && (JRUBY_VERSION.nil? rescue true)
warn "Jdbc-HSQLDB is only for use with JRuby"
end
15 changes: 11 additions & 4 deletions jdbc-jtds/lib/jdbc/jtds.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
module Jdbc
module JTDS
VERSION = "1.3.0"

def self.driver_jar
"jtds-#{VERSION}.jar"
end

def self.load_driver(method = :load)
send method, driver_jar
end
end
end
if RUBY_PLATFORM =~ /java/
require "jtds-#{Jdbc::JTDS::VERSION}.jar"
elsif $VERBOSE
warn "jdbc-jtds is only for use with JRuby"

if $VERBOSE && (JRUBY_VERSION.nil? rescue true)
warn "Jdbc-JTDS is only for use with JRuby"
end
15 changes: 11 additions & 4 deletions jdbc-mysql/lib/jdbc/mysql.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
module Jdbc
module MySQL
VERSION = "5.1.22"

def self.driver_jar
"mysql-connector-java-#{VERSION}.jar"
end

def self.load_driver(method = :load)
send method, driver_jar
end
end
end
if RUBY_PLATFORM =~ /java/
require "mysql-connector-java-#{Jdbc::MySQL::VERSION}.jar"
elsif $VERBOSE
warn "jdbc-mysql is only for use with JRuby"

if $VERBOSE && (JRUBY_VERSION.nil? rescue true)
warn "Jdbc-MySQL is only for use with JRuby"
end
4 changes: 0 additions & 4 deletions lib/arjdbc/derby.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
require 'arjdbc/jdbc'
jdbc_require_driver 'jdbc/derby'
require 'arjdbc/derby/connection_methods'
require 'arjdbc/derby/adapter'



3 changes: 2 additions & 1 deletion lib/arjdbc/derby/connection_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module ActiveRecord
class Base
class << self
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[:adapter_spec] = ::ArJdbc::Derby
Expand All @@ -12,7 +14,6 @@ def derby_connection(config)
end
conn
end

alias_method :jdbcderby_connection, :derby_connection
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/arjdbc/h2.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'arjdbc/jdbc'
jdbc_require_driver 'jdbc/h2'
require 'arjdbc/h2/connection_methods'
require 'arjdbc/h2/adapter'
2 changes: 2 additions & 0 deletions lib/arjdbc/h2/connection_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module ActiveRecord
class Base
class << self
def h2_connection(config)
require 'active_record/connection_adapters/jdbch2_adapter'

config[:url] ||= "jdbc:h2:#{config[:database]}"
config[:driver] ||= "org.h2.Driver"
config[:adapter_spec] = ::ArJdbc::H2
Expand Down
1 change: 0 additions & 1 deletion lib/arjdbc/hsqldb.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'arjdbc/jdbc'
jdbc_require_driver 'jdbc/hsqldb'
require 'arjdbc/hsqldb/connection_methods'
require 'arjdbc/hsqldb/adapter'
4 changes: 2 additions & 2 deletions lib/arjdbc/hsqldb/connection_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ module ActiveRecord
class Base
class << self
def hsqldb_connection(config)
require "arjdbc/hsqldb"
require 'active_record/connection_adapters/jdbchsqldb_adapter'

config[:url] ||= "jdbc:hsqldb:#{config[:database]}"
config[:driver] ||= "org.hsqldb.jdbcDriver"
config[:adapter_spec] = ::ArJdbc::HSQLDB
embedded_driver(config)
end

alias_method :jdbchsqldb_connection, :hsqldb_connection
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/arjdbc/mssql.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'arjdbc/jdbc'
jdbc_require_driver 'jdbc/jtds', 'jdbc-mssql'
require 'arjdbc/mssql/connection_methods'
require 'arjdbc/mssql/adapter'
5 changes: 3 additions & 2 deletions lib/arjdbc/mssql/connection_methods.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class ActiveRecord::Base
class << self
def mssql_connection(config)
require "arjdbc/mssql"
require 'active_record/connection_adapters/jdbcmssql_adapter'

config[:host] ||= "localhost"
config[:port] ||= 1433
config[:driver] ||= "net.sourceforge.jtds.jdbc.Driver"
Expand All @@ -20,7 +21,7 @@ def mssql_connection(config)
url << ";appname=#{config[:appname]}" if config[:appname]
config[:url] ||= url

if !config[:domain]
unless config[:domain]
config[:username] ||= "sa"
config[:password] ||= ""
end
Expand Down
1 change: 0 additions & 1 deletion lib/arjdbc/mysql.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'arjdbc/jdbc'
jdbc_require_driver 'jdbc/mysql'
require 'arjdbc/mysql/connection_methods'
require 'arjdbc/mysql/adapter'
5 changes: 2 additions & 3 deletions lib/arjdbc/mysql/connection_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
class ActiveRecord::Base
class << self
def mysql_connection(config)
require "arjdbc/mysql"
require 'active_record/connection_adapters/jdbcmysql_adapter'

config[:port] ||= 3306
options = (config[:options] ||= {})
options['zeroDateTimeBehavior'] ||= 'convertToNull'
Expand All @@ -24,5 +25,3 @@ def mysql_connection(config)
alias_method :mysql2_connection, :mysql_connection
end
end


1 change: 0 additions & 1 deletion lib/arjdbc/postgresql.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'arjdbc/jdbc'
jdbc_require_driver 'jdbc/postgres'
require 'arjdbc/postgresql/connection_methods'
require 'arjdbc/postgresql/adapter'
1 change: 0 additions & 1 deletion lib/arjdbc/sqlite3.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'arjdbc/jdbc'
jdbc_require_driver 'jdbc/sqlite3'
require 'arjdbc/sqlite3/connection_methods'
require 'arjdbc/sqlite3/adapter'

0 comments on commit f15684f

Please sign in to comment.