Class: ActiveRecord::ConnectionAdapters::JdbcAdapter
Defined Under Namespace
Modules: CompatibilityMethods, ConnectionPoolCallbacks, JndiConnectionPoolCallbacks, ShadowCoreMethods
Constant Summary
collapse
- ADAPTER_TYPES =
::JdbcSpec.constants.map{|c|
::JdbcSpec.const_get c }.select{ |c|
c.respond_to? :adapter_selector }.map{|c|
c.adapter_selector }.inject({}) { |h,val|
h[val[0]] = val[1]; h }
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
-
#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_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
-
#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.
488
489
490
491
492
493
494
495
496
497
498
499
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 488
def initialize(connection, logger, config)
super(connection, logger)
@config = config
dialect = config[:dialect] || config[:driver]
for reg, func in ADAPTER_TYPES
if reg === dialect.to_s
func.call(@config,self)
end
end
connection.adapter = self
JndiConnectionPoolCallbacks.prepare(self, connection)
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
480
481
482
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 480
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.
589
590
591
592
593
594
595
596
597
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 589
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
505
506
507
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 505
def adapter_name 'JDBC'
end
|
#begin_db_transaction ⇒ Object
623
624
625
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 623
def begin_db_transaction
@connection.begin
end
|
#commit_db_transaction ⇒ Object
627
628
629
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 627
def commit_db_transaction
@connection.commit
end
|
#database_name ⇒ Object
517
518
519
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 517
def database_name @connection.database_name
end
|
#disconnect! ⇒ Object
561
562
563
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 561
def disconnect!
@connection.disconnect!
end
|
#execute(sql, name = nil) ⇒ Object
580
581
582
583
584
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 580
def execute(sql, name = nil)
log(sql, name) do
_execute(sql,name)
end
end
|
#indexes(table_name, name = nil, schema_name = nil) ⇒ Object
619
620
621
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 619
def indexes(table_name, name = nil, schema_name = nil)
@connection.indexes(table_name, name, schema_name)
end
|
#jdbc_columns(table_name, name = nil) ⇒ Object
610
611
612
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 610
def jdbc_columns(table_name, name = nil)
@connection.columns(table_name.to_s)
end
|
#jdbc_insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) ⇒ Object
604
605
606
607
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 604
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
565
566
567
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 565
def jdbc_select_all(sql, name = nil)
select(sql, name)
end
|
#jdbc_update(sql, name = nil) ⇒ Object
599
600
601
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 599
def jdbc_update(sql, name = nil) execute(sql, name)
end
|
#modify_types(tp) ⇒ Object
501
502
503
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 501
def modify_types(tp)
tp
end
|
#native_database_types ⇒ Object
513
514
515
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 513
def native_database_types @connection.native_database_types
end
|
#native_sql_to_type(tp) ⇒ Object
521
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
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 521
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
|
#reconnect! ⇒ Object
556
557
558
559
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 556
def reconnect!
@connection.reconnect!
@connection
end
|
#rollback_db_transaction ⇒ Object
631
632
633
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 631
def rollback_db_transaction
@connection.rollback
end
|
#select_one(sql, name = nil) ⇒ Object
576
577
578
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 576
def select_one(sql, name = nil)
select(sql, name).first
end
|
#select_rows(sql, name = nil) ⇒ Object
570
571
572
573
574
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 570
def select_rows(sql, name = nil)
rows = []
select(sql, name).each {|row| rows << row.values }
rows
end
|
#supports_migrations? ⇒ Boolean
509
510
511
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 509
def supports_migrations?
true
end
|
#tables ⇒ Object
615
616
617
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 615
def tables
@connection.tables
end
|
#write_large_object(*args) ⇒ Object
635
636
637
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 635
def write_large_object(*args)
@connection.write_large_object(*args)
end
|