Sha256: 92b9dd588eb0aa3ecf1beb34ed4cfb11fda1fb6ae1f5d6388262be568ee50035

Contents?: true

Size: 1.57 KB

Versions: 22

Compression:

Stored size: 1.57 KB

Contents

module ActiveRecord
  module ConnectionAdapters
    class JdbcDriver
      attr_reader :name, :properties

      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.to_s] = val.to_s } if properties
        end
      end

      def driver_class
        @driver_class ||= begin
          driver_class_const = (@name[0...1].capitalize + @name[1..@name.length]).gsub(/\./, '_')
          Jdbc::DriverManager.java_class.synchronized do # avoid 2 threads here
            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

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

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
activerecord-jdbc-adapter-1.3.25 lib/arjdbc/jdbc/driver.rb
activerecord-jdbc-adapter-51.0 lib/arjdbc/jdbc/driver.rb
activerecord-jdbc-adapter-1.3.24 lib/arjdbc/jdbc/driver.rb
neo-activerecord-jdbc-adapter-5.0.pre2 lib/arjdbc/jdbc/driver.rb
activerecord-jdbc-adapter-1.3.23 lib/arjdbc/jdbc/driver.rb
activerecord-jdbc-adapter-1.3.22 lib/arjdbc/jdbc/driver.rb
activerecord-jdbc-adapter-5.0.pre1 lib/arjdbc/jdbc/driver.rb
activerecord-jdbc-adapter-1.3.21 lib/arjdbc/jdbc/driver.rb
activerecord-jdbc-adapter-1.3.20 lib/arjdbc/jdbc/driver.rb
activerecord-jdbc-adapter-1.3.19 lib/arjdbc/jdbc/driver.rb
activerecord-jdbc-adapter-1.3.18 lib/arjdbc/jdbc/driver.rb
activerecord-jdbc-adapter-1.3.17 lib/arjdbc/jdbc/driver.rb
activerecord-jdbc-adapter-1.3.16 lib/arjdbc/jdbc/driver.rb
activerecord-jdbc-adapter-1.3.15 lib/arjdbc/jdbc/driver.rb
activerecord-jdbc-adapter-1.3.14 lib/arjdbc/jdbc/driver.rb
activerecord-jdbc-adapter-1.3.13 lib/arjdbc/jdbc/driver.rb
activerecord-jdbc-adapter-1.3.12 lib/arjdbc/jdbc/driver.rb
activerecord-jdbc-adapter-1.3.11 lib/arjdbc/jdbc/driver.rb
activerecord-jdbc-adapter-1.3.10 lib/arjdbc/jdbc/driver.rb
activerecord-jdbc-adapter-1.3.9 lib/arjdbc/jdbc/driver.rb