Class: ActiveRecord::ConnectionAdapters::JdbcConnection
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::JdbcConnection
- Defined in:
- lib/active_record/connection_adapters/jdbc_adapter.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#connection_factory ⇒ Object
readonly
Returns the value of attribute connection_factory.
Instance Method Summary collapse
-
#indexes(table_name, name = nil, schema_name = nil) ⇒ Object
Default JDBC introspection for index metadata on the JdbcConnection.
-
#initialize(config) ⇒ JdbcConnection
constructor
A new instance of JdbcConnection.
- #jndi_connection? ⇒ Boolean
Constructor Details
#initialize(config) ⇒ JdbcConnection
Returns a new instance of JdbcConnection.
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 297 def initialize(config) @config = config.symbolize_keys! @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 connection # force the connection to load set_native_database_types @stmts = {} rescue Exception => e raise "The driver encountered an error: #{e}" end |
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
295 296 297 |
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 295 def adapter @adapter end |
#connection_factory ⇒ Object (readonly)
Returns the value of attribute connection_factory.
295 296 297 |
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 295 def connection_factory @connection_factory end |
Instance Method Details
#indexes(table_name, name = nil, schema_name = nil) ⇒ Object
Default JDBC introspection for index metadata on the JdbcConnection. This is currently used for migrations by JdbcSpec::HSQDLB and JdbcSpec::Derby indexes with a little filtering tacked on.
JDBC index metadata is denormalized (multiple rows may be returned for one index, one row per column in the index), so a simple block-based filter like that used for tables doesn’t really work here. Callers should filter the return from this method instead.
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 |
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 333 def indexes(table_name, name = nil, schema_name = nil) with_connection_retry_guard do |conn| = conn.getMetaData begin unless String === table_name table_name = table_name.to_s else table_name = table_name.dup end table_name.upcase! if .storesUpperCaseIdentifiers table_name.downcase! if .storesLowerCaseIdentifiers resultset = .getIndexInfo(nil, schema_name, table_name, false, false) primary_keys = primary_keys(table_name) indexes = [] current_index = nil while resultset.next index_name = resultset.get_string(Jdbc::IndexMetaData::INDEX_NAME) next unless index_name index_name.downcase! column_name = resultset.get_string(Jdbc::IndexMetaData::COLUMN_NAME).downcase next if primary_keys.include? column_name # We are working on a new index if current_index != index_name current_index = index_name table_name = resultset.get_string(Jdbc::IndexMetaData::TABLE_NAME).downcase non_unique = resultset.get_boolean(Jdbc::IndexMetaData::NON_UNIQUE) # empty list for column names, we'll add to that in just a bit indexes << IndexDefinition.new(table_name, index_name, !non_unique, []) end # One or more columns can be associated with an index indexes.last.columns << column_name end resultset.close indexes ensure .close rescue nil end end end |
#jndi_connection? ⇒ Boolean
377 378 379 |
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 377 def jndi_connection? @jndi_connection end |