Module: ActiveRecord::ConnectionAdapters::JdbcConnection::ConfigHelper
- Included in:
- ActiveRecord::ConnectionAdapters::JdbcConnection
- Defined in:
- lib/arjdbc/jdbc/connection.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #configure_connection ⇒ Object
- #configure_jdbc ⇒ Object
- #configure_jndi ⇒ Object
- #configure_url ⇒ Object
Instance Attribute Details
#config ⇒ Object
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_connection ⇒ Object
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.}; trying straight JDBC" configure_jdbc end else configure_jdbc end end |
#configure_jdbc ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/arjdbc/jdbc/connection.rb', line 56 def configure_jdbc unless config[:driver] && config[:url] raise ::ActiveRecord::ConnectionNotEstablished, "jdbc adapter requires driver class and url" end driver = config[:driver].to_s user = config[:username].to_s pass = config[:password].to_s url = configure_url jdbc_driver = (config[:driver_instance] ||= JdbcDriver.new(driver)) @connection_factory = JdbcConnectionFactory.impl do jdbc_driver.connection(url, user, pass) end end |
#configure_jndi ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/arjdbc/jdbc/connection.rb', line 28 def configure_jndi jndi = config[:jndi].to_s ctx = javax.naming.InitialContext.new ds = ctx.lookup(jndi) @connection_factory = JdbcConnectionFactory.impl do ds.connection end unless config[:driver] config[:driver] = connection..connection.java_class.name end @jndi_connection = true end |
#configure_url ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/arjdbc/jdbc/connection.rb', line 41 def configure_url url = config[:url].to_s if Hash === config[:options] = '' config[:options].each do |k,v| << '&' unless .empty? << "#{k}=#{v}" end url = url['?'] ? "#{url}&#{}" : "#{url}?#{}" unless .empty? config[:url] = url config[:options] = nil end url end |