Module: ActiveRecord::ConnectionAdapters::JdbcConnection::ConfigHelper

Included in:
ActiveRecord::ConnectionAdapters::JdbcConnection
Defined in:
lib/arjdbc/jdbc/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject

Returns the value of attribute config.



5
6
7
# File 'lib/arjdbc/jdbc/connection.rb', line 5

def config
  @config
end

Instance Method Details

#configure_connectionObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/arjdbc/jdbc/connection.rb', line 11

def configure_connection
  config[:retry_count] ||= 5
  config[:connection_alive_sql] ||= "select 1"
  @jndi_connection = false
  @connection = nil
  if config[:jndi]
    begin
      configure_jndi
    rescue => e
      warn "JNDI data source unavailable: #{e.message}; trying straight JDBC"
      configure_jdbc
    end
  else
    configure_jdbc
  end
end

#configure_jdbcObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/arjdbc/jdbc/connection.rb', line 36

def configure_jdbc
  if ! config[:url] || ( ! config[:driver] && ! config[:driver_instance] )
    raise ::ActiveRecord::ConnectionNotEstablished, "jdbc adapter requires :driver class and :url"
  end

  url = configure_url
  username = config[:username].to_s
  password = config[:password].to_s
  jdbc_driver = ( config[:driver_instance] ||= 
      JdbcDriver.new(config[:driver].to_s, config[:properties]) )

  @connection_factory = JdbcConnectionFactory.impl do
    jdbc_driver.connection(url, username, password)
  end
end

#configure_jndiObject



28
29
30
31
32
33
34
# File 'lib/arjdbc/jdbc/connection.rb', line 28

def configure_jndi
  data_source = javax.naming.InitialContext.new.lookup config[:jndi].to_s
  @jndi_connection = true
  @connection_factory = JdbcConnectionFactory.impl do
    data_source.connection
  end
end