Class: ActiveRecord::ConnectionAdapters::JdbcAdapter

Inherits:
AbstractAdapter
  • Object
show all
Extended by:
ShadowCoreMethods
Includes:
CompatibilityMethods, ConnectionPoolCallbacks
Defined in:
lib/active_record/connection_adapters/jdbc_adapter.rb

Defined Under Namespace

Modules: CompatibilityMethods, ConnectionPoolCallbacks, JndiConnectionPoolCallbacks, ShadowCoreMethods

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ShadowCoreMethods

alias_chained_method

Methods included from ConnectionPoolCallbacks

included, needed?, #on_checkin, #on_checkout

Methods included from CompatibilityMethods

needed?, #quote_table_name

Constructor Details

#initialize(connection, logger, config) ⇒ JdbcAdapter

Returns a new instance of JdbcAdapter.



471
472
473
474
475
476
477
478
479
480
481
482
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 471

def initialize(connection, logger, config)
  @config = config
  spec = adapter_spec config
  unless connection
    connection_class = jdbc_connection_class spec
    connection = connection_class.new config
  end
  super(connection, logger)
  extend spec if spec
  connection.adapter = self
  JndiConnectionPoolCallbacks.prepare(self, connection)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



469
470
471
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 469

def config
  @config
end

Instance Method Details

#_execute(sql, name = nil) ⇒ Object

we need to do it this way, to allow Rails stupid tests to always work even if we define a new execute method. Instead of mixing in a new execute, an _execute should be mixed in.



590
591
592
593
594
595
596
597
598
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 590

def _execute(sql, name = nil)
  if JdbcConnection::select?(sql)
    @connection.execute_query(sql)
  elsif JdbcConnection::insert?(sql)
    @connection.execute_insert(sql)
  else
    @connection.execute_update(sql)
  end
end

#adapter_nameObject

:nodoc:



506
507
508
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 506

def adapter_name #:nodoc:
  'JDBC'
end

#adapter_spec(config) ⇒ Object

Locate specialized adapter specification if one exists based on config data



491
492
493
494
495
496
497
498
499
500
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 491

def adapter_spec(config)
  dialect = (config[:dialect] || config[:driver]).to_s
  ::JdbcSpec.constants.map { |name| ::JdbcSpec.const_get name }.each do |constant|
    if constant.respond_to? :adapter_matcher
      spec = constant.adapter_matcher(dialect, config)
      return spec if spec
    end
  end
  nil
end

#begin_db_transactionObject



624
625
626
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 624

def begin_db_transaction
  @connection.begin
end

#commit_db_transactionObject



628
629
630
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 628

def commit_db_transaction
  @connection.commit
end

#database_nameObject

:nodoc:



518
519
520
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 518

def database_name #:nodoc:
  @connection.database_name
end

#disconnect!Object



562
563
564
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 562

def disconnect!
  @connection.disconnect!
end

#execute(sql, name = nil) ⇒ Object



581
582
583
584
585
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 581

def execute(sql, name = nil)
  log(sql, name) do
    _execute(sql,name)
  end
end

#indexes(table_name, name = nil, schema_name = nil) ⇒ Object



620
621
622
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 620

def indexes(table_name, name = nil, schema_name = nil)
  @connection.indexes(table_name, name, schema_name)
end

#jdbc_columns(table_name, name = nil) ⇒ Object



611
612
613
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 611

def jdbc_columns(table_name, name = nil)
  @connection.columns(table_name.to_s)
end

#jdbc_connection_class(spec) ⇒ Object



484
485
486
487
488
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 484

def jdbc_connection_class(spec)
  connection_class = spec.jdbc_connection_class if spec && spec.respond_to?(:jdbc_connection_class)
  connection_class = ::ActiveRecord::ConnectionAdapters::JdbcConnection unless connection_class
  connection_class
end

#jdbc_insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object



605
606
607
608
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 605

def jdbc_insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
  id = execute(sql, name = nil)
  id_value || id
end

#jdbc_select_all(sql, name = nil) ⇒ Object



566
567
568
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 566

def jdbc_select_all(sql, name = nil)
  select(sql, name)
end

#jdbc_update(sql, name = nil) ⇒ Object

:nodoc:



600
601
602
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 600

def jdbc_update(sql, name = nil) #:nodoc:
  execute(sql, name)
end

#modify_types(tp) ⇒ Object



502
503
504
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 502

def modify_types(tp)
  tp
end

#native_database_typesObject

:nodoc:



514
515
516
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 514

def native_database_types #:nodoc:
  @connection.native_database_types
end

#native_sql_to_type(tp) ⇒ Object



522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 522

def native_sql_to_type(tp)
  if /^(.*?)\(([0-9]+)\)/ =~ tp
    tname = $1
    limit = $2.to_i
    ntype = native_database_types
    if ntype[:primary_key] == tp
      return :primary_key,nil
    else
      ntype.each do |name,val|
        if name == :primary_key
          next
        end
        if val[:name].downcase == tname.downcase && (val[:limit].nil? || val[:limit].to_i == limit)
          return name,limit
        end
      end
    end
  elsif /^(.*?)/ =~ tp
    tname = $1
    ntype = native_database_types
    if ntype[:primary_key] == tp
      return :primary_key,nil
    else
      ntype.each do |name,val|
        if val[:name].downcase == tname.downcase && val[:limit].nil?
          return name,nil
        end
      end
    end
  else
    return :string,255
  end
  return nil,nil
end

#pk_and_sequence_for(table) ⇒ Object



640
641
642
643
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 640

def pk_and_sequence_for(table)
  key = primary_key(table)
  [key, nil] if key
end

#primary_key(table) ⇒ Object



645
646
647
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 645

def primary_key(table)
  primary_keys(table).first
end

#primary_keys(table) ⇒ Object



649
650
651
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 649

def primary_keys(table)
  @connection.primary_keys(table)
end

#reconnect!Object



557
558
559
560
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 557

def reconnect!
  @connection.reconnect!
  @connection
end

#rollback_db_transactionObject



632
633
634
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 632

def rollback_db_transaction
  @connection.rollback
end

#select_one(sql, name = nil) ⇒ Object



577
578
579
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 577

def select_one(sql, name = nil)
  select(sql, name).first
end

#select_rows(sql, name = nil) ⇒ Object



571
572
573
574
575
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 571

def select_rows(sql, name = nil)
  rows = []
  select(sql, name).each {|row| rows << row.values }
  rows
end

#supports_migrations?Boolean

Returns:

  • (Boolean)


510
511
512
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 510

def supports_migrations?
  true
end

#tablesObject



616
617
618
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 616

def tables
  @connection.tables
end

#write_large_object(*args) ⇒ Object



636
637
638
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 636

def write_large_object(*args)
  @connection.write_large_object(*args)
end