Class: ActiveRecord::ConnectionAdapters::JdbcDriver
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::JdbcDriver
- Defined in:
- lib/arjdbc/jdbc/driver.rb
Instance Method Summary collapse
- #connection(url, user, pass) ⇒ Object
- #driver_class ⇒ Object
-
#initialize(name) ⇒ JdbcDriver
constructor
A new instance of JdbcDriver.
Constructor Details
#initialize(name) ⇒ JdbcDriver
Returns a new instance of JdbcDriver.
4 5 6 7 |
# File 'lib/arjdbc/jdbc/driver.rb', line 4 def initialize(name) @name = name @driver = driver_class.new end |
Instance Method Details
#connection(url, user, pass) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/arjdbc/jdbc/driver.rb', line 26 def connection(url, user, pass) # bypass DriverManager to get around problem with dynamically loaded jdbc drivers props = java.util.Properties.new props.setProperty("user", user) props.setProperty("password", pass) @driver.connect(url, props) end |
#driver_class ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/arjdbc/jdbc/driver.rb', line 9 def driver_class @driver_class ||= begin driver_class_const = (@name[0...1].capitalize + @name[1..@name.length]).gsub(/\./, '_') Jdbc::Mutex.synchronized do unless Jdbc.const_defined?(driver_class_const) driver_class_name = @name Jdbc.module_eval do java_import(driver_class_name) { driver_class_const } end end end driver_class = Jdbc.const_get(driver_class_const) raise "You must specify a driver for your JDBC connection" unless driver_class driver_class end end |