ea 0.6.166 → 0.6.168
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/ea/qea/database.rb +84 -13
- data/lib/ea/qea/lazy_drops.rb +119 -14
- data/lib/ea/qea/services/database_loader.rb +16 -5
- data/lib/ea/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '090f1fb06dd45d8a7e52fdb723d878cb05511eee38d52427841bd988cda57a2d'
|
|
4
|
+
data.tar.gz: a0386f3f4e6272498094aa66bfaab99e56e103ef64528022bbd6b44f8e248f20
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 129810cd09fe475f5f65495c69a3cc7dd21428e458777d0bd0fe3a91ea360247c2eab96a5f5f4ecf821eb715e641ebc63caafc687786998076ee24f04b34e485
|
|
7
|
+
data.tar.gz: d542b2a4aa938c7e4aa052b6d414097000c2418b997eda660c47988fb9ca2a3db3de4ef5009db21334b09af71dc4d1c66b624a1c76e477fb2c25c0506e6c0a70
|
data/lib/ea/qea/database.rb
CHANGED
|
@@ -16,9 +16,6 @@ module Ea
|
|
|
16
16
|
# classes = database.objects.find_by_type("Class")
|
|
17
17
|
# obj = database.find_object(123)
|
|
18
18
|
class Database
|
|
19
|
-
# @return [Hash<Symbol, Array>] Collections of records by name
|
|
20
|
-
attr_reader :collections
|
|
21
|
-
|
|
22
19
|
# @return [String] Path to the QEA file
|
|
23
20
|
attr_reader :qea_path
|
|
24
21
|
|
|
@@ -26,9 +23,20 @@ module Ea
|
|
|
26
23
|
@qea_path = qea_path
|
|
27
24
|
@connection = connection
|
|
28
25
|
@collections = {}
|
|
26
|
+
@deferred = {}
|
|
29
27
|
@mutex = Mutex.new
|
|
30
28
|
end
|
|
31
29
|
|
|
30
|
+
# Collections of records by name. Resolves every deferred table
|
|
31
|
+
# first: direct-hash readers (lint rules, the SVG emitter) must
|
|
32
|
+
# observe the complete data, same as before lazy tables existed.
|
|
33
|
+
#
|
|
34
|
+
# @return [Hash<Symbol, Array>] loaded collections
|
|
35
|
+
def collections
|
|
36
|
+
resolve_all!
|
|
37
|
+
@collections
|
|
38
|
+
end
|
|
39
|
+
|
|
32
40
|
# Set database connection
|
|
33
41
|
#
|
|
34
42
|
# @param connection [SQLite3::Database] Database connection
|
|
@@ -97,6 +105,29 @@ module Ea
|
|
|
97
105
|
end
|
|
98
106
|
end
|
|
99
107
|
|
|
108
|
+
# Register a lazy table load: the block resolves the collection
|
|
109
|
+
# on first access. Keeps row models out of memory for tables a
|
|
110
|
+
# consumer never touches (e.g. the diagram trio on the render
|
|
111
|
+
# path), and defers the model-instantiation cost (the dominant
|
|
112
|
+
# share of load time) until the data is actually read.
|
|
113
|
+
#
|
|
114
|
+
# @param name [Symbol] collection name
|
|
115
|
+
# @param loader [Proc] resolves to the record Array when called
|
|
116
|
+
# @return [void]
|
|
117
|
+
def defer_collection(name, &loader)
|
|
118
|
+
@mutex.synchronize do
|
|
119
|
+
@deferred[name.to_sym] = loader
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
# Collections resolved so far — the observability counterpart of
|
|
124
|
+
# {#collection_names} for deferred loading.
|
|
125
|
+
#
|
|
126
|
+
# @return [Array<Symbol>] sorted names of loaded collections
|
|
127
|
+
def loaded_collection_names
|
|
128
|
+
@mutex.synchronize { @collections.keys.sort }
|
|
129
|
+
end
|
|
130
|
+
|
|
100
131
|
COLLECTION_ACCESSORS = %i[
|
|
101
132
|
attributes operations operation_params connectors packages
|
|
102
133
|
diagrams diagram_objects diagram_links object_constraints
|
|
@@ -143,8 +174,7 @@ module Ea
|
|
|
143
174
|
name = TABLE_TO_COLLECTION[table_name]
|
|
144
175
|
return [] unless name
|
|
145
176
|
|
|
146
|
-
records =
|
|
147
|
-
return [] unless records
|
|
177
|
+
records = fetch(name)
|
|
148
178
|
|
|
149
179
|
# t_object is wrapped in ObjectRepository — call .all to
|
|
150
180
|
# get the plain Array that validators expect.
|
|
@@ -153,7 +183,7 @@ module Ea
|
|
|
153
183
|
|
|
154
184
|
COLLECTION_ACCESSORS.each do |name|
|
|
155
185
|
define_method(name) do
|
|
156
|
-
|
|
186
|
+
fetch(name)
|
|
157
187
|
end
|
|
158
188
|
end
|
|
159
189
|
|
|
@@ -163,9 +193,7 @@ module Ea
|
|
|
163
193
|
def objects
|
|
164
194
|
return @objects if defined?(@objects)
|
|
165
195
|
|
|
166
|
-
@objects = Repositories::ObjectRepository.new(
|
|
167
|
-
@collections[:objects] || []
|
|
168
|
-
)
|
|
196
|
+
@objects = Repositories::ObjectRepository.new(fetch(:objects))
|
|
169
197
|
end
|
|
170
198
|
|
|
171
199
|
# Get statistics for all collections
|
|
@@ -181,6 +209,7 @@ module Ea
|
|
|
181
209
|
# # ...
|
|
182
210
|
# # }
|
|
183
211
|
def stats
|
|
212
|
+
resolve_all!
|
|
184
213
|
@collections.each_with_object({}) do |(name, records), hash|
|
|
185
214
|
hash[name.to_s] = records.size
|
|
186
215
|
end
|
|
@@ -190,6 +219,7 @@ module Ea
|
|
|
190
219
|
#
|
|
191
220
|
# @return [Integer] Total record count
|
|
192
221
|
def total_records
|
|
222
|
+
resolve_all!
|
|
193
223
|
@collections.values.sum(&:size)
|
|
194
224
|
end
|
|
195
225
|
|
|
@@ -309,17 +339,34 @@ module Ea
|
|
|
309
339
|
#
|
|
310
340
|
# @return [Boolean] true if no collections loaded
|
|
311
341
|
def empty?
|
|
312
|
-
|
|
342
|
+
total_records.zero?
|
|
313
343
|
end
|
|
314
344
|
|
|
315
345
|
# Get collection names
|
|
316
346
|
#
|
|
317
|
-
# @return [Array<Symbol>] Array of collection names
|
|
347
|
+
# @return [Array<Symbol>] Array of collection names, including
|
|
348
|
+
# tables registered but not yet loaded
|
|
318
349
|
def collection_names
|
|
319
|
-
@collections.keys
|
|
350
|
+
(@collections.keys + @deferred.keys).sort
|
|
320
351
|
end
|
|
321
352
|
|
|
322
|
-
# Freeze
|
|
353
|
+
# Freeze loaded collections (records immutable) without forcing
|
|
354
|
+
# deferred tables and without freezing the container itself —
|
|
355
|
+
# internal lazy state (table resolution, lookup-index memoization)
|
|
356
|
+
# keeps working after seal. The loader seals instead of freezing
|
|
357
|
+
# so a sealed container can still answer accesses for tables it
|
|
358
|
+
# has not touched yet.
|
|
359
|
+
#
|
|
360
|
+
# @return [self]
|
|
361
|
+
def seal
|
|
362
|
+
@collections.each_value(&:freeze)
|
|
363
|
+
self
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
# Freeze everything: resolve all deferred tables, build all
|
|
367
|
+
# lookup indexes, freeze the collections and the container.
|
|
368
|
+
# Consumers wanting a hard-frozen database call this explicitly;
|
|
369
|
+
# the loader uses #seal to keep lazy resolution available.
|
|
323
370
|
#
|
|
324
371
|
# @return [self]
|
|
325
372
|
def freeze
|
|
@@ -331,6 +378,30 @@ module Ea
|
|
|
331
378
|
|
|
332
379
|
private
|
|
333
380
|
|
|
381
|
+
# Resolve one collection, loading a deferred table on first
|
|
382
|
+
# access. Resolution is single-shot and deterministic; the
|
|
383
|
+
# mutex keeps concurrent first accesses from double-loading.
|
|
384
|
+
#
|
|
385
|
+
# @param name [Symbol] collection name
|
|
386
|
+
# @return [Array, Repositories::ObjectRepository] the records
|
|
387
|
+
def fetch(name)
|
|
388
|
+
@mutex.synchronize do
|
|
389
|
+
loader = @deferred.delete(name)
|
|
390
|
+
@collections[name] = loader.call.freeze if loader
|
|
391
|
+
@collections[name] || []
|
|
392
|
+
end
|
|
393
|
+
end
|
|
394
|
+
|
|
395
|
+
# Resolve every deferred table. Used by whole-database readers
|
|
396
|
+
# (stats, total_records, collections) whose answers are defined
|
|
397
|
+
# over the complete data.
|
|
398
|
+
#
|
|
399
|
+
# @return [void]
|
|
400
|
+
def resolve_all!
|
|
401
|
+
names = @mutex.synchronize { @deferred.keys.dup }
|
|
402
|
+
names.each { |name| fetch(name) }
|
|
403
|
+
end
|
|
404
|
+
|
|
334
405
|
# @param name [String] SQL identifier from the EA schema
|
|
335
406
|
# @return [String] double-quoted, escaped identifier
|
|
336
407
|
def quote_ident(name)
|
data/lib/ea/qea/lazy_drops.rb
CHANGED
|
@@ -36,6 +36,7 @@ module Ea
|
|
|
36
36
|
# @param guidance [Object, nil] guidance document
|
|
37
37
|
# @return [ParsedResult]
|
|
38
38
|
def parsed(qea_path, guidance: nil)
|
|
39
|
+
require_uml!
|
|
39
40
|
database = Services::DatabaseLoader.new(qea_path).load
|
|
40
41
|
context = Context.new(database, guidance)
|
|
41
42
|
ParsedResult.new(
|
|
@@ -45,6 +46,25 @@ module Ea
|
|
|
45
46
|
)
|
|
46
47
|
end
|
|
47
48
|
|
|
49
|
+
# Load a .qea file into the Loaded graph shape the table
|
|
50
|
+
# renders consume (parser, uml_document facade, drop options,
|
|
51
|
+
# lazy id index) — the .qea branch of the XMI load_graph.
|
|
52
|
+
#
|
|
53
|
+
# @param qea_path [String] path to the .qea file
|
|
54
|
+
# @param guidance [Object, nil] guidance document
|
|
55
|
+
# @return [LazyGraph]
|
|
56
|
+
def parsed_graph(qea_path, guidance: nil)
|
|
57
|
+
require_uml!
|
|
58
|
+
database = Services::DatabaseLoader.new(qea_path).load
|
|
59
|
+
context = Context.new(database, guidance)
|
|
60
|
+
LazyGraph.new(
|
|
61
|
+
parser: context.parser,
|
|
62
|
+
uml_document: LazyDocument.new(context),
|
|
63
|
+
drop_options: context.drop_options,
|
|
64
|
+
xmi_id_index: context.xmi_id_index
|
|
65
|
+
)
|
|
66
|
+
end
|
|
67
|
+
|
|
48
68
|
private
|
|
49
69
|
|
|
50
70
|
def require_uml!
|
|
@@ -160,6 +180,94 @@ module Ea
|
|
|
160
180
|
end
|
|
161
181
|
end
|
|
162
182
|
|
|
183
|
+
# The Loaded graph shape the table renders consume. Classes are
|
|
184
|
+
# constructed per package on demand and memoized on the
|
|
185
|
+
# context's caches; the database stays the single source.
|
|
186
|
+
LazyGraph = Struct.new(:parser, :uml_document, :drop_options,
|
|
187
|
+
:xmi_id_index, keyword_init: true)
|
|
188
|
+
|
|
189
|
+
# Document facade answering RootDrop's reads: name + packages.
|
|
190
|
+
class LazyDocument
|
|
191
|
+
def initialize(context)
|
|
192
|
+
@context = context
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def name
|
|
196
|
+
"EA Model"
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
def packages
|
|
200
|
+
@context.database.packages
|
|
201
|
+
.reject { |package| parent(package) }
|
|
202
|
+
.map { |package| LazyPackage.new(@context, package) }
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
private
|
|
206
|
+
|
|
207
|
+
def parent(package)
|
|
208
|
+
@context.database.find_package(package.parent_id)
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
# Package facade over one t_package row: classes, enums, data
|
|
213
|
+
# types and child packages construct on demand.
|
|
214
|
+
class LazyPackage
|
|
215
|
+
def initialize(context, package)
|
|
216
|
+
@context = context
|
|
217
|
+
@package = package
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
def name
|
|
221
|
+
@package.name
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def xmi_id
|
|
225
|
+
@package.ea_guid ? ea_id(@package.ea_guid) : nil
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def definition
|
|
229
|
+
@package.notes ? Ea::Rtf.to_text(@package.notes.to_s) : nil
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def stereotype
|
|
233
|
+
nil
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
def classes
|
|
237
|
+
@context.database.objects_in_package(@package.package_id)
|
|
238
|
+
.select(&:uml_class?)
|
|
239
|
+
.map { |row| @context.klass_for(row.ea_object_id) }
|
|
240
|
+
.compact
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def enums
|
|
244
|
+
@context.database.objects_in_package(@package.package_id)
|
|
245
|
+
.select(&:enumeration?)
|
|
246
|
+
.filter_map { |row| @context.enum_for(row.ea_object_id) }
|
|
247
|
+
end
|
|
248
|
+
|
|
249
|
+
def data_types
|
|
250
|
+
@context.database.objects_in_package(@package.package_id)
|
|
251
|
+
.select(&:data_type?)
|
|
252
|
+
.filter_map { |row| @context.data_type_for(row.ea_object_id) }
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
def packages
|
|
256
|
+
@context.database.child_packages_for(@package.package_id)
|
|
257
|
+
.map { |row| LazyPackage.new(@context, row) }
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
def diagrams
|
|
261
|
+
[]
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
private
|
|
265
|
+
|
|
266
|
+
def ea_id(guid)
|
|
267
|
+
Ea::GuidFormat.ea_guid_to_xmi_id(guid)
|
|
268
|
+
end
|
|
269
|
+
end
|
|
270
|
+
|
|
163
271
|
# Stand-in for the xmi gem's root model: the klass-table cache
|
|
164
272
|
# reads only its model name (to strip a leading path segment).
|
|
165
273
|
class RootModelFacade
|
|
@@ -330,21 +438,18 @@ module Ea
|
|
|
330
438
|
context = @context
|
|
331
439
|
database = context.database
|
|
332
440
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
context.data_type_for(object.ea_object_id)
|
|
345
|
-
end
|
|
441
|
+
guid = Ea::GuidFormat.xmi_id_to_ea_guid(xmi_id)
|
|
442
|
+
object = guid && database.find_object_by_guid(guid)
|
|
443
|
+
return unless object
|
|
444
|
+
|
|
445
|
+
case object
|
|
446
|
+
when ->(o) { o.uml_class? || o.interface? }
|
|
447
|
+
context.klass_for(object.ea_object_id)
|
|
448
|
+
when lambda(&:enumeration?)
|
|
449
|
+
context.enum_for(object.ea_object_id)
|
|
450
|
+
when lambda(&:data_type?)
|
|
451
|
+
context.data_type_for(object.ea_object_id)
|
|
346
452
|
end
|
|
347
|
-
nil
|
|
348
453
|
end
|
|
349
454
|
end
|
|
350
455
|
end
|
|
@@ -98,6 +98,13 @@ module Ea
|
|
|
98
98
|
|
|
99
99
|
# Load entire database
|
|
100
100
|
#
|
|
101
|
+
# Tables register as deferred loads rather than materializing
|
|
102
|
+
# up front: row-model instantiation dominates load cost, and
|
|
103
|
+
# consumers that never touch a table (the diagram trio on the
|
|
104
|
+
# klass-table path) no longer pay for it. First access loads
|
|
105
|
+
# through a reopened connection — nothing keeps the file
|
|
106
|
+
# handle open (a persistent handle locks the file on Windows).
|
|
107
|
+
#
|
|
101
108
|
# @return [Database] Populated database instance
|
|
102
109
|
# @raise [Errno::ENOENT] if QEA file not found
|
|
103
110
|
# @raise [SQLite3::Exception] if database access fails
|
|
@@ -106,16 +113,20 @@ module Ea
|
|
|
106
113
|
db = @connection.connection
|
|
107
114
|
|
|
108
115
|
database = Database.new(@qea_path, db)
|
|
109
|
-
# Kept for on-demand blob fetches
|
|
110
|
-
# itself closes in ensure;
|
|
116
|
+
# Kept for on-demand blob fetches and deferred table loads
|
|
117
|
+
# after load (the connection itself closes in ensure;
|
|
118
|
+
# Database reopens per fetch/resolve).
|
|
111
119
|
database.blob_connection = @connection
|
|
112
120
|
|
|
113
121
|
@config.enabled_tables.each do |table_def|
|
|
114
|
-
|
|
115
|
-
|
|
122
|
+
database.defer_collection(table_def.collection_name) do
|
|
123
|
+
@connection.with_connection do |live|
|
|
124
|
+
load_table_records(live, table_def)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
116
127
|
end
|
|
117
128
|
|
|
118
|
-
database.
|
|
129
|
+
database.seal
|
|
119
130
|
ensure
|
|
120
131
|
# All tables are in memory; nothing keeps the handle open, and
|
|
121
132
|
# an open handle locks the file on Windows. Blob fetches go
|
data/lib/ea/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ea
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.168
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: lutaml-model
|