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
-
#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.
453
454
455
456
457
458
459
460
461
462
463
464
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 453
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.
451
452
453
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 451
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.
572
573
574
575
576
577
578
579
580
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 572
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
488
489
490
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 488
def adapter_name 'JDBC'
end
|
#adapter_spec(config) ⇒ Object
Locate specialized adapter specification if one exists based on config data
473
474
475
476
477
478
479
480
481
482
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 473
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
606
607
608
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 606
def begin_db_transaction
@connection.begin
end
|
#commit_db_transaction ⇒ Object
610
611
612
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 610
def commit_db_transaction
@connection.commit
end
|
#database_name ⇒ Object
500
501
502
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 500
def database_name @connection.database_name
end
|
#disconnect! ⇒ Object
544
545
546
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 544
def disconnect!
@connection.disconnect!
end
|
#execute(sql, name = nil) ⇒ Object
563
564
565
566
567
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 563
def execute(sql, name = nil)
log(sql, name) do
_execute(sql,name)
end
end
|
#indexes(table_name, name = nil, schema_name = nil) ⇒ Object
602
603
604
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 602
def indexes(table_name, name = nil, schema_name = nil)
@connection.indexes(table_name, name, schema_name)
end
|
#jdbc_columns(table_name, name = nil) ⇒ Object
593
594
595
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 593
def jdbc_columns(table_name, name = nil)
@connection.columns(table_name.to_s)
end
|
#jdbc_connection_class(spec) ⇒ Object
466
467
468
469
470
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 466
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
587
588
589
590
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 587
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
548
549
550
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 548
def jdbc_select_all(sql, name = nil)
select(sql, name)
end
|
#jdbc_update(sql, name = nil) ⇒ Object
582
583
584
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 582
def jdbc_update(sql, name = nil) execute(sql, name)
end
|
#modify_types(tp) ⇒ Object
484
485
486
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 484
def modify_types(tp)
tp
end
|
#native_database_types ⇒ Object
496
497
498
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 496
def native_database_types @connection.native_database_types
end
|
#native_sql_to_type(tp) ⇒ Object
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 504
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
622
623
624
625
626
627
628
629
630
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 622
def pk_and_sequence_for(table)
result_set = @connection.connection.get_meta_data.get_primary_keys(nil, nil, table)
if result_set.next
keys = [result_set.getString("COLUMN_NAME"), nil]
end
keys.blank? ? nil : keys
ensure
result_set.close
end
|
#reconnect! ⇒ Object
539
540
541
542
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 539
def reconnect!
@connection.reconnect!
@connection
end
|
#rollback_db_transaction ⇒ Object
614
615
616
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 614
def rollback_db_transaction
@connection.rollback
end
|
#select_one(sql, name = nil) ⇒ Object
559
560
561
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 559
def select_one(sql, name = nil)
select(sql, name).first
end
|
#select_rows(sql, name = nil) ⇒ Object
553
554
555
556
557
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 553
def select_rows(sql, name = nil)
rows = []
select(sql, name).each {|row| rows << row.values }
rows
end
|
#supports_migrations? ⇒ Boolean
492
493
494
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 492
def supports_migrations?
true
end
|
#tables ⇒ Object
598
599
600
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 598
def tables
@connection.tables
end
|
#write_large_object(*args) ⇒ Object
618
619
620
|
# File 'lib/active_record/connection_adapters/jdbc_adapter.rb', line 618
def write_large_object(*args)
@connection.write_large_object(*args)
end
|