Module: Sequel::JDBC

Defined in:
lib/sequel/adapters/jdbc.rb,
lib/sequel/adapters/jdbc/h2.rb,
lib/sequel/adapters/jdbc/db2.rb,
lib/sequel/adapters/jdbc/jtds.rb,
lib/sequel/adapters/jdbc/derby.rb,
lib/sequel/adapters/jdbc/mssql.rb,
lib/sequel/adapters/jdbc/mysql.rb,
lib/sequel/adapters/jdbc/hsqldb.rb,
lib/sequel/adapters/jdbc/oracle.rb,
lib/sequel/adapters/jdbc/sqlite.rb,
lib/sequel/adapters/jdbc/sqlserver.rb,
lib/sequel/adapters/jdbc/postgresql.rb,
lib/sequel/adapters/jdbc/sqlanywhere.rb,
lib/sequel/adapters/jdbc/transactions.rb

Defined Under Namespace

Modules: DB2, Derby, H2, HSQLDB, JTDS, JavaSQL, MSSQL, MySQL, Oracle, Postgres, SQLServer, SQLite, SqlAnywhere, Transactions Classes: Database, Dataset, TypeConvertor

Constant Summary collapse

JNDI_URI_REGEXP =

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

/\Ajdbc:jndi:(.+)/
DATABASE_SETUP =

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

{}
NativeException =

Create custom NativeException alias for nicer access, and also so that JRuby 9.2+ so it doesn’t use the deprecated ::NativeException

java.lang.Exception
DATABASE_ERROR_CLASSES =

Default database error classes

[NativeException]

Class Method Summary collapse

Class Method Details

.load_driver(drv, gem = nil) ⇒ Object

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.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/sequel/adapters/jdbc.rb', line 50

def self.load_driver(drv, gem=nil)
  load_gem(gem) if gem
  if drv.is_a?(String)
    eval drv
  else
    *try, last = drv
    try.each do |try_drv|
      begin
        return eval(try_drv)
      rescue NameError
      end
    end

    eval last
  end
rescue NameError
  raise Sequel::AdapterNotFound, "#{drv} not loaded#{", try installing jdbc-#{gem.to_s.downcase} gem" if gem}"
end

.load_gem(name) ⇒ Object

Allow loading the necessary JDBC support via a gem.



34
35
36
37
38
39
40
41
42
43
# File 'lib/sequel/adapters/jdbc.rb', line 34

def self.load_gem(name)
  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