Class: Lutaml::Qea::Services::DatabaseLoader
- Inherits:
-
Object
- Object
- Lutaml::Qea::Services::DatabaseLoader
- Defined in:
- lib/lutaml/qea/services/database_loader.rb
Overview
DatabaseLoader orchestrates loading all EA tables into a Database
This service loads all enabled tables from the QEA database, converts database rows to model instances, and populates a Database container with the results.
Constant Summary collapse
- MODEL_CLASSES =
Table name to model class mapping
{ "t_object" => Models::EaObject, "t_attribute" => Models::EaAttribute, "t_operation" => Models::EaOperation, "t_operationparams" => Models::EaOperationParam, "t_connector" => Models::EaConnector, "t_package" => Models::EaPackage, "t_diagram" => Models::EaDiagram, "t_diagramobjects" => Models::EaDiagramObject, "t_diagramlinks" => Models::EaDiagramLink, "t_objectconstraint" => Models::EaObjectConstraint, "t_taggedvalue" => Models::EaTaggedValue, "t_objectproperties" => Models::EaObjectProperty, "t_attributetag" => Models::EaAttributeTag, "t_xref" => Models::EaXref, "t_document" => Models::EaDocument, "t_script" => Models::EaScript, "t_stereotypes" => Models::EaStereotype, "t_datatypes" => Models::EaDatatype, "t_constrainttypes" => Models::EaConstraintType, "t_connectortypes" => Models::EaConnectorType, "t_diagramtypes" => Models::EaDiagramType, "t_objecttypes" => Models::EaObjectType, "t_statustypes" => Models::EaStatusType, "t_complexitytypes" => Models::EaComplexityType, }.freeze
Instance Attribute Summary collapse
-
#config ⇒ Configuration
readonly
Configuration instance.
-
#qea_path ⇒ String
readonly
Path to QEA file.
Instance Method Summary collapse
-
#initialize(qea_path, config = nil) ⇒ DatabaseLoader
constructor
Initialize loader.
-
#load ⇒ Database
Load entire database.
-
#load_table(table_name) ⇒ Array
Load a single table.
-
#on_progress {|table_name, current, total| ... } ⇒ self
Set progress callback.
-
#quick_stats ⇒ Hash<String, Integer>
Get quick statistics without full loading.
Constructor Details
#initialize(qea_path, config = nil) ⇒ DatabaseLoader
Initialize loader
90 91 92 93 94 95 |
# File 'lib/lutaml/qea/services/database_loader.rb', line 90 def initialize(qea_path, config = nil) @qea_path = qea_path @config = config || Configuration.load @progress_callback = nil @connection = Infrastructure::DatabaseConnection.new(qea_path) end |
Instance Attribute Details
#config ⇒ Configuration (readonly)
Returns Configuration instance.
56 57 58 |
# File 'lib/lutaml/qea/services/database_loader.rb', line 56 def config @config end |
#qea_path ⇒ String (readonly)
Returns Path to QEA file.
53 54 55 |
# File 'lib/lutaml/qea/services/database_loader.rb', line 53 def qea_path @qea_path end |
Instance Method Details
#load ⇒ Database
Load entire database
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/lutaml/qea/services/database_loader.rb', line 114 def load # Connect but don't use with_connection - we need to keep it open @connection.connect unless @connection.connected? db = @connection.connection database = Database.new(@qea_path, db) @config.enabled_tables.each do |table_def| table_name = table_def.table_name collection_name = table_def.collection_name records = load_table_records(db, table_name) database.add_collection(collection_name, records) end database.freeze end |
#load_table(table_name) ⇒ Array
Load a single table
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/lutaml/qea/services/database_loader.rb', line 137 def load_table(table_name) # rubocop:disable Metrics/MethodLength table_def = @config.table_config_for(table_name) unless table_def raise ArgumentError, "Table #{table_name} not configured" end unless table_def.enabled raise ArgumentError, "Table #{table_name} not enabled" end @connection.with_connection do |db| load_table_records(db, table_name) end end |
#on_progress {|table_name, current, total| ... } ⇒ self
Set progress callback
104 105 106 107 |
# File 'lib/lutaml/qea/services/database_loader.rb', line 104 def on_progress(&block) @progress_callback = block self end |
#quick_stats ⇒ Hash<String, Integer>
Get quick statistics without full loading
156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/lutaml/qea/services/database_loader.rb', line 156 def quick_stats stats = {} @connection.with_connection do |db| @config.enabled_tables.each do |table_def| reader = Infrastructure::TableReader.new(db, table_def.table_name) stats[table_def.collection_name] = reader.count end end stats end |