Class: ActiveRecord::ConnectionAdapters::SQLServer::SchemaCache

Inherits:
ActiveRecord::ConnectionAdapters::SchemaCache
  • Object
show all
Defined in:
lib/active_record/connection_adapters/sqlserver/schema_cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(conn) ⇒ SchemaCache

Returns a new instance of SchemaCache.



6
7
8
9
10
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 6

def initialize(conn)
  super
  @views = {}
  @view_information = {}
end

Instance Method Details

#clear!Object



43
44
45
46
47
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 43

def clear!
  super
  @views.clear
  @view_information.clear
end

#clear_table_cache!(table_name) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 53

def clear_table_cache!(table_name)
  name = key(table_name)
  @columns.delete name
  @columns_hash.delete name
  @primary_keys.delete name
  @tables.delete name
  @views.delete name
  @view_information.delete name
end

#columns(table_name) ⇒ Object



31
32
33
34
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 31

def columns(table_name)
  name = key(table_name)
  @columns[name] ||= connection.columns(table_name)
end

#columns_hash(table_name) ⇒ Object



36
37
38
39
40
41
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 36

def columns_hash(table_name)
  name = key(table_name)
  @columns_hash[name] ||= Hash[columns(table_name).map { |col|
    [col.name, col]
  }]
end

#marshal_dumpObject



63
64
65
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 63

def marshal_dump
  super + [@views, @view_information]
end

#marshal_load(array) ⇒ Object



67
68
69
70
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 67

def marshal_load(array)
  @views, @view_information = array[-2..-1]
  super(array[0..-3])
end

#primary_keys(table_name) ⇒ Object

Superclass Overrides



14
15
16
17
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 14

def primary_keys(table_name)
  name = key(table_name)
  @primary_keys[name] ||= table_exists?(table_name) ? connection.primary_key(table_name) : nil
end

#sizeObject



49
50
51
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 49

def size
  super + [@views, @view_information].map{ |x| x.size }.inject(:+)
end

#table_exists?(table_name) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 19

def table_exists?(table_name)
  name = key(table_name)
  prepare_tables_and_views
  return @tables[name] if @tables.key? name
  table_exists = @tables[name] = connection.table_exists?(table_name)
  table_exists || view_exists?(table_name)
end

#tables(name) ⇒ Object



27
28
29
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 27

def tables(name)
  super(key(name))
end

#view_exists?(table_name) ⇒ Boolean

SQL Server Specific

Returns:

  • (Boolean)


74
75
76
77
78
79
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 74

def view_exists?(table_name)
  name = key(table_name)
  prepare_tables_and_views
  return @views[name] if @views.key? name
  @views[name] = connection.views.include?(table_name)
end

#view_information(table_name) ⇒ Object



81
82
83
84
85
# File 'lib/active_record/connection_adapters/sqlserver/schema_cache.rb', line 81

def view_information(table_name)
  name = key(table_name)
  return @view_information[name] if @view_information.key? name
  @view_information[name] = connection.send(:view_information, table_name)
end