Class: Lutaml::Qea::Database
- Inherits:
-
Object
- Object
- Lutaml::Qea::Database
- Defined in:
- lib/lutaml/qea/database.rb,
lib/lutaml/qea/lookup_indexes.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.
31 32 33 34 35 36 |
# File 'lib/lutaml/qea/database.rb', line 31 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.
23 24 25 |
# File 'lib/lutaml/qea/database.rb', line 23 def collections @collections end |
#connection ⇒ SQLite3::Database?
Returns Database connection.
29 30 31 |
# File 'lib/lutaml/qea/database.rb', line 29 def connection @connection end |
#qea_path ⇒ String (readonly)
Returns Path to the QEA file.
26 27 28 |
# File 'lib/lutaml/qea/database.rb', line 26 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
51 52 53 54 55 |
# File 'lib/lutaml/qea/database.rb', line 51 def add_collection(name, records) @mutex.synchronize do @collections[name.to_sym] = records.freeze end end |
#attributes_for_object(id) ⇒ Object
128 129 130 131 |
# File 'lib/lutaml/qea/database.rb', line 128 def attributes_for_object(id) ensure_lookup_indexes @attributes_by_object_id[id] || [] end |
#child_packages_for(id) ⇒ Object
143 144 145 146 |
# File 'lib/lutaml/qea/database.rb', line 143 def child_packages_for(id) ensure_lookup_indexes @packages_by_parent[id] || [] end |
#collection_names ⇒ Array<Symbol>
Get collection names
196 197 198 |
# File 'lib/lutaml/qea/database.rb', line 196 def collection_names @collections.keys end |
#connectors_for_object(object_id) ⇒ Object
Get connectors involving a specific object (start or end)
180 181 182 183 184 |
# File 'lib/lutaml/qea/database.rb', line 180 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
163 164 165 166 |
# File 'lib/lutaml/qea/database.rb', line 163 def diagram_links_for(id) ensure_lookup_indexes @diagram_links_by_id[id] || [] end |
#diagram_objects_for(id) ⇒ Object
158 159 160 161 |
# File 'lib/lutaml/qea/database.rb', line 158 def diagram_objects_for(id) ensure_lookup_indexes @diagram_objects_by_id[id] || [] end |
#diagrams_in_package(id) ⇒ Object
153 154 155 156 |
# File 'lib/lutaml/qea/database.rb', line 153 def diagrams_in_package(id) ensure_lookup_indexes @diagrams_by_package_id[id] || [] end |
#empty? ⇒ Boolean
Check if database is empty
189 190 191 |
# File 'lib/lutaml/qea/database.rb', line 189 def empty? @collections.empty? || total_records.zero? end |
#find_attribute(id) ⇒ Object
113 114 115 116 |
# File 'lib/lutaml/qea/database.rb', line 113 def find_attribute(id) ensure_lookup_indexes @attributes_by_id[id] end |
#find_connector(id) ⇒ Object
118 119 120 121 |
# File 'lib/lutaml/qea/database.rb', line 118 def find_connector(id) ensure_lookup_indexes @connectors_by_id[id] end |
#find_diagram(id) ⇒ Object
123 124 125 126 |
# File 'lib/lutaml/qea/database.rb', line 123 def find_diagram(id) ensure_lookup_indexes @diagrams_by_id[id] end |
#find_object(id) ⇒ Object
Find an object by ID
169 170 171 |
# File 'lib/lutaml/qea/database.rb', line 169 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
174 175 176 177 |
# File 'lib/lutaml/qea/database.rb', line 174 def find_object_by_guid(ea_guid) ensure_lookup_indexes @objects_by_guid[ea_guid] end |
#find_package(id) ⇒ Object
108 109 110 111 |
# File 'lib/lutaml/qea/database.rb', line 108 def find_package(id) ensure_lookup_indexes @packages_by_id[id] end |
#freeze ⇒ self
Freeze all collections to make database immutable
203 204 205 206 207 208 |
# File 'lib/lutaml/qea/database.rb', line 203 def freeze objects ensure_lookup_indexes @collections.freeze super end |
#objects ⇒ Repositories::ObjectRepository
Get objects collection (special: wrapped in ObjectRepository)
75 76 77 78 79 80 81 |
# File 'lib/lutaml/qea/database.rb', line 75 def objects return @objects if defined?(@objects) @objects = Repositories::ObjectRepository.new( @collections[:objects] || [], ) end |
#objects_in_package(id) ⇒ Object
148 149 150 151 |
# File 'lib/lutaml/qea/database.rb', line 148 def objects_in_package(id) ensure_lookup_indexes @objects_by_package_id[id] || [] end |
#operation_params_for(id) ⇒ Object
138 139 140 141 |
# File 'lib/lutaml/qea/database.rb', line 138 def operation_params_for(id) ensure_lookup_indexes @operation_params_by_id[id] || [] end |
#operations_for_object(id) ⇒ Object
133 134 135 136 |
# File 'lib/lutaml/qea/database.rb', line 133 def operations_for_object(id) ensure_lookup_indexes @operations_by_object_id[id] || [] end |
#stats ⇒ Hash<String, Integer>
Get statistics for all collections
95 96 97 98 99 |
# File 'lib/lutaml/qea/database.rb', line 95 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
104 105 106 |
# File 'lib/lutaml/qea/database.rb', line 104 def total_records @collections.values.sum(&:size) end |