Class: ActiveRecord::ConnectionAdapters::JdbcAdapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- ActiveRecord::ConnectionAdapters::JdbcAdapter
- Includes:
- ActiveRecord::ConnectionAdapters::Jdbc::ArelSupport, ActiveRecord::ConnectionAdapters::Jdbc::ConnectionPoolCallbacks
- Defined in:
- lib/arjdbc/jdbc/adapter.rb
Overview
Built on top of ActiveRecord::ConnectionAdapters::AbstractAdapter
which
provides the abstract interface for database-specific functionality, this
class serves 2 purposes in AR-JDBC :
- as a base class for sub-classes
- usable standalone (or with a mixed in adapter spec module)
Historically this class is mostly been used standalone and that's still a
valid use-case esp. since (with it's arjdbc.jdbc.RubyJdbcConnectionClass
)
JDBC provides a unified interface for all databases in Java it tries to do
it's best implementing all ActiveRecord
functionality on top of that.
This might no be perfect that's why it checks for a config[:adapter_spec]
module (or tries to resolve one from the JDBC driver's meta-data) and if
the database has "extended" AR-JDBC support mixes in the given module for
each adapter instance.
This is sufficient for most database specific specs we support, but for
compatibility with native (MRI) adapters it's perfectly fine to sub-class
the adapter and override some of its API methods.
Direct Known Subclasses
H2Adapter, HsqldbAdapter, InformixAdapter, MSSQLAdapter, MysqlAdapter, OracleAdapter, PostgreSQLAdapter, SQLite3Adapter
Constant Summary collapse
- ADAPTER_NAME =
'JDBC'.freeze
- @@suble_binds =
due compatibility
ActiveRecord::VERSION::MAJOR < 4
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
-
.arel2_visitors(config) ⇒ Hash
deprecated
Deprecated.
re-implemented - no longer used
-
.configure_arel2_visitors(config) ⇒ Object
deprecated
Deprecated.
re-implemented - no longer used
-
.insert?(sql) ⇒ Boolean
protected
Whether the given SQL string is an 'INSERT' query.
-
.prepared_statements?(config) ⇒ Boolean
protected
Allows changing the prepared statements setting for this connection.
-
.select?(sql) ⇒ Boolean
protected
query (returning a result set).
- .suble_binds=(flag) ⇒ Object protected
- .suble_binds? ⇒ Boolean protected
-
.update?(sql) ⇒ Boolean
protected
Whether the given SQL string is an 'UPDATE' (or 'DELETE') query.
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#adapter_name ⇒ String
The 'JDBC' adapter name.
-
#adapter_spec(config) ⇒ Module
Locate the specialized (database specific) adapter specification module if one exists based on provided configuration data.
-
#begin_db_transaction ⇒ Object
Starts a database transaction.
-
#begin_isolated_db_transaction(isolation) ⇒ Object
Starts a database transaction.
- #columns(table_name, name = nil) ⇒ Object
-
#commit_db_transaction ⇒ Object
Commits the current database transaction.
-
#create_savepoint(name = current_savepoint_name(true)) ⇒ Object
Creates a (transactional) save-point one can rollback to.
-
#current_savepoint_name(create = nil) ⇒ String
Due tracking of save-points created in a LIFO manner, always returns the correct name if any (last) save-point has been marked and not released.
-
#database_name ⇒ Object
Returns the underlying database name.
- #disconnect! ⇒ Object
-
#exec_delete(sql, name, binds) ⇒ Object
Executes a delete statement in the context of this connection.
-
#exec_insert(sql, name, binds, pk = nil, sequence_name = nil) ⇒ Object
Executes an insert statement in the context of this connection.
-
#exec_query(sql, name = 'SQL', binds = []) ⇒ ActiveRecord::Result
Executes a SQL query in the context of this connection using the bind substitutes.
-
#exec_query_raw(sql, name = 'SQL', binds = []) {|v1, v2| ... } ⇒ Array
Similar to #exec_query except it returns "raw" results in an array where each rows is a hash with keys as columns (just like Rails used to do up until 3.0) instead of wrapping them in a #ActiveRecord#ActiveRecord::Result.
-
#exec_update(sql, name, binds) ⇒ Object
Executes an update statement in the context of this connection.
- #indexes(table_name, name = nil, schema_name = nil) ⇒ Object
-
#initialize(connection, logger, config = nil) ⇒ JdbcAdapter
constructor
Initializes the (JDBC connection) adapter instance.
- #insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object
-
#is_a?(klass) ⇒ Boolean
Will return true even when native adapter classes passed in e.g.
-
#jdbc_column_class ⇒ Object
Returns the (JDBC)
ActiveRecord
column class for this adapter. -
#jdbc_connection(unwrap = nil) ⇒ Java::JavaSql::Connection
Retrieve the raw
java.sql.Connection
object. -
#jdbc_connection_class(spec) ⇒ Object
Returns the (JDBC) connection class to be used for this adapter.
- #log(sql, name = nil, binds = []) ⇒ Object
-
#modify_types(types) ⇒ Object
Allows for modification of the detected native types.
-
#native_database_types ⇒ Hash
DB specific types are detected but adapter specs (or extenders) are expected to hand tune these types for concrete databases.
- #pk_and_sequence_for(table) ⇒ Object
-
#prepared_statements? ⇒ Boolean
protected
Whether
:prepared_statements
are to be used. - #primary_key(table) ⇒ Object
- #primary_keys(table) ⇒ Object
- #reconnect! ⇒ Object
-
#release_savepoint(name = current_savepoint_name) ⇒ Object
Release a previously created save-point.
-
#rollback_db_transaction ⇒ Object
Rolls back the current database transaction.
-
#rollback_to_savepoint(name = current_savepoint_name) ⇒ Object
Transaction rollback to a given (previously created) save-point.
-
#structure_dump ⇒ Object
Abstract adapter default implementation does nothing silently.
-
#supports_migrations? ⇒ true
JDBC adapters support migration.
-
#supports_savepoints? ⇒ Boolean
Does our database (+ its JDBC driver) support save-points?.
-
#supports_transaction_isolation?(level = nil) ⇒ Boolean
Does this adapter support setting the isolation level for a transaction? Unlike 'plain'
ActiveRecord
we allow checking for concrete transaction isolation level support by the database. - #supports_views? ⇒ Boolean
-
#table_definition ⇒ Object
protected
aliasing #create_table_definition as #table_definition :.
- #table_exists?(name) ⇒ Boolean
- #tables(name = nil) ⇒ Object
- #translate_exception(e, message) ⇒ Object protected
- #update_lob_value(record, column, value) ⇒ Object
-
#write_large_object(*args) ⇒ Object
deprecated
Deprecated.
Rather use #update_lob_value instead.
Methods included from ActiveRecord::ConnectionAdapters::Jdbc::ConnectionPoolCallbacks
Methods included from ActiveRecord::ConnectionAdapters::Jdbc::ArelSupport
Constructor Details
#initialize(connection, logger, config = nil) ⇒ JdbcAdapter
initialize(logger, config)
with 2 arguments is supported as well
Initializes the (JDBC connection) adapter instance.
The passed configuration Hash's keys are symbolized, thus changes to
the original config
keys won't be reflected in the adapter.
If the adapter's sub-class or the spec module that this instance will
extend in responds to configure_connection
than it will be called.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 52 def initialize(connection, logger, config = nil) if config.nil? && logger.respond_to?(:key?) # (logger, config) config, logger, connection = logger, connection, nil end @config = config.respond_to?(:symbolize_keys) ? config.symbolize_keys : config # NOTE: JDBC 4.0 drivers support checking if connection isValid # thus no need to @config[:connection_alive_sql] ||= 'SELECT 1' # # NOTE: setup to retry 5-times previously - maybe do not set at all ? @config[:retry_count] ||= 1 @config[:adapter_spec] = adapter_spec(@config) unless @config.key?(:adapter_spec) spec = @config[:adapter_spec] # NOTE: adapter spec's init_connection only called if instantiated here : connection ||= jdbc_connection_class(spec).new(@config, self) super(connection, logger) # kind of like `extend ArJdbc::MyDB if self.class == JdbcAdapter` : klass = @config[:adapter_class] extend spec if spec && ( ! klass || klass == JdbcAdapter) # NOTE: should not be necessary for JNDI due reconnect! on checkout : configure_connection if respond_to?(:configure_connection) Jdbc::JndiConnectionPoolCallbacks.prepare(self, connection) @visitor = new_visitor # nil if no AREL (AR-2.3) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
41 42 43 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 41 def config @config end |
Class Method Details
.arel2_visitors(config) ⇒ Hash
re-implemented - no longer used
If there's a self.arel2_visitors(config)
method on the adapter
spec than it is preferred and will be used instead of this one.
187 188 189 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 187 def self.arel2_visitors(config) { 'jdbc' => ::Arel::Visitors::ToSql } end |
.configure_arel2_visitors(config) ⇒ Object
re-implemented - no longer used
193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 193 def self.configure_arel2_visitors(config) visitors = ::Arel::Visitors::VISITORS klass = config[:adapter_spec] klass = self unless klass.respond_to?(:arel2_visitors) visitor = nil klass.arel2_visitors(config).each do |name, arel| visitors[name] = ( visitor = arel ) end if visitor && config[:adapter] =~ /^(jdbc|jndi)$/ visitors[ config[:adapter] ] = visitor end visitor end |
.insert?(sql) ⇒ Boolean (protected)
Returns whether the given SQL string is an 'INSERT' query.
849 850 851 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 849 def self.insert?(sql) JdbcConnection::insert?(sql) end |
.prepared_statements?(config) ⇒ Boolean (protected)
Allows changing the prepared statements setting for this connection. def prepared_statements=(statements) @prepared_statements = statements end
776 777 778 779 780 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 776 def self.prepared_statements?(config) config.key?(:prepared_statements) ? type_cast_config_to_boolean(config.fetch(:prepared_statements)) : false # off by default - NOTE: on AR 4.x it's on by default !? end |
.select?(sql) ⇒ Boolean (protected)
query (returning a result set)
844 845 846 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 844 def self.select?(sql) JdbcConnection::select?(sql) end |
.suble_binds=(flag) ⇒ Object (protected)
788 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 788 def self.suble_binds=(flag); @@suble_binds = flag; end |
.suble_binds? ⇒ Boolean (protected)
787 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 787 def self.suble_binds?; @@suble_binds; end |
.update?(sql) ⇒ Boolean (protected)
Returns whether the given SQL string is an 'UPDATE' (or 'DELETE') query.
854 855 856 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 854 def self.update?(sql) ! select?(sql) && ! insert?(sql) end |
Instance Method Details
#active? ⇒ Boolean
282 283 284 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 282 def active? @connection.active? end |
#adapter_name ⇒ String
Returns the 'JDBC' adapter name.
162 163 164 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 162 def adapter_name ADAPTER_NAME end |
#adapter_spec(config) ⇒ Module
Locate the specialized (database specific) adapter specification module
if one exists based on provided configuration data. This module will than
extend an instance of the adapter (unless an :adapter_class
provided).
This method is called during #initialize unless an explicit
config[:adapter_spec]
is set.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 132 def adapter_spec(config) dialect = (config[:dialect] || config[:driver]).to_s ::ArJdbc.modules.each do |constant| # e.g. ArJdbc::MySQL if constant.respond_to?(:adapter_matcher) spec = constant.adapter_matcher(dialect, config) return spec if spec end end if (config[:jndi] || config[:data_source]) && ! config[:dialect] begin data_source = config[:data_source] || Java::JavaxNaming::InitialContext.new.lookup(config[:jndi]) connection = data_source.getConnection config[:dialect] = connection.getMetaData.getDatabaseProductName rescue Java::JavaSql::SQLException => e warn "failed to set database :dialect from connection meda-data (#{e})" else return adapter_spec(config) # re-try matching a spec with set config[:dialect] ensure connection.close if connection # return to the pool end end nil end |
#begin_db_transaction ⇒ Object
Starts a database transaction.
332 333 334 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 332 def begin_db_transaction @connection.begin end |
#begin_isolated_db_transaction(isolation) ⇒ Object
Starts a database transaction.
352 353 354 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 352 def begin_isolated_db_transaction(isolation) @connection.begin(isolation) end |
#columns(table_name, name = nil) ⇒ Object
326 327 328 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 326 def columns(table_name, name = nil) @connection.columns(table_name.to_s) end |
#commit_db_transaction ⇒ Object
Commits the current database transaction.
338 339 340 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 338 def commit_db_transaction @connection.commit end |
#create_savepoint(name = current_savepoint_name(true)) ⇒ Object
Creates a (transactional) save-point one can rollback to.
Unlike 'plain' ActiveRecord
it is allowed to pass a save-point name.
379 380 381 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 379 def create_savepoint(name = current_savepoint_name(true)) @connection.create_savepoint(name) end |
#current_savepoint_name(create = nil) ⇒ String
Due tracking of save-points created in a LIFO manner, always returns
the correct name if any (last) save-point has been marked and not released.
Otherwise when creating a save-point same naming convention as
ActiveRecord
uses ("active_record_" prefix) will be returned.
409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 409 def current_savepoint_name(create = nil) open_tx = open_transactions return "active_record_#{open_tx}" if create sp_names = @connection.marked_savepoint_names unless sp_names.empty? sp_names[ -(sp_names.size - open_tx + 1) ] else "active_record_#{open_tx}" end end |
#database_name ⇒ Object
Returns the underlying database name.
241 242 243 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 241 def database_name @connection.database_name end |
#disconnect! ⇒ Object
293 294 295 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 293 def disconnect! @connection.disconnect! end |
#exec_delete(sql, name, binds) ⇒ Object
Executes a delete statement in the context of this connection.
467 468 469 470 471 472 473 474 475 476 477 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 467 def exec_delete(sql, name, binds) if sql.respond_to?(:to_sql) sql = to_sql(sql, binds); to_sql = true end if prepared_statements? log(sql, name || 'SQL', binds) { @connection.execute_delete(sql, binds) } else sql = suble_binds(sql, binds) unless to_sql # deprecated behavior log(sql, name || 'SQL') { @connection.execute_delete(sql) } end end |
#exec_insert(sql, name, binds, pk = nil, sequence_name = nil) ⇒ Object
Executes an insert statement in the context of this connection.
450 451 452 453 454 455 456 457 458 459 460 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 450 def exec_insert(sql, name, binds, pk = nil, sequence_name = nil) if sql.respond_to?(:to_sql) sql = to_sql(sql, binds); to_sql = true end if prepared_statements? log(sql, name || 'SQL', binds) { @connection.execute_insert(sql, binds) } else sql = suble_binds(sql, binds) unless to_sql # deprecated behavior log(sql, name || 'SQL') { @connection.execute_insert(sql) } end end |
#exec_query(sql, name = 'SQL', binds = []) ⇒ ActiveRecord::Result
Executes a SQL query in the context of this connection using the bind substitutes.
433 434 435 436 437 438 439 440 441 442 443 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 433 def exec_query(sql, name = 'SQL', binds = []) if sql.respond_to?(:to_sql) sql = to_sql(sql, binds); to_sql = true end if prepared_statements? log(sql, name, binds) { @connection.execute_query(sql, binds) } else sql = suble_binds(sql, binds) unless to_sql # deprecated behavior log(sql, name) { @connection.execute_query(sql) } end end |
#exec_query_raw(sql, name = 'SQL', binds = []) {|v1, v2| ... } ⇒ Array
Similar to #exec_query except it returns "raw" results in an array where each rows is a hash with keys as columns (just like Rails used to do up until 3.0) instead of wrapping them in a ActiveRecord::ConnectionAdapters::JdbcAdapter#ActiveRecord#ActiveRecord::Result. In case a block is given it will yield each row from the result set instead of returning mapped query results in an array.
506 507 508 509 510 511 512 513 514 515 516 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 506 def exec_query_raw(sql, name = 'SQL', binds = [], &block) if sql.respond_to?(:to_sql) sql = to_sql(sql, binds); to_sql = true end if prepared_statements? log(sql, name, binds) { @connection.execute_query_raw(sql, binds, &block) } else sql = suble_binds(sql, binds) unless to_sql # deprecated behavior log(sql, name) { @connection.execute_query_raw(sql, &block) } end end |
#exec_update(sql, name, binds) ⇒ Object
Executes an update statement in the context of this connection.
484 485 486 487 488 489 490 491 492 493 494 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 484 def exec_update(sql, name, binds) if sql.respond_to?(:to_sql) sql = to_sql(sql, binds); to_sql = true end if prepared_statements? log(sql, name || 'SQL', binds) { @connection.execute_update(sql, binds) } else sql = suble_binds(sql, binds) unless to_sql # deprecated behavior log(sql, name || 'SQL') { @connection.execute_update(sql) } end end |
#indexes(table_name, name = nil, schema_name = nil) ⇒ Object
597 598 599 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 597 def indexes(table_name, name = nil, schema_name = nil) @connection.indexes(table_name, name, schema_name) end |
#insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object
Used on AR 2.3 and 3.0
321 322 323 324 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 321 def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) id = execute(sql, name) id_value || id end |
#is_a?(klass) ⇒ Boolean
Will return true even when native adapter classes passed in
e.g. jdbc_adapter.is_a? ConnectionAdapter::PostgresqlAdapter
This is only necessary (for built-in adapters) when
config[:adapter_class]
is forced to nil
and the :adapter_spec
module is used to extend the JdbcAdapter
, otherwise we replace the
class constants for built-in adapters (MySQL, PostgreSQL and SQLite3).
174 175 176 177 178 179 180 181 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 174 def is_a?(klass) # This is to fake out current_adapter? conditional logic in AR tests if klass.is_a?(Class) && klass.name =~ /#{adapter_name}Adapter$/i true else super end end |
#jdbc_column_class ⇒ Object
Returns the (JDBC) ActiveRecord
column class for this adapter.
This is used by (database specific) spec modules to override the class.
96 97 98 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 96 def jdbc_column_class ::ActiveRecord::ConnectionAdapters::JdbcColumn 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.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 105 def jdbc_connection(unwrap = nil) java_connection = raw_connection.connection return java_connection unless unwrap connection_class = java.sql.Connection.java_class begin if java_connection.wrapper_for?(connection_class) return java_connection.unwrap(connection_class) # java.sql.Wrapper.unwrap end rescue Java::JavaLang::AbstractMethodError => e ArJdbc.warn("driver/pool connection impl does not support unwrapping (#{e})") end if java_connection.respond_to?(:connection) # e.g. org.apache.tomcat.jdbc.pool.PooledConnection java_connection.connection # getConnection else java_connection end end |
#jdbc_connection_class(spec) ⇒ Object
Returns the (JDBC) connection class to be used for this adapter. This is used by (database specific) spec modules to override the class used assuming some of the available methods have been re-defined.
88 89 90 91 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 88 def jdbc_connection_class(spec) connection_class = spec.jdbc_connection_class if spec && spec.respond_to?(:jdbc_connection_class) connection_class ? connection_class : ::ActiveRecord::ConnectionAdapters::JdbcConnection end |
#log(sql, name = nil, binds = []) ⇒ Object
650 651 652 653 654 655 656 657 658 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 650 def log(sql, name = nil, binds = []) unless binds.blank? binds = binds.map do |column, value| column ? [column.name, value] : [nil, value] end sql = "#{sql} #{binds.inspect}" end super(sql, name || 'SQL') # `log(sql, name)` on AR <= 3.0 end |
#modify_types(types) ⇒ Object
Allows for modification of the detected native types.
222 223 224 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 222 def modify_types(types) types end |
#native_database_types ⇒ Hash
DB specific types are detected but adapter specs (or extenders) are expected to hand tune these types for concrete databases.
211 212 213 214 215 216 217 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 211 def native_database_types @native_database_types ||= begin types = @connection.native_database_types modify_types(types) types end end |
#pk_and_sequence_for(table) ⇒ Object
602 603 604 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 602 def pk_and_sequence_for(table) ( key = primary_key(table) ) ? [ key, nil ] : nil end |
#prepared_statements? ⇒ Boolean (protected)
Returns whether :prepared_statements
are to be used.
765 766 767 768 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 765 def prepared_statements? return @prepared_statements unless (@prepared_statements ||= nil).nil? @prepared_statements = self.class.prepared_statements?(config) end |
#primary_key(table) ⇒ Object
607 608 609 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 607 def primary_key(table) primary_keys(table).first end |
#primary_keys(table) ⇒ Object
612 613 614 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 612 def primary_keys(table) @connection.primary_keys(table) end |
#reconnect! ⇒ Object
287 288 289 290 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 287 def reconnect! @connection.reconnect! # handles adapter.configure_connection @connection end |
#release_savepoint(name = current_savepoint_name) ⇒ Object
Save-points are auto-released with the transaction they're created
Release a previously created save-point. in (on transaction commit or roll-back).
398 399 400 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 398 def release_savepoint(name = current_savepoint_name) @connection.release_savepoint(name) end |
#rollback_db_transaction ⇒ Object
Rolls back the current database transaction.
344 345 346 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 344 def rollback_db_transaction @connection.rollback end |
#rollback_to_savepoint(name = current_savepoint_name) ⇒ Object
Transaction rollback to a given (previously created) save-point. If no save-point name given rollback to the last created one.
388 389 390 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 388 def rollback_to_savepoint(name = current_savepoint_name) @connection.rollback_savepoint(name) end |
#structure_dump ⇒ Object
Abstract adapter default implementation does nothing silently.
228 229 230 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 228 def structure_dump raise NotImplementedError, "structure_dump not supported" end |
#supports_migrations? ⇒ true
JDBC adapters support migration.
235 236 237 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 235 def supports_migrations? true end |
#supports_savepoints? ⇒ Boolean
Does our database (+ its JDBC driver) support save-points?
369 370 371 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 369 def supports_savepoints? @connection.supports_savepoints? end |
#supports_transaction_isolation?(level = nil) ⇒ Boolean
Does this adapter support setting the isolation level for a transaction?
Unlike 'plain' ActiveRecord
we allow checking for concrete transaction
isolation level support by the database.
362 363 364 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 362 def supports_transaction_isolation?(level = nil) @connection.supports_transaction_isolation?(level) end |
#supports_views? ⇒ Boolean
422 423 424 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 422 def supports_views? @connection.supports_views? end |
#table_definition ⇒ Object (protected)
aliasing #create_table_definition as #table_definition :
698 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 698 alias table_definition create_table_definition |
#table_exists?(name) ⇒ Boolean
591 592 593 594 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 591 def table_exists?(name) return false unless name @connection.table_exists?(name) # schema_name = nil end |
#tables(name = nil) ⇒ Object
586 587 588 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 586 def tables(name = nil) @connection.tables end |
#translate_exception(e, message) ⇒ Object (protected)
661 662 663 664 665 666 667 668 669 670 671 672 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 661 def translate_exception(e, ) # we shall not translate native "Java" exceptions as they might # swallow an ArJdbc / driver bug into a AR::StatementInvalid ... return e if e.is_a?(NativeException) # JRuby 1.6 return e if e.is_a?(Java::JavaLang::Throwable) case e when SystemExit, SignalException, NoMemoryError then e # NOTE: wraps AR::JDBCError into AR::StatementInvalid, desired ?! else super end end |
#update_lob_value(record, column, value) ⇒ Object
624 625 626 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 624 def update_lob_value(record, column, value) @connection.update_lob_value(record, column, value) end |
#write_large_object(*args) ⇒ Object
Rather use #update_lob_value instead.
617 618 619 |
# File 'lib/arjdbc/jdbc/adapter.rb', line 617 def write_large_object(*args) @connection.write_large_object(*args) end |