module Sequel::JDBC

Houses Sequel's JDBC support when running on JRuby.

Constants

DATABASE_SETUP

Contains procs keyed on subadapter type that extend the given database object so it supports the correct database type.

DECIMAL_TYPE_RE

The types to check for 0 scale to transform :decimal types to :integer.

JNDI_URI_REGEXP

Used to identify a jndi connection and to extract the jndi resource name.

Public Class Methods

load_driver(drv, gem=nil) click to toggle source

Attempt to load the JDBC driver class, which should be specified as a string containing the driver class name (which JRuby should autoload). Note that the string is evaled, so this method is not safe to call with untrusted input. Raise a Sequel::AdapterNotFound if evaluating the class name raises a NameError.

# File lib/sequel/adapters/jdbc.rb, line 55
def self.load_driver(drv, gem=nil)
  load_gem(gem) if gem
  eval drv
rescue NameError
  raise Sequel::AdapterNotFound, "#{drv} not loaded#{", try installing jdbc-#{gem.to_s.downcase} gem" if gem}"
end
load_gem(name) click to toggle source

Allow loading the necessary JDBC support via a gem.

# File lib/sequel/adapters/jdbc.rb, line 37
def self.load_gem(name)
  begin
    require "jdbc/#{name.to_s.downcase}"
  rescue LoadError
    # jdbc gem not used, hopefully the user has the .jar in their CLASSPATH
  else
    if defined?(::Jdbc) && ( ::Jdbc.const_defined?(name) rescue nil )
      jdbc_module = ::Jdbc.const_get(name) # e.g. Jdbc::SQLite3
      jdbc_module.load_driver if jdbc_module.respond_to?(:load_driver)
    end
  end
end