Module: JdbcSpec::ActiveRecordExtensions
- Included in:
- ActiveRecord::Base
- Defined in:
- lib/jdbc_adapter/jdbc_derby.rb,
lib/jdbc_adapter/jdbc_mssql.rb,
lib/jdbc_adapter/jdbc_mysql.rb,
lib/jdbc_adapter/jdbc_hsqldb.rb,
lib/jdbc_adapter/jdbc_oracle.rb,
lib/jdbc_adapter/jdbc_cachedb.rb,
lib/jdbc_adapter/jdbc_postgre.rb,
lib/jdbc_adapter/jdbc_sqlite3.rb,
lib/jdbc_adapter/jdbc_informix.rb,
lib/active_record/connection_adapters/jdbc_adapter.rb,
lib/active_record/connection_adapters/jdbc_adapter_spec.rb
Class Method Summary collapse
Instance Method Summary collapse
- #cachedb_connection(config) ⇒ Object
- #check_version(conn) ⇒ Object
- #derby_connection(config) ⇒ Object
- #embedded_driver(config) ⇒ Object
- #h2_connection(config) ⇒ Object
- #hsqldb_connection(config) ⇒ Object
- #informix_connection(config) ⇒ Object
- #jdbc_connection(config) ⇒ Object (also: #jndi_connection)
- #mssql_connection(config) ⇒ Object
- #mysql_connection(config) ⇒ Object
- #oracle_connection(config) ⇒ Object
- #parse_sqlite3_config!(config) ⇒ Object
- #postgresql_connection(config) ⇒ Object
- #sqlite3_connection(config) ⇒ Object
Class Method Details
.add_method_to_remove_from_ar_base(meth) ⇒ Object
3 4 5 6 |
# File 'lib/active_record/connection_adapters/jdbc_adapter_spec.rb', line 3 def self.add_method_to_remove_from_ar_base(meth) @methods ||= [] @methods << meth end |
.extended(klass) ⇒ Object
8 9 10 |
# File 'lib/active_record/connection_adapters/jdbc_adapter_spec.rb', line 8 def self.extended(klass) (@methods || []).each {|m| (class << klass; self; end).instance_eval { remove_method(m) rescue nil } } end |
Instance Method Details
#cachedb_connection(config) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/jdbc_adapter/jdbc_cachedb.rb', line 5 def cachedb_connection( config ) config[:port] ||= 1972 config[:url] ||= "jdbc:Cache://#{config[:host]}:#{config[:port]}/#{ config[:database]}" config[:driver] ||= "com.intersys.jdbc.CacheDriver" jdbc_connection( config ) end |
#check_version(conn) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/jdbc_adapter/jdbc_derby.rb', line 12 def check_version(conn) md = conn.raw_connection.connection. if md.database_major_version < 10 || md.database_minor_version < 5 raise ::ActiveRecord::ConnectionFailed, "Derby adapter requires Derby 10.5 or later" end conn end |
#derby_connection(config) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/jdbc_adapter/jdbc_derby.rb', line 5 def derby_connection(config) require File.dirname(__FILE__) + "/../active_record/connection_adapters/derby_adapter" config[:url] ||= "jdbc:derby:#{config[:database]};create=true" config[:driver] ||= "org.apache.derby.jdbc.EmbeddedDriver" check_version((config)) end |
#embedded_driver(config) ⇒ Object
53 54 55 56 57 |
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 53 def (config) config[:username] ||= "sa" config[:password] ||= "" jdbc_connection(config) end |
#h2_connection(config) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 10 def h2_connection(config) require File.dirname(__FILE__) + "/../active_record/connection_adapters/h2_adapter" config[:url] ||= "jdbc:h2:#{config[:database]}" config[:driver] ||= "org.h2.Driver" (config) end |
#hsqldb_connection(config) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/jdbc_adapter/jdbc_hsqldb.rb', line 3 def hsqldb_connection(config) require File.dirname(__FILE__) + "/../active_record/connection_adapters/hsqldb_adapter" config[:url] ||= "jdbc:hsqldb:#{config[:database]}" config[:driver] ||= "org.hsqldb.jdbcDriver" (config) end |
#informix_connection(config) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/jdbc_adapter/jdbc_informix.rb', line 30 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' jdbc_connection(config) end |
#jdbc_connection(config) ⇒ Object Also known as: jndi_connection
48 49 50 |
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 48 def jdbc_connection(config) ::ActiveRecord::ConnectionAdapters::JdbcAdapter.new(nil, logger, config) end |
#mssql_connection(config) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/jdbc_adapter/jdbc_mssql.rb', line 7 def mssql_connection(config) require "active_record/connection_adapters/mssql_adapter" config[:host] ||= "localhost" config[:port] ||= 1433 config[:url] ||= "jdbc:jtds:sqlserver://#{config[:host]}:#{config[:port]}/#{config[:database]}" config[:driver] ||= "net.sourceforge.jtds.jdbc.Driver" (config) end |
#mysql_connection(config) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/jdbc_adapter/jdbc_mysql.rb', line 10 def mysql_connection(config) require File.dirname(__FILE__) + "/../active_record/connection_adapters/mysql_adapter" config[:port] ||= 3306 = "zeroDateTimeBehavior=convertToNull&jdbcCompliantTruncation=false&useUnicode=true&characterEncoding=" << (config[:encoding] || 'utf8') if config[:url] config[:url] = config[:url]['?'] ? "#{config[:url]}&#{}" : "#{config[:url]}?#{}" else config[:url] = "jdbc:mysql://#{config[:host]}:#{config[:port]}/#{config[:database]}?#{}" end config[:driver] = "com.mysql.jdbc.Driver" connection = jdbc_connection(config) ::JdbcSpec::MySQL.kill_cancel_timer(connection.raw_connection) connection end |
#oracle_connection(config) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/jdbc_adapter/jdbc_oracle.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" jdbc_connection(config) end |
#parse_sqlite3_config!(config) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/jdbc_adapter/jdbc_sqlite3.rb', line 18 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.(config[:database], rails_root) end end |
#postgresql_connection(config) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/jdbc_adapter/jdbc_postgre.rb', line 9 def postgresql_connection(config) require File.dirname(__FILE__) + "/../active_record/connection_adapters/postgresql_adapter" 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" conn = jdbc_connection(config) conn.execute("SET SEARCH_PATH TO #{config[:schema_search_path]}") if config[:schema_search_path] conn end |
#sqlite3_connection(config) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/jdbc_adapter/jdbc_sqlite3.rb', line 8 def sqlite3_connection(config) require File.dirname(__FILE__) + "/../active_record/connection_adapters/sqlite3_adapter" parse_sqlite3_config!(config) config[:url] ||= "jdbc:sqlite:#{config[:database]}" config[:driver] ||= "org.sqlite.JDBC" jdbc_connection(config) end |