# File lib/arjdbc/jdbc/connection.rb, line 7 7: def config=(config) 8: @config = config.symbolize_keys! 9: end
# File lib/arjdbc/jdbc/connection.rb, line 11
11: def configure_connection
12: config[:retry_count] ||= 5
13: config[:connection_alive_sql] ||= "select 1"
14: @jndi_connection = false
15: @connection = nil
16: if config[:jndi]
17: begin
18: configure_jndi
19: rescue => e
20: warn "JNDI data source unavailable: #{e.message}; trying straight JDBC"
21: configure_jdbc
22: end
23: else
24: configure_jdbc
25: end
26: end
# File lib/arjdbc/jdbc/connection.rb, line 56
56: def configure_jdbc
57: unless config[:driver] && config[:url]
58: raise ::ActiveRecord::ConnectionNotEstablished, "jdbc adapter requires driver class and url"
59: end
60:
61: driver = config[:driver].to_s
62: user = config[:username].to_s
63: pass = config[:password].to_s
64: url = configure_url
65:
66: jdbc_driver = JdbcDriver.new(driver)
67: jdbc_driver.load
68: @connection_factory = JdbcConnectionFactory.impl do
69: jdbc_driver.connection(url, user, pass)
70: end
71: end
# File lib/arjdbc/jdbc/connection.rb, line 28
28: def configure_jndi
29: jndi = config[:jndi].to_s
30: ctx = javax.naming.InitialContext.new
31: ds = ctx.lookup(jndi)
32: @connection_factory = JdbcConnectionFactory.impl do
33: ds.connection
34: end
35: unless config[:driver]
36: config[:driver] = connection.meta_data.connection.java_class.name
37: end
38: @jndi_connection = true
39: end
# File lib/arjdbc/jdbc/connection.rb, line 41
41: def configure_url
42: url = config[:url].to_s
43: if Hash === config[:options]
44: options = ''
45: config[:options].each do |k,v|
46: options << '&' unless options.empty?
47: options << "#{k}=#{v}"
48: end
49: url = url['?'] ? "#{url}&#{options}" : "#{url}?#{options}" unless options.empty?
50: config[:url] = url
51: config[:options] = nil
52: end
53: url
54: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.