Class: ActiveFacts::Metamodel::ValueType

Inherits:
DomainObjectType
  • Object
show all
Defined in:
lib/activefacts/rmap/columns.rb,
lib/activefacts/rmap/index.rb,
lib/activefacts/rmap/tables.rb

Overview

The ValueType class is defined in the metamodel; full documentation is not generated. This section shows the features relevant to relational mapping.

Instance Method Summary collapse

Instance Method Details

#absorbed_viaObject

:nodoc:



21
22
23
24
# File 'lib/activefacts/rmap/tables.rb', line 21

def absorbed_via  #:nodoc:
  # ValueTypes aren't absorbed in the way EntityTypes are
  nil
end

#all_columns(excluded_supertypes) ⇒ Object

When absorbing this ValueType, what columns must be absorbed? This must be a fresh copy, because the columns will have References prepended.



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/activefacts/rmap/columns.rb', line 303

def all_columns(excluded_supertypes)    #:nodoc:
  columns = []
  trace :columns, "All Columns for #{name}" do
    if is_table
      self_value_reference
    else
      columns << ActiveFacts::RMap::Column.new
    end
    references_from.each do |ref|
      trace :columns, "Columns absorbed via #{ref}" do
        columns += ref.columns({})
      end
    end
  end
  columns
end

#identifier_columnsObject

The identifier_columns for a ValueType can only ever be the self-value role that was injected



273
274
275
276
277
278
279
280
281
282
# File 'lib/activefacts/rmap/columns.rb', line 273

def identifier_columns
  trace :columns, "Identifier Columns for #{name}" do
    raise "Illegal call to identifier_columns for absorbed ValueType #{name}" unless is_table
    if isr = injected_surrogate_role
      columns.select{|column| column.references[0].from_role == isr }
    else
      columns.select{|column| column.references[0] == self_value_reference}
    end
  end
end

#is_tableObject

Returns true if this ValueType is a table



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/activefacts/rmap/tables.rb', line 27

def is_table
  return @is_table if @is_table != nil

  # Always a table if marked so:
  if is_separate
    trace :absorption, "ValueType #{name} is declared independent or separate"
    @tentative = false
    return @is_table = true
  end

  # Only a table if it has references (to another ValueType)
  if !references_from.empty? && !is_auto_assigned
    trace :absorption, "#{name} is a table because it has #{references_from.size} references to it"
    @is_table = true
  else
    @is_table = false
  end
  @tentative = false

  @is_table
end

#reference_columns(excluded_supertypes) ⇒ Object

When creating a foreign key to this ValueType, what columns must we include? This must be a fresh copy, because the columns will have References prepended



286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/activefacts/rmap/columns.rb', line 286

def reference_columns(excluded_supertypes)  #:nodoc:
  trace :columns, "Reference Columns for #{name}" do
    if is_table
      if isr = injected_surrogate_role
        ref_from = references_from.detect{|ref| ref.from_role == isr}
        [ActiveFacts::RMap::Column.new(ref_from)]
      else
        [ActiveFacts::RMap::Column.new(self_value_reference)]
      end
    else
      [ActiveFacts::RMap::Column.new]
    end
  end
end

#self_indexObject



93
94
95
96
97
98
99
100
101
# File 'lib/activefacts/rmap/index.rb', line 93

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
  )
end

#self_value_referenceObject

If someone asks for this, it’s because it’s needed, so create it.



321
322
323
324
# File 'lib/activefacts/rmap/columns.rb', line 321

def self_value_reference  #:nodoc:
  # Make a reference for the self-value column
  @self_value_reference ||= ActiveFacts::RMap::Reference.new(self, nil).tabulate
end