Class: Mkxms::Mssql::Index

Inherits:
Object
  • Object
show all
Extended by:
Utils::FlagsQueries
Includes:
ExtendedProperties, Property::Hosting
Defined in:
lib/mkxms/mssql/index_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::FlagsQueries

flags_query

Methods included from ExtendedProperties

#extended_properties

Methods included from Property::Hosting

#extended_properties_sql

Constructor Details

#initialize(attrs) ⇒ Index

Returns a new instance of Index.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mkxms/mssql/index_handler.rb', line 11

def initialize(attrs)
  @schema = attrs['schema']
  @relation = attrs['relation']
  @name = attrs['name']
  @fill_factor = attrs['fill-factor']
  @spatial_index_geometry = attrs['spatial-index-over']
  @cells_per_object = attrs['cells-per-object']
  @storage = attrs['stored-on']
  @columns = []
  @included_columns = []
  
  @flags = []
  @flags << :unique if attrs['unique']
  @flags << :padded if attrs['padded']
  @flags << :disabled if attrs['disabled']
  @flags << :ignore_duplicates if attrs['ignore-duplicates']
  @flags << :row_locks_prohibited if attrs['no-row-locks']
  @flags << :page_locks_prohibited if attrs['no-page-locks']
end

Instance Attribute Details

#cells_per_objectObject

Returns the value of attribute cells_per_object.



31
32
33
# File 'lib/mkxms/mssql/index_handler.rb', line 31

def cells_per_object
  @cells_per_object
end

#columnsObject (readonly)

Returns the value of attribute columns.



32
33
34
# File 'lib/mkxms/mssql/index_handler.rb', line 32

def columns
  @columns
end

#fill_factorObject

Returns the value of attribute fill_factor.



31
32
33
# File 'lib/mkxms/mssql/index_handler.rb', line 31

def fill_factor
  @fill_factor
end

#flagsObject (readonly)

Returns the value of attribute flags.



32
33
34
# File 'lib/mkxms/mssql/index_handler.rb', line 32

def flags
  @flags
end

#included_columnsObject (readonly)

Returns the value of attribute included_columns.



32
33
34
# File 'lib/mkxms/mssql/index_handler.rb', line 32

def included_columns
  @included_columns
end

#nameObject

Returns the value of attribute name.



31
32
33
# File 'lib/mkxms/mssql/index_handler.rb', line 31

def name
  @name
end

#relationObject

Returns the value of attribute relation.



31
32
33
# File 'lib/mkxms/mssql/index_handler.rb', line 31

def relation
  @relation
end

#schemaObject

Returns the value of attribute schema.



31
32
33
# File 'lib/mkxms/mssql/index_handler.rb', line 31

def schema
  @schema
end

#spatial_index_geometryObject

Returns the value of attribute spatial_index_geometry.



31
32
33
# File 'lib/mkxms/mssql/index_handler.rb', line 31

def spatial_index_geometry
  @spatial_index_geometry
end

#storageObject

Returns the value of attribute storage.



31
32
33
# File 'lib/mkxms/mssql/index_handler.rb', line 31

def storage
  @storage
end

Instance Method Details

#property_subject_identifiersObject



64
65
66
# File 'lib/mkxms/mssql/index_handler.rb', line 64

def property_subject_identifiers
  ['SCHEMA', @schema, 'TABLE', @relation, 'INDEX', @name].map {|n| Utils.unquoted_name(n)}
end

#qualified_relationObject



68
69
70
# File 'lib/mkxms/mssql/index_handler.rb', line 68

def qualified_relation
  [@schema, @relation].join '.'
end

#to_sqlObject



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
62
# File 'lib/mkxms/mssql/index_handler.rb', line 36

def to_sql
  if @spatial_index_geometry
  else
    [].tap do |parts|
      parts << "CREATE #{'UNIQUE ' if unique?}INDEX #@name ON #{qualified_relation} (\n" +
      @columns.map(&:to_sql).join(', ') +
      "\n)"
      
      parts << "INCLUDE (\n" +
      @included_columns.map(&:name).join(', ') +
      "\n)" unless @included_columns.empty?
      
      # TODO: "WHERE" clause
      
      options = []
      options << "PAD_INDEX = ON" if padded?
      options << "FILLFACTOR = #@fill_factor" if @fill_factor
      options << "IGNORE_DUP_KEY = ON" if ignore_duplicates?
      options << "ALLOW_ROW_LOCKS = OFF" if row_locks_prohibited?
      options << "ALLOW_PAGE_LOCKS = OFF" if page_locks_prohibited?
      parts << "WITH (#{options.join(', ')})" unless options.empty?
      
      parts << "ON #@storage" if @storage
      
    end.join(' ') + ';' + extended_properties_sql.joined_on_new_lines
  end
end