Module: Rubeus::Extensions::Java::Sql::DatabaseMetaData

Defined in:
lib/rubeus/extensions/java/sql/database_meta_data.rb

Instance Method Summary collapse

Instance Method Details

#getTables_with_rubeus(*args, &block) ⇒ Object Also known as: tables



12
13
14
15
16
17
# File 'lib/rubeus/extensions/java/sql/database_meta_data.rb', line 12

def getTables_with_rubeus(*args, &block)
  case args.length
    when 0, 1 then table_objects(*args, &block)
    else getTables_without_rubeus(*args, &block)
  end
end

#included(mod) ⇒ Object



5
6
7
8
9
10
# File 'lib/rubeus/extensions/java/sql/database_meta_data.rb', line 5

def included(mod)
  mod.module_eval do 
    alias_method :getTables_without_rubeus, :getTables
    alias_method :getTables, :getTables_with_rubeus
  end
end

#table_object(table_name, options = nil) ⇒ Object Also known as: table



20
21
22
23
# File 'lib/rubeus/extensions/java/sql/database_meta_data.rb', line 20

def table_object(table_name, options = nil)
  options = {:table_name_pattern => table_name}.update(options || {})
  table_objects(options).first
end

#table_objects(options = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rubeus/extensions/java/sql/database_meta_data.rb', line 26

def table_objects(options = nil)
  options = {
    :catalog => nil, 
    :schema => nil,
    :schema_pattern => nil,
    :table => nil,
    :table_name => nil,
    :table_name_pattern => nil,
    :name_case => nil # nil, :downcase, :upcase
  }.update(options || {})
  catalog = options[:catalog] 
  schema_pattern = options[:schema_pattern] || options[:schema]
  table_name_pattern = options[:table_name_pattern] || options[:table_name] || options[:table]
  
  @table_objects ||= {}
  unless table_name_pattern.nil?
    key = [catalog, schema_pattern, table_name_pattern].map{|s| s.nil? ? nil : s.to_s.upcase}
    cached = @table_objects[key]
    return [cached] if cached
  end
  
  tables = getTables(catalog, schema_pattern, table_name_pattern, nil).map do |rs|
    Rubeus::Jdbc::Table.new(self, rs.to_hash, options)
  end
  tables = Rubeus::Util::NameAccessArray.new(*tables)
  
  columns = getColumns(catalog, schema_pattern, table_name_pattern, nil).map{|r| r.to_hash}
  tables.each do |table|
    table.columns = Rubeus::Util::NameAccessArray.new(
      *columns.
      select{|hash|table.same_fqn?(hash)}.
      map{|hash| Rubeus::Jdbc::Column.new(self, table, hash, options)})
  end
  tables.each{|t| @table_objects[t.fqn] = t}
  tables
end