Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/arjdbc/jdbc/base_ext.rb,
lib/arjdbc/informix/adapter.rb,
lib/arjdbc/h2/connection_methods.rb,
lib/arjdbc/jdbc/connection_methods.rb,
lib/arjdbc/derby/connection_methods.rb,
lib/arjdbc/mssql/connection_methods.rb,
lib/arjdbc/mysql/connection_methods.rb,
lib/arjdbc/hsqldb/connection_methods.rb,
lib/arjdbc/oracle/connection_methods.rb,
lib/arjdbc/sqlite3/connection_methods.rb,
lib/arjdbc/informix/connection_methods.rb,
lib/arjdbc/postgresql/connection_methods.rb

Overview

reopen

Class Method Summary collapse

Class Method Details

.derby_connection(config) ⇒ Object Also known as: jdbcderby_connection



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/arjdbc/derby/connection_methods.rb', line 4

def derby_connection(config)
  config[:url] ||= "jdbc:derby:#{config[:database]};create=true"
  config[:driver] ||= "org.apache.derby.jdbc.EmbeddedDriver"
  config[:adapter_spec] = ::ArJdbc::Derby
  conn = embedded_driver(config)
  md = conn.jdbc_connection.
  if md.database_major_version < 10 || (md.database_major_version == 10 && md.database_minor_version < 5)
    raise ::ActiveRecord::ConnectionFailed, "Derby adapter requires Derby 10.5 or later"
  end
  conn
end

.embedded_driver(config) ⇒ Object



10
11
12
13
14
# File 'lib/arjdbc/jdbc/connection_methods.rb', line 10

def embedded_driver(config)
  config[:username] ||= "sa"
  config[:password] ||= ""
  jdbc_connection(config)
end

.h2_connection(config) ⇒ Object Also known as: jdbch2_connection



4
5
6
7
8
9
# File 'lib/arjdbc/h2/connection_methods.rb', line 4

def h2_connection(config)
  config[:url] ||= "jdbc:h2:#{config[:database]}"
  config[:driver] ||= "org.h2.Driver"
  config[:adapter_spec] = ::ArJdbc::H2
  embedded_driver(config)
end

.hsqldb_connection(config) ⇒ Object Also known as: jdbchsqldb_connection



4
5
6
7
8
9
10
# File 'lib/arjdbc/hsqldb/connection_methods.rb', line 4

def hsqldb_connection(config)
  require "arjdbc/hsqldb"
  config[:url] ||= "jdbc:hsqldb:#{config[:database]}"
  config[:driver] ||= "org.hsqldb.jdbcDriver"
  config[:adapter_spec] = ::ArJdbc::HSQLDB
  embedded_driver(config)
end

.informix_connection(config) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/arjdbc/informix/connection_methods.rb', line 3

def informix_connection(config)
  config[:port] ||= 9088
  config[:url] ||= "jdbc:informix-sqli://#{config[:host]}:#{config[:port]}/#{config[:database]}:INFORMIXSERVER=#{config[:servername]}"
  config[:driver] = 'com.informix.jdbc.IfxDriver'
  config[:adapter_spec] = ::ArJdbc::Informix
  jdbc_connection(config)
end

.jdbc_connection(config) ⇒ Object Also known as: jndi_connection



3
4
5
6
7
# File 'lib/arjdbc/jdbc/connection_methods.rb', line 3

def jdbc_connection(config)
  adapter_class = config[:adapter_class]
  adapter_class ||= ::ActiveRecord::ConnectionAdapters::JdbcAdapter
  adapter_class.new(nil, logger, config)
end

.mssql_connection(config) ⇒ Object Also known as: jdbcmssql_connection



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/arjdbc/mssql/connection_methods.rb', line 3

def mssql_connection(config)
  require "arjdbc/mssql"
  config[:host] ||= "localhost"
  config[:port] ||= 1433
  config[:driver] ||= "net.sourceforge.jtds.jdbc.Driver"
  config[:adapter_spec] = ::ArJdbc::MsSQL

  url = "jdbc:jtds:sqlserver://#{config[:host]}:#{config[:port]}/#{config[:database]}"

  # Instance is often a preferrable alternative to port when dynamic ports are used.
  # If instance is specified then port is essentially ignored.
  url << ";instance=#{config[:instance]}" if config[:instance]

  # This will enable windows domain-based authentication and will require the JTDS native libraries be available.
  url << ";domain=#{config[:domain]}" if config[:domain]

  # AppName is shown in sql server as additional information against the connection.
  url << ";appname=#{config[:appname]}" if config[:appname]
  config[:url] ||= url

  if !config[:domain]
    config[:username] ||= "sa"
    config[:password] ||= ""
  end
  jdbc_connection(config)
