Class: ActiveFacts::Metamodel::ValueType
- Inherits:
-
DomainObjectType
- Object
- ObjectType
- DomainObjectType
- ActiveFacts::Metamodel::ValueType
- Defined in:
- lib/activefacts/persistence/columns.rb,
lib/activefacts/generate/cql.rb,
lib/activefacts/persistence/index.rb,
lib/activefacts/persistence/tables.rb,
lib/activefacts/vocabulary/metamodel.rb,
lib/activefacts/vocabulary/extensions.rb,
lib/activefacts/generate/transform/surrogate.rb
Overview
The ValueType class is defined in the metamodel; full documentation is not generated. This section shows the features relevant to relational Persistence.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from ObjectType
#injected_surrogate_role, #tentative
Instance Method Summary collapse
-
#absorbed_via ⇒ Object
:nodoc:.
-
#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.
- #as_cql ⇒ Object
-
#identifier_columns ⇒ Object
The identifier_columns for a ValueType can only ever be the self-value role that was injected.
- #inject_surrogate ⇒ Object
-
#is_auto_assigned ⇒ Object
Is this ValueType auto-assigned on first save to the database?.
-
#is_table ⇒ Object
Returns true if this ValueType is a table.
- #needs_surrogate ⇒ Object
-
#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.
- #self_index ⇒ Object
-
#self_value_reference ⇒ Object
If someone asks for this, it’s because it’s needed, so create it.
- #subtypes ⇒ Object
- #subtypes_transitive ⇒ Object
- #supertypes_transitive ⇒ Object
Methods inherited from ObjectType
#add_surrogate, #all_absorbed_foreign_key_reference_path, #clear_indices, #clear_references, #columns, #definitely_not_table, #definitely_table, #foreign_keys, #foreign_keys_to, #has_references, #indices, #populate_columns, #populate_indices, #populate_reference, #populate_references, #probably_not_table, #probably_table, #rails_class_name, #rails_name, #rails_singular_name, #references_from, #references_to, #show_tabular
Instance Method Details
#absorbed_via ⇒ Object
:nodoc:
21 22 23 24 |
# File 'lib/activefacts/persistence/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.
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/activefacts/persistence/columns.rb', line 271 def all_columns(excluded_supertypes) #:nodoc: columns = [] debug :columns, "All Columns for #{name}" do if is_table self_value_reference else columns << ActiveFacts::Persistence::Column.new end references_from.each do |ref| debug :columns, "Columns absorbed via #{ref}" do columns += ref.columns({}) end end end columns end |
#as_cql ⇒ Object
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 |
# File 'lib/activefacts/generate/cql.rb', line 617 def as_cql parameters = [ length != 0 || scale != 0 ? length : nil, scale != 0 ? scale : nil ].compact parameters = parameters.length > 0 ? "("+parameters.join(",")+")" : "" "#{name } #{ (is_independent ? '[independent] ' : '') }is written as #{ (supertype || self).name }#{ parameters }#{ unit && " "+unit.name }#{ concept.all_context_note_as_relevant_concept.map do |cn| cn.verbalise end.join("\n") }#{ value_constraint && " "+value_constraint.describe };" end |
#identifier_columns ⇒ Object
The identifier_columns for a ValueType can only ever be the self-value role that was injected
241 242 243 244 245 246 247 248 249 250 |
# File 'lib/activefacts/persistence/columns.rb', line 241 def identifier_columns debug :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 |
#inject_surrogate ⇒ Object
73 74 75 76 |
# File 'lib/activefacts/generate/transform/surrogate.rb', line 73 def inject_surrogate debug :transform_surrogate, "Adding surrogate ID to Value Type #{name}" add_surrogate('Auto Counter', 'ID') end |
#is_auto_assigned ⇒ Object
Is this ValueType auto-assigned on first save to the database?
50 51 52 53 54 55 |
# File 'lib/activefacts/persistence/tables.rb', line 50 def is_auto_assigned # REVISIT: Find a better way to determine AutoCounters (ValueType unary role?) type = self type = type.supertype while type.supertype type.name =~ /^Auto/ end |
#is_table ⇒ Object
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/persistence/tables.rb', line 27 def is_table return @is_table if @is_table != nil # Always a table if marked so: if is_independent debug :absorption, "ValueType #{name} is declared independent" @tentative = false return @is_table = true end # Only a table if it has references (to another ValueType) if !references_from.empty? && !is_auto_assigned debug :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 |
#needs_surrogate ⇒ Object
68 69 70 71 |
# File 'lib/activefacts/generate/transform/surrogate.rb', line 68 def needs_surrogate supertype_names = supertypes_transitive.map(&:name) !(supertype_names.include?('Auto Counter') or supertype_names.include?('Guid') or supertype_names.include?('ID')) 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
254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/activefacts/persistence/columns.rb', line 254 def reference_columns(excluded_supertypes) #:nodoc: debug :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::Persistence::Column.new(ref_from)] else [ActiveFacts::Persistence::Column.new(self_value_reference)] end else [ActiveFacts::Persistence::Column.new] end end end |
#self_index ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/activefacts/persistence/index.rb', line 93 def self_index ActiveFacts::Persistence::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_reference ⇒ Object
If someone asks for this, it’s because it’s needed, so create it.
289 290 291 292 |
# File 'lib/activefacts/persistence/columns.rb', line 289 def self_value_reference #:nodoc: # Make a reference for the self-value column @self_value_reference ||= ActiveFacts::Persistence::Reference.new(self, nil).tabulate end |
#subtypes ⇒ Object
258 259 260 |
# File 'lib/activefacts/vocabulary/extensions.rb', line 258 def subtypes all_value_type_as_supertype end |
#subtypes_transitive ⇒ Object
262 263 264 |
# File 'lib/activefacts/vocabulary/extensions.rb', line 262 def subtypes_transitive [self] + subtypes.map{|st| st.subtypes_transitive}.flatten end |
#supertypes_transitive ⇒ Object
254 255 256 |
# File 'lib/activefacts/vocabulary/extensions.rb', line 254 def supertypes_transitive [self] + (supertype ? supertype.supertypes_transitive : []) end |