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.
Constant Summary collapse
- COLLECTION_ACCESSORS =
%i[ attributes operations operation_params connectors packages diagrams diagram_objects diagram_links object_constraints tagged_values object_properties attribute_tags xrefs stereotypes datatypes constraint_types connector_types diagram_types object_types status_types complexity_types documents scripts ].freeze
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.
- #attributes_for_object(id) ⇒ Object
- #child_packages_for(id) ⇒ Object
-
#collection_names ⇒ Array<Symbol>
Get collection names.
-
#connectors_for_object(object_id) ⇒ Object
Get connectors involving a specific object (start or end).
- #diagram_links_for(id) ⇒ Object
- #diagram_objects_for(id) ⇒ Object
- #diagrams_in_package(id) ⇒ Object
-
#empty? ⇒ Boolean
Check if database is empty.
- #find_attribute(id) ⇒ Object
- #find_connector(id) ⇒ Object
- #find_diagram(id) ⇒ Object
-
#find_object(id) ⇒ Object
Find an object by ID.
-
#find_object_by_guid(ea_guid) ⇒ Object
Find object by ea_guid.
- #find_package(id) ⇒ Object
-
#freeze ⇒ self
Freeze all collections to make database immutable.
-
#initialize(qea_path, connection = nil) ⇒ Database
constructor
A new instance of Database.
-
#objects ⇒ Repositories::ObjectRepository
Get objects collection (special: wrapped in ObjectRepository).
- #objects_in_package(id) ⇒ Object
- #operation_params_for(id) ⇒ Object
- #operations_for_object(id) ⇒ Object
-
#stats ⇒ Hash<String, Integer>
Get statistics for all collections.
-
#total_records ⇒ Integer
Get total number of records across all collections.
Constructor Details
#initialize(qea_path, connection = nil) ⇒ Database
Returns a new instance of Database.
28 29 30 31 32 33 |
# File 'lib/lutaml/qea/database.rb', line 28 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.
20 21 22 |
# File 'lib/lutaml/qea/database.rb', line 20 def collections @collections end |
#connection ⇒ SQLite3::Database?
Returns Database connection.
26 27 28 |
# File 'lib/lutaml/qea/database.rb', line 26 def connection @connection end |
#qea_path ⇒ String (readonly)
Returns Path to the QEA file.
23 24 25 |
# File 'lib/lutaml/qea/database.rb', line 23 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
48 49 50 51 52 |
# File 'lib/lutaml/qea/database.rb', line 48 def add_collection(name, records) @mutex.synchronize do @collections[name.to_sym] = records.freeze end end |
#attributes_for_object(id) ⇒ Object
125 126 127 128 |
# File 'lib/lutaml/qea/database.rb', line 125 def attributes_for_object(id) ensure_lookup_indexes @attributes_by_object_id[id] || [] end |
#child_packages_for(id) ⇒ Object
140 141 142 143 |
# File 'lib/lutaml/qea/database.rb', line 140 def child_packages_for(id) ensure_lookup_indexes @packages_by_parent[id] || [] end |
#collection_names ⇒ Array<Symbol>
Get collection names
193 194 195 |
# File 'lib/lutaml/qea/database.rb', line 193 def collection_names @collections.keys end |
#connectors_for_object(object_id) ⇒ Object
Get connectors involving a specific object (start or end)
177 178 179 180 181 |
# File 'lib/lutaml/qea/database.rb', line 177 def connectors_for_object(object_id) ensure_lookup_indexes (@connectors_by_start[object_id] || []) + (@connectors_by_end[object_id] || []) end |
#diagram_links_for(id) ⇒ Object
160 161 162 163 |
# File 'lib/lutaml/qea/database.rb', line 160 def diagram_links_for(id) ensure_lookup_indexes @diagram_links_by_id[id] || [] end |
#diagram_objects_for(id) ⇒ Object
155 156 157 158 |
# File 'lib/lutaml/qea/database.rb', line 155 def diagram_objects_for(id) ensure_lookup_indexes @diagram_objects_by_id[id] || [] end |
#diagrams_in_package(id) ⇒ Object
150 151 152 153 |
# File 'lib/lutaml/qea/database.rb', line 150 def diagrams_in_package(id) ensure_lookup_indexes @diagrams_by_package_id[id] || [] end |
#empty? ⇒ Boolean
Check if database is empty
186 187 188 |
# File 'lib/lutaml/qea/database.rb', line 186 def empty? @collections.empty? || total_records.zero? end |
#find_attribute(id) ⇒ Object
110 111 112 113 |
# File 'lib/lutaml/qea/database.rb', line 110 def find_attribute(id) ensure_lookup_indexes @attributes_by_id[id] end |
#find_connector(id) ⇒ Object
115 116 117 118 |
# File 'lib/lutaml/qea/database.rb', line 115 def find_connector(id) ensure_lookup_indexes @connectors_by_id[id] end |
#find_diagram(id) ⇒ Object
120 121 122 123 |
# File 'lib/lutaml/qea/database.rb', line 120 def find_diagram(id) ensure_lookup_indexes @diagrams_by_id[id] end |
#find_object(id) ⇒ Object
Find an object by ID
166 167 168 |
# File 'lib/lutaml/qea/database.rb', line 166 def find_object(id) objects.find_by_key(:ea_object_id, id) end |
#find_object_by_guid(ea_guid) ⇒ Object
Find object by ea_guid
171 172 173 174 |
# File 'lib/lutaml/qea/database.rb', line 171 def find_object_by_guid(ea_guid) ensure_lookup_indexes @objects_by_guid[ea_guid] end |
#find_package(id) ⇒ Object
105 106 107 108 |
# File 'lib/lutaml/qea/database.rb', line 105 def find_package(id) ensure_lookup_indexes @packages_by_id[id] end |
#freeze ⇒ self
Freeze all collections to make database immutable
200 201 202 203 204 205 |
# File 'lib/lutaml/qea/database.rb', line 200 def freeze objects ensure_lookup_indexes @collections.freeze super end |
#objects ⇒ Repositories::ObjectRepository
Get objects collection (special: wrapped in ObjectRepository)
72 73 74 75 76 77 78 |
# File 'lib/lutaml/qea/database.rb', line 72 def objects return @objects if defined?(@objects) @objects = Repositories::ObjectRepository.new( @collections[:objects] || [], ) end |
#objects_in_package(id) ⇒ Object
145 146 147 148 |
# File 'lib/lutaml/qea/database.rb', line 145 def objects_in_package(id) ensure_lookup_indexes @objects_by_package_id[id] || [] end |
#operation_params_for(id) ⇒ Object
135 136 137 138 |
# File 'lib/lutaml/qea/database.rb', line 135 def operation_params_for(id) ensure_lookup_indexes @operation_params_by_id[id] || [] end |
#operations_for_object(id) ⇒ Object
130 131 132 133 |
# File 'lib/lutaml/qea/database.rb', line 130 def operations_for_object(id) ensure_lookup_indexes @operations_by_object_id[id] || [] end |
#stats ⇒ Hash<String, Integer>
Get statistics for all collections
92 93 94 95 96 |
# File 'lib/lutaml/qea/database.rb', line 92 def stats @collections.each_with_object({}) do |(name, records), hash| hash[name.to_s] = records.size end end |
#total_records ⇒ Integer
Get total number of records across all collections
101 102 103 |
# File 'lib/lutaml/qea/database.rb', line 101 def total_records @collections.values.sum(&:size) end |