Sha256: 23594b79331d2d904fb6f6494e20ac00741ef005b0737fbe51524a69a88bf523
Contents?: true
Size: 1.54 KB
Versions: 1
Compression:
Stored size: 1.54 KB
Contents
require 'active_record/connection_adapters/jdbc_adapter' module ActiveRecord #:nodoc: class Base #:nodoc: def self.jdbc_connection(config) config.symbolize_keys if config[:jndi] connection = ConnectionAdapters::JndiConnection.new(config) else connection = ConnectionAdapters::JdbcConnection.new(config) end ConnectionAdapters::JdbcAdapter.new(connection, logger, config) end end module ConnectionAdapters #:nodoc: # This adapter allows ActiveRecord to use JNDI to retrieve # a JDBC connection from a previously configured DataSource. # The ActiveRecord configuration looks like this: # # ActiveRecord::Base.establish_connection( # :adapter => 'jdbc', # :jndi => 'java:comp/env/jdbc/test', # :driver => 'sqlserver' # ) # # Right now, enough driver information needs to be supplied so that AR-JDBC # can genrate the right flavor of SQL. However, it's not necessary to know # exactly which driver is being used, just enough so the right SQL is generated. # class JndiConnection < JdbcConnection def initialize(config) @config = config jndi = @config[:jndi].to_s ctx = javax.naming.InitialContext.new ds = ctx.lookup(jndi) @connection = ds.connection set_native_database_types @stmts = {} rescue Exception => e raise "The driver encountered an error: #{e}" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
ActiveRecord-JDBC-0.2.3 | lib/active_record/connection_adapters/jndi_adapter.rb |