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 this connection from the available configuration.
- #configure_jdbc ⇒ Object
- #configure_jndi ⇒ Object
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
68 69 70 |
# File 'lib/arjdbc/jdbc/connection.rb', line 68 def config @config end |
Instance Method Details
#configure_connection ⇒ Object
Note:
this has nothing to do with the configure_connection implemented
Configure this connection from the available configuration. on some of the concrete adapters (e.g. ActiveRecord::ConnectionAdapters::JdbcConnection::ConfigHelper#ArJdbc#ArJdbc::Postgres)
80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/arjdbc/jdbc/connection.rb', line 80 def configure_connection config[:retry_count] ||= 5 config[:connection_alive_sql] ||= "select 1" 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
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/arjdbc/jdbc/connection.rb', line 103 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_jndi ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/arjdbc/jdbc/connection.rb', line 95 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 |