]> source.dussan.org Git - sonarqube.git/blob
fb8665271b7e0d97a18ee9086de44e53c19dfa78
[sonarqube.git] /
1 module ActiveRecord
2   module ConnectionAdapters
3     class JdbcDriver
4       def initialize(name)
5         @name = name
6         @driver = driver_class.new
7       end
8
9       def driver_class
10         @driver_class ||= begin
11           driver_class_const = (@name[0...1].capitalize + @name[1..@name.length]).gsub(/\./, '_')
12           Jdbc::Mutex.synchronized do
13             unless Jdbc.const_defined?(driver_class_const)
14               driver_class_name = @name
15               Jdbc.module_eval do
16                 java_import(driver_class_name) { driver_class_const }
17               end
18             end
19           end
20           driver_class = Jdbc.const_get(driver_class_const)
21           raise "You must specify a driver for your JDBC connection" unless driver_class
22           driver_class
23         end
24       end
25
26       def connection(url, user, pass)
27         # bypass DriverManager to get around problem with dynamically loaded jdbc drivers
28         props = java.util.Properties.new
29         props.setProperty("user", user)
30         props.setProperty("password", pass)
31         @driver.connect(url, props)
32       end
33     end
34   end
35 end