Class: ActiveRecord::ConnectionAdapters::JdbcDriver

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, properties = {}) ⇒ JdbcDriver

Returns a new instance of JdbcDriver.



6
7
8
9
10
11
12
13
14
15
# File 'lib/arjdbc/jdbc/driver.rb', line 6

def initialize(name, properties = {})
  @name = name
  @driver = driver_class.new
  if properties.is_a?(Java::JavaUtil::Properties)
    @properties = properties # allow programmatically set properties
  else
    @properties = Java::JavaUtil::Properties.new
    properties.each { |key, val| @properties[key] = val.to_s } if properties
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#propertiesObject (readonly)

Returns the value of attribute properties.



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

def properties
  @properties
end

Instance Method Details

#connection(url, user, pass) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/arjdbc/jdbc/driver.rb', line 34

def connection(url, user, pass)
  # bypass DriverManager to get around problem with dynamically loaded jdbc drivers
  properties = self.properties.clone
  properties.setProperty("user", user) if user
  properties.setProperty("password", pass) if pass
  @driver.connect(url, properties)
end

#driver_classObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/arjdbc/jdbc/driver.rb', line 17

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 unless Jdbc.const_defined?(driver_class_const)
    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