Class: Lutaml::Qea::Database
- Inherits:
-
Object
- Object
- Lutaml::Qea::Database
- Defined in:
- lib/lutaml/qea/database.rb
Overview
Database container for all loaded EA models
This class provides a unified container for all EA table collections loaded from a QEA database. It stores collections by name and provides accessor methods, statistics, and lookup functionality.
Instance Attribute Summary collapse
-
#collections ⇒ Hash<Symbol, Array>
readonly
Collections of records by name.
-
#connection ⇒ SQLite3::Database?
Database connection.
-
#qea_path ⇒ String
readonly
Path to the QEA file.
Instance Method Summary collapse
-
#add_collection(name, records) ⇒ void
Add a collection to the database.
-
#attribute_tags ⇒ Array<Models::EaAttributeTag>
Get attribute tags collection.
-
#attributes ⇒ Array<Models::EaAttribute>
Get attributes collection.
-
#collection_names ⇒ Array<Symbol>
Get collection names.
-
#complexity_types ⇒ Array<Models::EaComplexityType>
Get complexity types collection (Priority 3 lookup table).
-
#connector_types ⇒ Array<Models::EaConnectorType>
Get connector types collection (Priority 3 lookup table).
-
#connectors ⇒ Array<Models::EaConnector>
Get connectors collection.
-
#constraint_types ⇒ Array<Models::EaConstraintType>
Get constraint types collection (Priority 3 lookup table).
-
#datatypes ⇒ Array<Models::EaDatatype>
Get datatypes collection.
-
#diagram_links ⇒ Array<Models::EaDiagramLink>
Get diagram links collection (visual routing).
-
#diagram_objects ⇒ Array<Models::EaDiagramObject>
Get diagram objects collection (visual placement).
-
#diagram_types ⇒ Array<Models::EaDiagramType>
Get diagram types collection (Priority 3 lookup table).
-
#diagrams ⇒ Array<Models::EaDiagram>
Get diagrams collection.
-
#documents ⇒ Array<Models::EaDocument>
Get documents collection (Priority 4).
-
#empty? ⇒ Boolean
Check if database is empty.
-
#find_attribute(id) ⇒ Models::EaAttribute?
Find an attribute by ID.
-
#find_connector(id) ⇒ Models::EaConnector?
Find a connector by ID.
-
#find_diagram(id) ⇒ Models::EaDiagram?
Find a diagram by ID.
-
#find_object(id) ⇒ Models::EaObject?
Find an object by ID.
-
#find_package(id) ⇒ Models::EaPackage?
Find a package by ID.
-
#freeze ⇒ self
Freeze all collections to make database immutable.
-
#initialize(qea_path, connection = nil) ⇒ Database
constructor
A new instance of Database.
-
#object_constraints ⇒ Array<Models::EaObjectConstraint>
Get object constraints collection.
-
#object_properties ⇒ Array<Models::EaObjectProperty>
Get object properties collection.
-
#object_types ⇒ Array<Models::EaObjectType>
Get object types collection (Priority 3 lookup table).
-
#objects ⇒ Repositories::ObjectRepository
Get objects collection.
-
#operation_params ⇒ Array<Models::EaOperationParam>
Get operation parameters collection.
-
#operations ⇒ Array<Models::EaOperation>
Get operations collection.
-
#packages ⇒ Array<Models::EaPackage>
Get packages collection.
-
#scripts ⇒ Array<Models::EaScript>
Get scripts collection (Priority 4).
-
#stats ⇒ Hash<String, Integer>
Get statistics for all collections.
-
#status_types ⇒ Array<Models::EaStatusType>
Get status types collection (Priority 3 lookup table).
-
#stereotypes ⇒ Array<Models::EaStereotype>
Get stereotypes collection.
-
#tagged_values ⇒ Array<Models::EaTaggedValue>
Get tagged values collection.
-
#total_records ⇒ Integer
Get total number of records across all collections.
-
#xrefs ⇒ Array<Models::EaXref>
Get cross-references collection.
Constructor Details
#initialize(qea_path, connection = nil) ⇒ Database
Returns a new instance of Database.
30 31 32 33 34 35 |
# File 'lib/lutaml/qea/database.rb', line 30 def initialize(qea_path, connection = nil) @qea_path = qea_path @connection = connection @collections = {} @mutex = Mutex.new end |
Instance Attribute Details
#collections ⇒ Hash<Symbol, Array> (readonly)
Returns Collections of records by name.
22 23 24 |
# File 'lib/lutaml/qea/database.rb', line 22 def collections @collections end |
#connection ⇒ SQLite3::Database?
Returns Database connection.
28 29 30 |
# File 'lib/lutaml/qea/database.rb', line 28 def connection @connection end |
#qea_path ⇒ String (readonly)
Returns Path to the QEA file.
25 26 27 |
# File 'lib/lutaml/qea/database.rb', line 25 def qea_path @qea_path end |
Instance Method Details
#add_collection(name, records) ⇒ void
This method returns an undefined value.
Add a collection to the database
50 51 52 53 54 |
# File 'lib/lutaml/qea/database.rb', line 50 def add_collection(name, records) @mutex.synchronize do @collections[name.to_sym] = records.freeze end end |
#attribute_tags ⇒ Array<Models::EaAttributeTag>
Get attribute tags collection
148 149 150 |
# File 'lib/lutaml/qea/database.rb', line 148 def @collections[:attribute_tags] || [] end |
#attributes ⇒ Array<Models::EaAttribute>
Get attributes collection
70 71 72 |
# File 'lib/lutaml/qea/database.rb', line 70 def attributes @collections[:attributes] || [] end |
#collection_names ⇒ Array<Symbol>
Get collection names
308 309 310 |
# File 'lib/lutaml/qea/database.rb', line 308 def collection_names @collections.keys end |
#complexity_types ⇒ Array<Models::EaComplexityType>
Get complexity types collection (Priority 3 lookup table)
215 216 217 |
# File 'lib/lutaml/qea/database.rb', line 215 def complexity_types @collections[:complexity_types] || [] end |
#connector_types ⇒ Array<Models::EaConnectorType>
Get connector types collection (Priority 3 lookup table)
185 186 187 |
# File 'lib/lutaml/qea/database.rb', line 185 def connector_types @collections[:connector_types] || [] end |
#connectors ⇒ Array<Models::EaConnector>
Get connectors collection
91 92 93 |
# File 'lib/lutaml/qea/database.rb', line 91 def connectors @collections[:connectors] || [] end |
#constraint_types ⇒ Array<Models::EaConstraintType>
Get constraint types collection (Priority 3 lookup table)
177 178 179 |
# File 'lib/lutaml/qea/database.rb', line 177 def constraint_types @collections[:constraint_types] || [] end |
#datatypes ⇒ Array<Models::EaDatatype>
Get datatypes collection
169 170 171 |
# File 'lib/lutaml/qea/database.rb', line 169 def datatypes @collections[:datatypes] || [] end |
#diagram_links ⇒ Array<Models::EaDiagramLink>
Get diagram links collection (visual routing)
119 120 121 |
# File 'lib/lutaml/qea/database.rb', line 119 def diagram_links @collections[:diagram_links] || [] end |
#diagram_objects ⇒ Array<Models::EaDiagramObject>
Get diagram objects collection (visual placement)
112 113 114 |
# File 'lib/lutaml/qea/database.rb', line 112 def diagram_objects @collections[:diagram_objects] || [] end |
#diagram_types ⇒ Array<Models::EaDiagramType>
Get diagram types collection (Priority 3 lookup table)
193 194 195 |
# File 'lib/lutaml/qea/database.rb', line 193 def diagram_types @collections[:diagram_types] || [] end |
#diagrams ⇒ Array<Models::EaDiagram>
Get diagrams collection
105 106 107 |
# File 'lib/lutaml/qea/database.rb', line 105 def diagrams @collections[:diagrams] || [] end |
#documents ⇒ Array<Models::EaDocument>
Get documents collection (Priority 4)
222 223 224 |
# File 'lib/lutaml/qea/database.rb', line 222 def documents @collections[:documents] || [] end |
#empty? ⇒ Boolean
Check if database is empty
301 302 303 |
# File 'lib/lutaml/qea/database.rb', line 301 def empty? @collections.empty? || total_records.zero? end |
#find_attribute(id) ⇒ Models::EaAttribute?
Find an attribute by ID
278 279 280 |
# File 'lib/lutaml/qea/database.rb', line 278 def find_attribute(id) attributes.find { |attr| attr.id == id } end |
#find_connector(id) ⇒ Models::EaConnector?
Find a connector by ID
286 287 288 |
# File 'lib/lutaml/qea/database.rb', line 286 def find_connector(id) connectors.find { |conn| conn.connector_id == id } end |
#find_diagram(id) ⇒ Models::EaDiagram?
Find a diagram by ID
294 295 296 |
# File 'lib/lutaml/qea/database.rb', line 294 def find_diagram(id) diagrams.find { |diag| diag.diagram_id == id } end |
#find_object(id) ⇒ Models::EaObject?
Find an object by ID
262 263 264 |
# File 'lib/lutaml/qea/database.rb', line 262 def find_object(id) objects.find_by_key(:ea_object_id, id) end |
#find_package(id) ⇒ Models::EaPackage?
Find a package by ID
270 271 272 |
# File 'lib/lutaml/qea/database.rb', line 270 def find_package(id) packages.find { |pkg| pkg.package_id == id } end |
#freeze ⇒ self
Freeze all collections to make database immutable
315 316 317 318 319 320 321 |
# File 'lib/lutaml/qea/database.rb', line 315 def freeze # Memoize repositories before freezing objects @collections.freeze super end |
#object_constraints ⇒ Array<Models::EaObjectConstraint>
Get object constraints collection
127 128 129 |
# File 'lib/lutaml/qea/database.rb', line 127 def object_constraints @collections[:object_constraints] || [] end |
#object_properties ⇒ Array<Models::EaObjectProperty>
Get object properties collection
141 142 143 |
# File 'lib/lutaml/qea/database.rb', line 141 def object_properties @collections[:object_properties] || [] end |
#object_types ⇒ Array<Models::EaObjectType>
Get object types collection (Priority 3 lookup table)
200 201 202 |
# File 'lib/lutaml/qea/database.rb', line 200 def object_types @collections[:object_types] || [] end |
#objects ⇒ Repositories::ObjectRepository
Get objects collection
59 60 61 62 63 64 65 |
# File 'lib/lutaml/qea/database.rb', line 59 def objects return @objects if defined?(@objects) @objects = Repositories::ObjectRepository.new( @collections[:objects] || [], ) end |
#operation_params ⇒ Array<Models::EaOperationParam>
Get operation parameters collection
84 85 86 |
# File 'lib/lutaml/qea/database.rb', line 84 def operation_params @collections[:operation_params] || [] end |
#operations ⇒ Array<Models::EaOperation>
Get operations collection
77 78 79 |
# File 'lib/lutaml/qea/database.rb', line 77 def operations @collections[:operations] || [] end |
#packages ⇒ Array<Models::EaPackage>
Get packages collection
98 99 100 |
# File 'lib/lutaml/qea/database.rb', line 98 def packages @collections[:packages] || [] end |
#scripts ⇒ Array<Models::EaScript>
Get scripts collection (Priority 4)
229 230 231 |
# File 'lib/lutaml/qea/database.rb', line 229 def scripts @collections[:scripts] || [] end |
#stats ⇒ Hash<String, Integer>
Get statistics for all collections
245 246 247 248 249 |
# File 'lib/lutaml/qea/database.rb', line 245 def stats @collections.each_with_object({}) do |(name, records), hash| hash[name.to_s] = records.size end end |
#status_types ⇒ Array<Models::EaStatusType>
Get status types collection (Priority 3 lookup table)
207 208 209 |
# File 'lib/lutaml/qea/database.rb', line 207 def status_types @collections[:status_types] || [] end |
#stereotypes ⇒ Array<Models::EaStereotype>
Get stereotypes collection
162 163 164 |
# File 'lib/lutaml/qea/database.rb', line 162 def stereotypes @collections[:stereotypes] || [] end |
#tagged_values ⇒ Array<Models::EaTaggedValue>
Get tagged values collection
134 135 136 |
# File 'lib/lutaml/qea/database.rb', line 134 def tagged_values @collections[:tagged_values] || [] end |
#total_records ⇒ Integer
Get total number of records across all collections
254 255 256 |
# File 'lib/lutaml/qea/database.rb', line 254 def total_records @collections.values.sum(&:size) end |
#xrefs ⇒ Array<Models::EaXref>
Get cross-references collection
155 156 157 |
# File 'lib/lutaml/qea/database.rb', line 155 def xrefs @collections[:xrefs] || [] end |