Module: Sequel::JDBC

Defined in:
lib/sequel/lib/sequel/adapters/jdbc.rb,
lib/sequel/lib/sequel/adapters/jdbc/h2.rb,
lib/sequel/lib/sequel/adapters/jdbc/mysql.rb,
lib/sequel/lib/sequel/adapters/jdbc/mssql.rb,
lib/sequel/lib/sequel/adapters/jdbc/oracle.rb,
lib/sequel/lib/sequel/adapters/jdbc/sqlite.rb,
lib/sequel/lib/sequel/adapters/jdbc/postgresql.rb

Overview

Houses Sequel's JDBC support when running on JRuby. Support for individual database types is done using sub adapters. PostgreSQL, MySQL, SQLite, Oracle, and MSSQL all have relatively good support, close the the level supported by the native adapter. PostgreSQL, MySQL, SQLite can load necessary support using the jdbc-* gem, if it is installed, though they will work if you have the correct .jar in your CLASSPATH. Oracle and MSSQL should load the necessary support if you have the .jar in your CLASSPATH. For all other databases, the Java class should be loaded manually before calling Sequel.connect.

Note that when using a JDBC adapter, the best way to use Sequel is via Sequel.connect, NOT Sequel.jdbc. Use the JDBC connection string when connecting, which will be in a different format than the native connection string. The connection string should start with 'jdbc:'. For PostgreSQL, use 'jdbc:postgresql:', and for SQLite you do not need 2 preceding slashes for the database name (use no preceding slashes for a relative path, and one preceding slash for an absolute path).

Defined Under Namespace

Modules: H2, JavaLang, JavaSQL, MSSQL, MySQL, Oracle, Postgres, SQLite Classes: Database, Dataset

Constant Summary collapse

DATABASE_SETUP =

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

{:postgresql=>proc do |db|
    Sequel.require 'adapters/jdbc/postgresql'
    db.extend(Sequel::JDBC::Postgres::DatabaseMethods)
    JDBC.load_gem('postgres')
    org.postgresql.Driver
  end,
  :mysql=>proc do |db|
    Sequel.require 'adapters/jdbc/mysql'
    db.extend(Sequel::JDBC::MySQL::DatabaseMethods)
    JDBC.load_gem('mysql')
    com.mysql.jdbc.Driver
  end,
  :sqlite=>proc do |db|
    Sequel.require 'adapters/jdbc/sqlite'
    db.extend(Sequel::JDBC::SQLite::DatabaseMethods)
    JDBC.load_gem('sqlite3')
    org.sqlite.JDBC
  end,
  :oracle=>proc do |db|
    Sequel.require 'adapters/jdbc/oracle'
    db.extend(Sequel::JDBC::Oracle::DatabaseMethods)
    Java::oracle.jdbc.driver.OracleDriver
  end,
  :sqlserver=>proc do |db|
    Sequel.require 'adapters/jdbc/mssql'
    db.extend(Sequel::JDBC::MSSQL::DatabaseMethods)
    com.microsoft.sqlserver.jdbc.SQLServerDriver
  end,
  :h2=>proc do |db|
    Sequel.require 'adapters/jdbc/h2'
    db.extend(Sequel::JDBC::H2::DatabaseMethods)
    JDBC.load_gem('h2')
    org.h2.Driver
  end
}

Class Method Summary collapse

Class Method Details

.load_gem(name) ⇒ Object

Allowing loading the necessary JDBC support via a gem, which works for PostgreSQL, MySQL, and SQLite.



75
76
77
78
79
80
81
# File 'lib/sequel/lib/sequel/adapters/jdbc.rb', line 75

def self.load_gem(name)
  begin
    require "jdbc/#{name}"
  rescue LoadError
    # jdbc gem not used, hopefully the user has the .jar in their CLASSPATH
  end
end