Module: ArJdbc::Abstract::Core
- Included in:
- ActiveRecord::ConnectionAdapters::JdbcAdapter, ActiveRecord::ConnectionAdapters::PostgreSQLAdapter, ActiveRecord::ConnectionAdapters::SQLite3Adapter
- Defined in:
- lib/arjdbc/abstract/core.rb
Overview
This is minimum amount of code needed from base JDBC Adapter class to make common adapters work. This replaces using jdbc/adapter as a base class for all adapters.
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #initialize(connection, logger = nil, config = {}) ⇒ Object
-
#jdbc_connection(unwrap = nil) ⇒ Java::JavaSql::Connection
Retrieve the raw
java.sql.Connection
object. - #translate_exception(e, message) ⇒ Object protected
- #translate_exception_class(e, sql) ⇒ Object protected
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
8 9 10 |
# File 'lib/arjdbc/abstract/core.rb', line 8 def config @config end |
Instance Method Details
#initialize(connection, logger = nil, config = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/arjdbc/abstract/core.rb', line 10 def initialize(connection, logger = nil, config = {}) @config = config if self.class.equal? ActiveRecord::ConnectionAdapters::JdbcAdapter spec = @config.key?(:adapter_spec) ? @config[:adapter_spec] : ( @config[:adapter_spec] = adapter_spec(@config) ) # due resolving visitor extend spec if spec end connection ||= jdbc_connection_class(config[:adapter_spec]).new(config, self) super(connection, logger, config) # AbstractAdapter connection.configure_connection # will call us (maybe) end |
#jdbc_connection(unwrap = nil) ⇒ Java::JavaSql::Connection
Retrieve the raw java.sql.Connection
object.
The unwrap parameter is useful if an attempt to unwrap a pooled (JNDI)
connection should be made - to really return the 'native' JDBC object.
31 32 33 |
# File 'lib/arjdbc/abstract/core.rb', line 31 def jdbc_connection(unwrap = nil) raw_connection.jdbc_connection(unwrap) end |
#translate_exception(e, message) ⇒ Object (protected)
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/arjdbc/abstract/core.rb', line 49 def translate_exception(e, ) # override in derived class # we shall not translate native "Java" exceptions as they might # swallow an ArJdbc / driver bug into an AR::StatementInvalid ! return e if e.is_a?(Java::JavaLang::Throwable) case e when SystemExit, SignalException, NoMemoryError then e when ActiveModel::RangeError, TypeError, RuntimeError then e else ActiveRecord::StatementInvalid.new() end end |
#translate_exception_class(e, sql) ⇒ Object (protected)
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/arjdbc/abstract/core.rb', line 37 def translate_exception_class(e, sql) begin = "#{e.class.name}: #{e.}: #{sql}" rescue Encoding::CompatibilityError = "#{e.class.name}: #{e..force_encoding sql.encoding}: #{sql}" end exception = translate_exception(e, ) exception.set_backtrace e.backtrace unless e.equal?(exception) exception end |