Class: ActiveRecord::ConnectionAdapters::JdbcAdapter
Defined Under Namespace
Modules: CompatibilityMethods, ConnectionPoolCallbacks, JndiConnectionPoolCallbacks, ShadowCoreMethods
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#_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.
-
#adapter_name ⇒ Object
-
#adapter_spec(config) ⇒ Object
Locate specialized adapter specification if one exists based on config data.
-
#begin_db_transaction ⇒ Object
-
#commit_db_transaction ⇒ Object
-
#database_name ⇒ Object
-
#disconnect! ⇒ Object
-
#execute(sql, name = nil) ⇒ Object
-
#indexes(table_name, name = nil, schema_name = nil) ⇒ Object
-
#initialize(connection, logger, config) ⇒ JdbcAdapter
constructor
A new instance of JdbcAdapter.
-
#jdbc_columns(table_name, name = nil) ⇒ Object
-
#jdbc_connection_class(spec) ⇒ Object
-
#jdbc_insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object
-
#jdbc_select_all(sql, name = nil) ⇒ Object
-
#jdbc_update(sql, name = nil) ⇒ Object
-
#modify_types(tp) ⇒ Object
-
#native_database_types ⇒ Object
-
#native_sql_to_type(tp) ⇒ Object
-
#pk_and_sequence_for(table) ⇒ Object
-
#primary_key(table) ⇒ Object
-
#primary_keys(table) ⇒ Object
-
#reconnect! ⇒ Object
-
#rollback_db_transaction ⇒ Object
-
#select_one(sql, name = nil) ⇒ Object
-
#select_rows(sql, name = nil) ⇒ Object
-
#supports_migrations? ⇒ Boolean
-
#tables ⇒ Object
-
#write_large_object(*args) ⇒ Object
alias_chained_method
included, needed?, #on_checkin, #on_checkout
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
#config ⇒ Object
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_name ⇒ Object
506
507
508
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 506
def adapter_name '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_transaction ⇒ Object
624
625
626
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 624
def begin_db_transaction
@connection.begin
end
|
#commit_db_transaction ⇒ Object
628
629
630
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 628
def commit_db_transaction
@connection.commit
end
|
#database_name ⇒ Object
518
519
520
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 518
def database_name @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
600
601
602
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 600
def jdbc_update(sql, name = nil) 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_types ⇒ Object
514
515
516
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 514
def native_database_types @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_transaction ⇒ Object
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
510
511
512
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 510
def supports_migrations?
true
end
|
#tables ⇒ Object
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
|