end

.mysql_connection(config) ⇒ Object Also known as: jdbcmysql_connection, mysql2_connection



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/arjdbc/mysql/connection_methods.rb', line 7

def mysql_connection(config)
  require "arjdbc/mysql"
  config[:port] ||= 3306
  options = (config[:options] ||= {})
  options['zeroDateTimeBehavior'] ||= 'convertToNull'
  options['jdbcCompliantTruncation'] ||= 'false'
  options['useUnicode'] ||= 'true'
  options['characterEncoding'] = config[:encoding] || 'utf8'
  config[:url] ||= "jdbc:mysql://#{config[:host]}:#{config[:port]}/#{config[:database]}"
  config[:driver] ||= "com.mysql.jdbc.Driver"
  config[:adapter_class] = ActiveRecord::ConnectionAdapters::MysqlAdapter
  config[:adapter_spec] = ::ArJdbc::MySQL
  connection = jdbc_connection(config)
  ::ArJdbc::MySQL.kill_cancel_timer(connection.raw_connection)
  connection
end

.oracle_connection(config) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/arjdbc/oracle/connection_methods.rb', line 3

def oracle_connection(config)
  config[:port] ||= 1521
  config[:url] ||= "jdbc:oracle:thin:@#{config[:host]}:#{config[:port]}:#{config[:database]}"
  config[:driver] ||= "oracle.jdbc.driver.OracleDriver"
  config[:adapter_spec] = ::ArJdbc::Oracle
  jdbc_connection(config)
end

.parse_sqlite3_config!(config) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/arjdbc/sqlite3/connection_methods.rb', line 20

def parse_sqlite3_config!(config)
  config[:database] ||= config[:dbfile]

  # Allow database path relative to RAILS_ROOT, but only if
  # the database path is not the special path that tells
  # Sqlite to build a database only in memory.
  rails_root_defined = defined?(Rails.root) || Object.const_defined?(:RAILS_ROOT)
  if rails_root_defined && ':memory:' != config[:database]
    rails_root = defined?(Rails.root) ? Rails.root : RAILS_ROOT
    config[:database] = File.expand_path(config[:database], rails_root)
  end
end

.postgresql_connection(config) ⇒ Object Also known as: jdbcpostgresql_connection



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/arjdbc/postgresql/connection_methods.rb', line 6

def postgresql_connection(config)
  require "arjdbc/postgresql"
  config[:host] ||= "localhost"
  config[:port] ||= 5432
  config[:url] ||= "jdbc:postgresql://#{config[:host]}:#{config[:port]}/#{config[:database]}"
  config[:url] << config[:pg_params] if config[:pg_params]
  config[:driver] ||= "org.postgresql.Driver"
  config[:adapter_class] = ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
  config[:adapter_spec] = ::ArJdbc::PostgreSQL
  conn = jdbc_connection(config)
  conn.execute("SET SEARCH_PATH TO #{config[:schema_search_path]}") if config[:schema_search_path]
  conn
end

.reset_column_information_with_arjdbc_base_extObject

Allow adapters to provide their own reset_column_information methods

NOTE: This only affects the current thread’s connection.



7
8
9
10
11
# File 'lib/arjdbc/jdbc/base_ext.rb', line 7

def reset_column_information_with_arjdbc_base_ext
  # Invoke the adapter-specific reset_column_information method
  connection.reset_column_information if connection.respond_to?(:reset_column_information)
  reset_column_information_without_arjdbc_base_ext
end

.sqlite3_connection(config) ⇒ Object Also known as: jdbcsqlite3_connection



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/arjdbc/sqlite3/connection_methods.rb', line 7

def sqlite3_connection(config)
  require "arjdbc/sqlite3"

  parse_sqlite3_config!(config)
  database = config[:database]
  database = '' if database == ':memory:'
  config[:url] ||= "jdbc:sqlite:#{database}"
  config[:driver] ||= "org.sqlite.JDBC"
  config[:adapter_class] = ActiveRecord::ConnectionAdapters::SQLite3Adapter
  config[:adapter_spec] = ::ArJdbc::SQLite3
  jdbc_connection(config)
end