Class: ActiveRecord::ConnectionAdapters::JdbcDriver

Inherits:
Object
  • Object
show all
Defined in:
lib/arjdbc/jdbc/driver.rb

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ JdbcDriver

Returns a new instance of JdbcDriver.



4
5
6
# File 'lib/arjdbc/jdbc/driver.rb', line 4

def initialize(name)
  @name = name
end

Instance Method Details

#connection(url, user, pass) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/arjdbc/jdbc/driver.rb', line 29

def connection(url, user, pass)
  Jdbc::DriverManager.getConnection(url, user, pass)
rescue
  # bypass DriverManager to get around problem with dynamically loaded jdbc drivers
  props = java.util.Properties.new
  props.setProperty("user", user)
  props.setProperty("password", pass)
  create.connect(url, props)
end

#createObject



39
40
41
# File 'lib/arjdbc/jdbc/driver.rb', line 39

def create
  driver_class.new
end

#driver_classObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/arjdbc/jdbc/driver.rb', line 8

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
          include_class(driver_class_name) { driver_class_const }
        end
      end
    end
    driver_class = Jdbc.const_get(driver_class_const)
    raise "You specify a driver for your JDBC connection" unless driver_class
    driver_class
  end
end

#loadObject



25
26
27
# File 'lib/arjdbc/jdbc/driver.rb', line 25

def load
  Jdbc::DriverManager.registerDriver(create)
end