Class/Module Index [+]

Quicksearch

RR::ConnectionExtenders::JdbcSQLExtender

Provides various JDBC specific functionality required by Rubyrep.

Public Instance Methods

disconnect!() click to toggle source

Monkey patch for activerecord-jdbc-adapter-0.7.2 as it doesn’t set the +@active+ flag to false, thus ActiveRecord#active? incorrectly confirms the connection to still be active.

# File lib/rubyrep/connection_extenders/jdbc_extender.rb, line 13
def disconnect!
  super
  @active = false
end
primary_key_names(table) click to toggle source

Returns an ordered list of primary key column names of the given table

# File lib/rubyrep/connection_extenders/jdbc_extender.rb, line 19
def primary_key_names(table)
  if tables.grep(/^#{table}$/).empty?
    # Note: Cannot use tables.include? as returned tables are made lowercase under JRuby MySQL
    raise "table '#{table}' does not exist"
  end
  columns = []
  result_set = @connection.connection.getMetaData.getPrimaryKeys(nil, nil, table);
  while result_set.next
    column_name = result_set.getString("COLUMN_NAME")
    key_seq = result_set.getShort("KEY_SEQ")
    columns << {:column_name => column_name, :key_seq => key_seq}
  end
  columns.sort! {|a, b| a[:key_seq] <=> b[:key_seq]}
  key_names = columns.map {|column| column[:column_name]}
  key_names
end
referenced_tables(tables) click to toggle source

Returns for each given table, which other tables it references via foreign key constraints.

  • tables: an array of table names

  • returns: a hash with

    • key: name of the referencing table

    • value: an array of names of referenced tables

# File lib/rubyrep/connection_extenders/jdbc_extender.rb, line 42
def referenced_tables(tables)
  result = {}
  tables.each do |table|
    references_of_this_table = []
    result_set = @connection.connection.getMetaData.getImportedKeys(nil, nil, table)
    while result_set.next
      referenced_table = result_set.getString("PKTABLE_NAME")
      unless references_of_this_table.include? referenced_table
        references_of_this_table << referenced_table
      end
    end
    result[table] = references_of_this_table
  end
  result
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.