lib/activefacts/rmap/index.rb in activefacts-rmap-1.8.1 vs lib/activefacts/rmap/index.rb in activefacts-rmap-1.8.2

- old
+ new

@@ -67,46 +67,46 @@ def view_name "#{over.name.gsub(' ','')}#{on == over ? "" : "In"+on.name.gsub(' ','')}" end def to_s #:nodoc: - if @uniqueness_constraint - name = @uniqueness_constraint.name - preferred = @uniqueness_constraint.is_preferred_identifier ? " (preferred)" : "" - else - name = "#{@on.name}IsUnique" - preferred = !@on.injected_surrogate_role ? " (preferred)" : "" - end + if @uniqueness_constraint + name = @uniqueness_constraint.name + preferred = @uniqueness_constraint.is_preferred_identifier ? " (preferred)" : "" + else + name = "#{@on.name}IsUnique" + preferred = !@on.injected_surrogate_role ? " (preferred)" : "" + end colnames = @columns.map(&:name)*", " "Index #{name} on #{@on.name} over #{@over.name}(#{colnames})#{preferred}" end end end module Metamodel #:nodoc: class EntityType def self_index - nil + nil end end class ValueType def self_index - ActiveFacts::RMap::Index.new( - nil, # The implied uniqueness constraint is not created - self, # ValueType being indexed - self, # Absorbed object being indexed - columns.select{|c| c.references[0].is_self_value}, - injected_surrogate_role ? false : true - ) + ActiveFacts::RMap::Index.new( + nil, # The implied uniqueness constraint is not created + self, # ValueType being indexed + self, # Absorbed object being indexed + columns.select{|c| c.references[0].is_self_value}, + injected_surrogate_role ? false : true + ) end end class ObjectType # An array of each Index for this table def indices - @indices || populate_indices + @indices || populate_indices end def clear_indices #:nodoc: # Clear any previous indices @indices = nil @@ -144,11 +144,11 @@ ref_path.each do |ref| next unless ref.to_role # trace :index2, "Considering #{ref_path.map(&:to_s)*" and "} yielding columns #{all_column_by_ref_path[ref_path].map{|c| c.name('.')}*", "}" ref.to_role.all_role_ref.each do |role_ref| all_pcs = role_ref.role_sequence.all_presence_constraint - # puts "pcs over #{ref_path.map{|r| r.to_names}.flatten*'.'}: #{role_ref.role_sequence.all_presence_constraint.map(&:describe)*"; "}" if all_pcs.size > 0 + # puts "pcs over #{ref_path.map{|r| r.to_names}.flatten*'.'}: #{role_ref.role_sequence.all_presence_constraint.map(&:describe)*"; "}" if all_pcs.size > 0 pcs = all_pcs. reject do |pc| !pc.max_frequency or # No maximum freq; cannot be a uniqueness constraint pc.max_frequency != 1 or # maximum is not 1 # Constraint is not over a unary fact type role (NORMA does this) @@ -177,16 +177,16 @@ columns = columns_with_ordinal.sort_by{|ca| [ca[0,2], ca[2].name]}.map{|ca| ca[2]} absorption_level = columns.map(&:absorption_level).min over = columns[0].references[absorption_level].from # Absorption through a one-to-one forms a UC that we don't need to enforce using an index: - if over != self and + if over != self and over.absorbed_via == columns[0].references[absorption_level-1] and (rr = uc.role_sequence.all_role_ref.single) and over.absorbed_via.fact_type.all_role.include?(rr.role) - next nil - end + next nil + end index = ActiveFacts::RMap::Index.new( uc, self, over, @@ -200,12 +200,12 @@ sort_by do |index| # Put the indices in a defined order: index.columns.map(&:name)+['', index.over.name] end end - si = self_index - @indices.unshift(si) if si - @indices + si = self_index + @indices.unshift(si) if si + @indices end end class Vocabulary