ea 0.6.159 → 0.6.161
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/.rubocop_todo.yml +13 -47
- data/lib/ea/export/xsd/class_mapping.rb +4 -4
- data/lib/ea/export/xsd/generator.rb +21 -12
- data/lib/ea/mdg/stereotype_alias_registry.rb +6 -6
- data/lib/ea/qea/database.rb +49 -0
- data/lib/ea/qea/factory/generalization_builder.rb +17 -17
- data/lib/ea/qea/infrastructure/table_reader.rb +26 -4
- data/lib/ea/qea/models/ea_datatype.rb +2 -2
- data/lib/ea/qea/models/ea_document.rb +2 -2
- data/lib/ea/qea/models/ea_script.rb +2 -2
- data/lib/ea/qea/services/configuration.rb +5 -7
- data/lib/ea/qea/services/database_loader.rb +31 -11
- data/lib/ea/qea/validation/formatters/text_formatter.rb +4 -4
- data/lib/ea/qea/validation/validation_engine.rb +4 -4
- data/lib/ea/qea/validation/validation_result.rb +4 -4
- data/lib/ea/qea/verification/comparison_result.rb +1 -1
- data/lib/ea/rules/general_attribute_mapping.rb +35 -0
- data/lib/ea/rules/namespacing.rb +27 -0
- data/lib/ea/rules.rb +10 -0
- data/lib/ea/sources/multiplicity.rb +41 -0
- data/lib/ea/sources/qea/relationship_builder.rb +6 -40
- data/lib/ea/sources/xmi/constraint_builder.rb +18 -18
- data/lib/ea/sources/xmi/diagram_builder/association_class_metadata.rb +50 -12
- data/lib/ea/sources/xmi/diagram_builder/connector_metadata.rb +59 -7
- data/lib/ea/sources/xmi/diagram_builder/font_settings.rb +2 -2
- data/lib/ea/sources/xmi/diagram_builder/umldi_edges/property_roles.rb +7 -5
- data/lib/ea/sources/xmi/diagram_builder/umldi_edges.rb +16 -10
- data/lib/ea/sources/xmi/extension_types.rb +2 -2
- data/lib/ea/sources/xmi/instance_builder.rb +6 -4
- data/lib/ea/sources/xmi/note_builder.rb +1 -1
- data/lib/ea/sources/xmi/reception_builder.rb +2 -2
- data/lib/ea/sources/xmi/relationship_builder.rb +6 -24
- data/lib/ea/sources/xmi/tag_builder.rb +2 -2
- data/lib/ea/sources/xmi/umldi_keyword_extractor.rb +2 -2
- data/lib/ea/sources.rb +1 -0
- data/lib/ea/svg/ea_emitter/document.rb +12 -1
- data/lib/ea/svg/ea_emitter/element/package_shape_renderer.rb +4 -4
- data/lib/ea/svg/ea_emitter/elements.rb +1 -1
- data/lib/ea/svg/parity/checker.rb +21 -10
- data/lib/ea/svg/parity/differ.rb +4 -2
- data/lib/ea/svg/parity/suite.rb +1 -1
- data/lib/ea/transformers/qea_to_xmi/transformer.rb +3 -7
- data/lib/ea/version.rb +1 -1
- data/lib/ea/xmi/liquid_drops/connector_drop.rb +2 -2
- data/lib/ea/xmi/parser.rb +39 -46
- data/lib/ea/xmi.rb +1 -1
- data/lib/ea/xml.rb +44 -0
- data/lib/ea.rb +2 -0
- metadata +23 -18
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d7197145439783ffd1371d762178adb42d10fbb7bd149a35b321eb07d85bfdea
|
|
4
|
+
data.tar.gz: 2337db7f718d4237e586bb4b77bd7ab03fe2c8ca21466be720c73a0f74bd78ba
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5d1728a63e4be58c217d2204e3095af3255f0e2a69ef84586ac74a3c3eb62c3ab132b8d06d31a8f139e0ab08f53160b856fa3c03f8e5a9bb5d0053b544ad9d1e
|
|
7
|
+
data.tar.gz: 9abe04e07fb696d543c4ea5fbadba8049baea8b91fbae6276ddecd3c9bfaf7b716a576adf6bacb1c9e1dd156c87044081ae28f688095ba9277c80e522d48d46a
|
data/.rubocop_todo.yml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# This configuration was generated by
|
|
2
|
-
# `rubocop --auto-gen-config`
|
|
3
|
-
#
|
|
2
|
+
# `rubocop --auto-gen-config --no-auto-gen-timestamp`
|
|
3
|
+
# using RuboCop version 1.92.3.
|
|
4
4
|
# The point is for the user to remove these configuration records
|
|
5
5
|
# one by one as the offenses are removed from the code base.
|
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
|
@@ -158,43 +158,43 @@ Lint/Void:
|
|
|
158
158
|
- 'lib/ea/cli/output.rb'
|
|
159
159
|
- 'lib/ea/svg/ea_emitter/marker.rb'
|
|
160
160
|
|
|
161
|
-
# Offense count:
|
|
161
|
+
# Offense count: 282
|
|
162
162
|
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
|
|
163
163
|
Metrics/AbcSize:
|
|
164
164
|
Max: 175
|
|
165
165
|
|
|
166
|
-
# Offense count:
|
|
166
|
+
# Offense count: 6
|
|
167
167
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
|
168
168
|
# AllowedMethods: refine
|
|
169
169
|
Metrics/BlockLength:
|
|
170
|
-
Max:
|
|
170
|
+
Max: 38
|
|
171
171
|
|
|
172
|
-
# Offense count:
|
|
172
|
+
# Offense count: 50
|
|
173
173
|
# Configuration parameters: CountComments, CountAsOne.
|
|
174
174
|
Metrics/ClassLength:
|
|
175
175
|
Max: 897
|
|
176
176
|
|
|
177
|
-
# Offense count:
|
|
177
|
+
# Offense count: 142
|
|
178
178
|
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
|
179
179
|
Metrics/CyclomaticComplexity:
|
|
180
180
|
Max: 81
|
|
181
181
|
|
|
182
|
-
# Offense count:
|
|
182
|
+
# Offense count: 326
|
|
183
183
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
|
184
184
|
Metrics/MethodLength:
|
|
185
185
|
Max: 153
|
|
186
186
|
|
|
187
|
-
# Offense count:
|
|
187
|
+
# Offense count: 7
|
|
188
188
|
# Configuration parameters: CountComments, CountAsOne.
|
|
189
189
|
Metrics/ModuleLength:
|
|
190
190
|
Max: 931
|
|
191
191
|
|
|
192
|
-
# Offense count:
|
|
192
|
+
# Offense count: 63
|
|
193
193
|
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
|
|
194
194
|
Metrics/ParameterLists:
|
|
195
195
|
Max: 33
|
|
196
196
|
|
|
197
|
-
# Offense count:
|
|
197
|
+
# Offense count: 106
|
|
198
198
|
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
|
199
199
|
Metrics/PerceivedComplexity:
|
|
200
200
|
Max: 83
|
|
@@ -223,13 +223,7 @@ Naming/MethodName:
|
|
|
223
223
|
Exclude:
|
|
224
224
|
- 'spec/ea/svg/ea_emitter/compartment_spec.rb'
|
|
225
225
|
|
|
226
|
-
# Offense count:
|
|
227
|
-
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
|
|
228
|
-
# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
|
|
229
|
-
Naming/MethodParameterName:
|
|
230
|
-
Enabled: false
|
|
231
|
-
|
|
232
|
-
# Offense count: 17
|
|
226
|
+
# Offense count: 4
|
|
233
227
|
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros, UseSorbetSigs.
|
|
234
228
|
# NamePrefix: is_, has_, have_, does_
|
|
235
229
|
# ForbiddenPrefixes: is_, has_, have_, does_
|
|
@@ -238,13 +232,6 @@ Naming/MethodParameterName:
|
|
|
238
232
|
Naming/PredicatePrefix:
|
|
239
233
|
Exclude:
|
|
240
234
|
- 'spec/**/*'
|
|
241
|
-
- 'lib/ea/qea/models/ea_datatype.rb'
|
|
242
|
-
- 'lib/ea/qea/models/ea_document.rb'
|
|
243
|
-
- 'lib/ea/qea/models/ea_script.rb'
|
|
244
|
-
- 'lib/ea/qea/validation/validation_result.rb'
|
|
245
|
-
- 'lib/ea/qea/verification/comparison_result.rb'
|
|
246
|
-
- 'lib/ea/svg/ea_emitter/element/package_shape_renderer.rb'
|
|
247
|
-
- 'lib/ea/svg/ea_emitter/elements.rb'
|
|
248
235
|
- 'lib/ea/xmi/liquid_drops/data_type_drop.rb'
|
|
249
236
|
- 'lib/ea/xmi/liquid_drops/generalization_attribute_drop.rb'
|
|
250
237
|
- 'lib/ea/xmi/liquid_drops/generalization_drop.rb'
|
|
@@ -258,27 +245,6 @@ Naming/VariableNumber:
|
|
|
258
245
|
Exclude:
|
|
259
246
|
- 'spec/ea/svg/ea_emitter/color_resolver_spec.rb'
|
|
260
247
|
|
|
261
|
-
# Offense count: 24
|
|
262
|
-
# This cop supports unsafe autocorrection (--autocorrect-all).
|
|
263
|
-
Style/CommentedKeyword:
|
|
264
|
-
Exclude:
|
|
265
|
-
- 'lib/ea/xmi/parser.rb'
|
|
266
|
-
|
|
267
|
-
# Offense count: 84
|
|
268
|
-
# Configuration parameters: AllowedConstants.
|
|
269
|
-
Style/Documentation:
|
|
270
|
-
Enabled: false
|
|
271
|
-
|
|
272
|
-
# Offense count: 5
|
|
273
|
-
# This cop supports unsafe autocorrection (--autocorrect-all).
|
|
274
|
-
# Configuration parameters: EnforcedStyle.
|
|
275
|
-
# SupportedStyles: allowed_in_returns, forbidden
|
|
276
|
-
Style/DoubleNegation:
|
|
277
|
-
Exclude:
|
|
278
|
-
- 'lib/ea/qea/factory/generalization_builder.rb'
|
|
279
|
-
- 'lib/ea/xmi/liquid_drops/connector_drop.rb'
|
|
280
|
-
- 'lib/ea/xmi/parser.rb'
|
|
281
|
-
|
|
282
248
|
# Offense count: 1
|
|
283
249
|
# This cop supports unsafe autocorrection (--autocorrect-all).
|
|
284
250
|
# Configuration parameters: EnforcedStyle.
|
|
@@ -415,7 +381,7 @@ Style/StructInheritance:
|
|
|
415
381
|
Exclude:
|
|
416
382
|
- 'lib/ea/svg/ea_emitter/render_context.rb'
|
|
417
383
|
|
|
418
|
-
# Offense count:
|
|
384
|
+
# Offense count: 41
|
|
419
385
|
# This cop supports safe autocorrection (--autocorrect).
|
|
420
386
|
# Configuration parameters: AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, AllowRBSInlineAnnotation, AllowCopDirectives, AllowedPatterns, SplitStrings.
|
|
421
387
|
# URISchemes: http, https
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Ea
|
|
6
6
|
module Export
|
|
@@ -30,12 +30,12 @@ module Ea
|
|
|
30
30
|
def self.from_path(path)
|
|
31
31
|
return new if path.nil? || !File.exist?(path)
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
from_xml(Ea::Xml.parse_file(path))
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
# @param doc [
|
|
36
|
+
# @param doc [Moxml::Wrappers::Document]
|
|
37
37
|
# @return [ClassMapping]
|
|
38
|
-
def self.
|
|
38
|
+
def self.from_xml(doc)
|
|
39
39
|
mappings = {}
|
|
40
40
|
doc.xpath("//Class").each do |node|
|
|
41
41
|
name = node["name"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "
|
|
3
|
+
require "moxml"
|
|
4
4
|
|
|
5
5
|
module Ea
|
|
6
6
|
module Export
|
|
@@ -46,13 +46,14 @@ module Ea
|
|
|
46
46
|
private
|
|
47
47
|
|
|
48
48
|
def build_schema_doc(target_namespace, prefix)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
doc = Moxml.new.create_document
|
|
50
|
+
schema = doc.create_element("schema")
|
|
51
|
+
schema["xmlns"] = XSD_NS
|
|
52
|
+
schema["xmlns:#{prefix}"] = target_namespace
|
|
53
|
+
schema["targetNamespace"] = target_namespace
|
|
54
|
+
schema["elementFormDefault"] = "qualified"
|
|
55
|
+
doc.root = schema
|
|
56
|
+
doc
|
|
56
57
|
end
|
|
57
58
|
|
|
58
59
|
def walk_model(model, doc)
|
|
@@ -107,16 +108,16 @@ module Ea
|
|
|
107
108
|
end
|
|
108
109
|
|
|
109
110
|
def element_node(doc, name, type_name)
|
|
110
|
-
el = doc
|
|
111
|
+
el = xsd_element(doc)
|
|
111
112
|
el["name"] = name
|
|
112
113
|
el["type"] = "tns:#{type_name}"
|
|
113
114
|
el
|
|
114
115
|
end
|
|
115
116
|
|
|
116
117
|
def complex_type_node(doc, type_name, classifier)
|
|
117
|
-
ct = doc
|
|
118
|
+
ct = xsd_element(doc, "complexType")
|
|
118
119
|
ct["name"] = type_name
|
|
119
|
-
seq = doc
|
|
120
|
+
seq = xsd_element(doc, "sequence")
|
|
120
121
|
classifier.attributes.each do |attr|
|
|
121
122
|
seq.add_child(attribute_element(doc, attr))
|
|
122
123
|
end
|
|
@@ -125,12 +126,20 @@ module Ea
|
|
|
125
126
|
end
|
|
126
127
|
|
|
127
128
|
def attribute_element(doc, attr)
|
|
128
|
-
el = doc
|
|
129
|
+
el = xsd_element(doc)
|
|
129
130
|
el["name"] = attr[:name].to_s
|
|
130
131
|
el["type"] = "xs:string"
|
|
131
132
|
el["minOccurs"] = "0"
|
|
132
133
|
el
|
|
133
134
|
end
|
|
135
|
+
|
|
136
|
+
# Schema children carry the XSD namespace explicitly, matching
|
|
137
|
+
# the reference EA output.
|
|
138
|
+
def xsd_element(doc, name = "element")
|
|
139
|
+
el = doc.create_element(name)
|
|
140
|
+
el["xmlns"] = XSD_NS
|
|
141
|
+
el
|
|
142
|
+
end
|
|
134
143
|
end
|
|
135
144
|
end
|
|
136
145
|
end
|
|
@@ -32,16 +32,16 @@ module Ea
|
|
|
32
32
|
def self.from_path(path)
|
|
33
33
|
return new if path.nil? || !File.exist?(path)
|
|
34
34
|
|
|
35
|
-
require "
|
|
36
|
-
doc =
|
|
37
|
-
|
|
35
|
+
require "moxml"
|
|
36
|
+
doc = Ea::Xml.parse_file(path)
|
|
37
|
+
from_xml(doc)
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
# Build from a parsed
|
|
40
|
+
# Build from a parsed XML document. Tested separately so
|
|
41
41
|
# the parser path is exercised without file IO.
|
|
42
|
-
# @param doc [
|
|
42
|
+
# @param doc [Moxml::Wrappers::Document]
|
|
43
43
|
# @return [StereotypeAliasRegistry]
|
|
44
|
-
def self.
|
|
44
|
+
def self.from_xml(doc)
|
|
45
45
|
aliases = {}
|
|
46
46
|
doc.xpath("//Stereotype").each do |stereo|
|
|
47
47
|
canonical = stereo["name"]
|
data/lib/ea/qea/database.rb
CHANGED
|
@@ -35,6 +35,49 @@ module Ea
|
|
|
35
35
|
# @return [void]
|
|
36
36
|
attr_writer :connection
|
|
37
37
|
|
|
38
|
+
# The DatabaseConnection the loader used. Kept (not connected)
|
|
39
|
+
# so blob fetches can reopen the QEA file on demand; nil for
|
|
40
|
+
# hand-constructed Databases.
|
|
41
|
+
attr_accessor :blob_connection
|
|
42
|
+
|
|
43
|
+
# Fetch a blob column value on demand by reopening the QEA file
|
|
44
|
+
# read-only for the duration of the fetch. The container's load
|
|
45
|
+
# connection is closed after load (an open handle locks the file
|
|
46
|
+
# on Windows), so each fetch opens, reads, and closes per call —
|
|
47
|
+
# fetched values are returned, never stored, keeping the frozen
|
|
48
|
+
# container contract intact.
|
|
49
|
+
#
|
|
50
|
+
# @param table_name [String] EA table carrying the blob
|
|
51
|
+
# @param pk_column [String] primary-key column of that table
|
|
52
|
+
# @param column [String] the blob column to read
|
|
53
|
+
# @param id [Object] primary-key value of the row
|
|
54
|
+
# @return [String, nil] the blob value, or nil when no connection
|
|
55
|
+
# route exists, the row is absent, or the fetch fails
|
|
56
|
+
def blob_value(table_name, pk_column, column, id)
|
|
57
|
+
conn = blob_connection
|
|
58
|
+
return nil unless conn
|
|
59
|
+
|
|
60
|
+
conn.with_connection do |db|
|
|
61
|
+
row = db.get_first_row(
|
|
62
|
+
"SELECT #{quote_ident(column)} FROM #{quote_ident(table_name)} " \
|
|
63
|
+
"WHERE #{quote_ident(pk_column)} = ?", [id]
|
|
64
|
+
)
|
|
65
|
+
row && row[column]
|
|
66
|
+
end
|
|
67
|
+
rescue StandardError
|
|
68
|
+
# Best-effort accessor: missing/locked file, absent row or table
|
|
69
|
+
# all mean "blob unavailable"; callers already handle nil.
|
|
70
|
+
nil
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Fetch a t_image blob by its ImageID.
|
|
74
|
+
#
|
|
75
|
+
# @param image_id [Integer] t_image.ImageID
|
|
76
|
+
# @return [String, nil] the Image blob, or nil when unavailable
|
|
77
|
+
def image_blob(image_id)
|
|
78
|
+
blob_value("t_image", "ImageID", "Image", image_id)
|
|
79
|
+
end
|
|
80
|
+
|
|
38
81
|
# Close the database connection if open
|
|
39
82
|
# @return [void]
|
|
40
83
|
def close_connection
|
|
@@ -288,6 +331,12 @@ module Ea
|
|
|
288
331
|
|
|
289
332
|
private
|
|
290
333
|
|
|
334
|
+
# @param name [String] SQL identifier from the EA schema
|
|
335
|
+
# @return [String] double-quoted, escaped identifier
|
|
336
|
+
def quote_ident(name)
|
|
337
|
+
%("#{name.to_s.gsub('"', '""')}")
|
|
338
|
+
end
|
|
339
|
+
|
|
291
340
|
def ensure_lookup_indexes
|
|
292
341
|
return if @lookup_indexes_built
|
|
293
342
|
|
|
@@ -54,17 +54,23 @@ module Ea
|
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
def to_general_attribute(attr)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
Ea::Rules::GeneralAttributeMapping.build(
|
|
58
|
+
id: attr.id,
|
|
59
|
+
name: attr.name,
|
|
60
|
+
type: attr.type,
|
|
61
|
+
xmi_id: attr.xmi_id,
|
|
62
|
+
cardinality: attr.cardinality,
|
|
63
|
+
definition: attr.definition,
|
|
64
|
+
association: attr.association,
|
|
65
|
+
type_ns: attr.type_ns,
|
|
66
|
+
is_derived: attr.is_derived
|
|
61
67
|
)
|
|
62
68
|
end
|
|
63
69
|
|
|
64
70
|
def to_top_element_attribute(attr)
|
|
65
71
|
Lutaml::Uml::TopElementAttribute.new(
|
|
66
72
|
**base_attr_hash(attr),
|
|
67
|
-
is_derived:
|
|
73
|
+
is_derived: attr.is_derived == true
|
|
68
74
|
)
|
|
69
75
|
end
|
|
70
76
|
|
|
@@ -120,16 +126,6 @@ module Ea
|
|
|
120
126
|
end
|
|
121
127
|
end
|
|
122
128
|
|
|
123
|
-
def resolve_name_ns(type_ns, upper_klass)
|
|
124
|
-
ns = case type_ns
|
|
125
|
-
when "core", "gml"
|
|
126
|
-
upper_klass
|
|
127
|
-
else
|
|
128
|
-
type_ns
|
|
129
|
-
end
|
|
130
|
-
ns || upper_klass
|
|
131
|
-
end
|
|
132
|
-
|
|
133
129
|
def build_generalization(object_id, current_obj)
|
|
134
130
|
ea_connector = ea_connector_for(object_id)
|
|
135
131
|
gen_transformer = GeneralizationTransformer.new(database)
|
|
@@ -174,7 +170,9 @@ module Ea
|
|
|
174
170
|
upper_klass = generalization.general_upper_klass
|
|
175
171
|
general_attrs.each do |attr|
|
|
176
172
|
attr.gen_name = generalization.general_name
|
|
177
|
-
attr.name_ns = resolve_name_ns(
|
|
173
|
+
attr.name_ns = Ea::Rules::Namespacing.resolve_name_ns(
|
|
174
|
+
attr.type_ns, upper_klass
|
|
175
|
+
)
|
|
178
176
|
end
|
|
179
177
|
end
|
|
180
178
|
|
|
@@ -196,7 +194,9 @@ module Ea
|
|
|
196
194
|
|
|
197
195
|
generalization.general_attributes.map do |attr|
|
|
198
196
|
transformed = attr.dup
|
|
199
|
-
transformed.name_ns = resolve_name_ns(
|
|
197
|
+
transformed.name_ns = Ea::Rules::Namespacing.resolve_name_ns(
|
|
198
|
+
attr.type_ns, upper_klass
|
|
199
|
+
)
|
|
200
200
|
transformed.gen_name = gen_name
|
|
201
201
|
transformed.name = "" if transformed.name.nil?
|
|
202
202
|
transformed
|
|
@@ -44,6 +44,13 @@ module Ea
|
|
|
44
44
|
!row.nil?
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
+
# @return [Array<String>] the table's actual column names
|
|
48
|
+
def column_names
|
|
49
|
+
@database
|
|
50
|
+
.execute("PRAGMA table_info(#{@table_name})")
|
|
51
|
+
.map { |row| row["name"] }
|
|
52
|
+
end
|
|
53
|
+
|
|
47
54
|
# Read all records from the table
|
|
48
55
|
#
|
|
49
56
|
# @param limit [Integer, nil] Maximum number of records to return
|
|
@@ -66,6 +73,8 @@ module Ea
|
|
|
66
73
|
# Stream records row-by-row without materializing the full
|
|
67
74
|
# result set (halves peak memory on large tables).
|
|
68
75
|
#
|
|
76
|
+
# @param columns [Array<String>, nil] column subset to select;
|
|
77
|
+
# nil selects every column
|
|
69
78
|
# @param limit [Integer, nil]
|
|
70
79
|
# @param offset [Integer, nil]
|
|
71
80
|
# @yieldparam row [Hash] one database row
|
|
@@ -73,8 +82,12 @@ module Ea
|
|
|
73
82
|
#
|
|
74
83
|
# @example
|
|
75
84
|
# reader.each_row { |row| models << Model.from_db_row(row) }
|
|
76
|
-
|
|
77
|
-
|
|
85
|
+
#
|
|
86
|
+
# @example Metadata-only streaming (skip the heavy blob column)
|
|
87
|
+
# reader.each_row(columns: %w[ImageID Name Type]) { |row| ... }
|
|
88
|
+
def each_row(columns: nil, limit: nil, offset: nil, &block)
|
|
89
|
+
query, params = build_select_query(columns: columns,
|
|
90
|
+
limit: limit, offset: offset)
|
|
78
91
|
@database.execute(query, params, &block)
|
|
79
92
|
end
|
|
80
93
|
|
|
@@ -233,8 +246,8 @@ module Ea
|
|
|
233
246
|
|
|
234
247
|
private
|
|
235
248
|
|
|
236
|
-
def build_select_query(limit: nil, offset: nil)
|
|
237
|
-
query = +"SELECT
|
|
249
|
+
def build_select_query(columns: nil, limit: nil, offset: nil)
|
|
250
|
+
query = +"SELECT #{select_list(columns)} FROM #{@table_name}"
|
|
238
251
|
params = []
|
|
239
252
|
if limit
|
|
240
253
|
query << " LIMIT ?"
|
|
@@ -246,6 +259,15 @@ module Ea
|
|
|
246
259
|
end
|
|
247
260
|
[query, params]
|
|
248
261
|
end
|
|
262
|
+
|
|
263
|
+
# @param columns [Array<String>, nil] quoted identifier list, or
|
|
264
|
+
# "*" when no subset is requested
|
|
265
|
+
# @return [String] the SELECT list
|
|
266
|
+
def select_list(columns)
|
|
267
|
+
return "*" unless columns
|
|
268
|
+
|
|
269
|
+
columns.map { |name| %("#{name.to_s.gsub('"', '""')}") }.join(", ")
|
|
270
|
+
end
|
|
249
271
|
end
|
|
250
272
|
end
|
|
251
273
|
end
|
|
@@ -64,13 +64,13 @@ module Ea
|
|
|
64
64
|
|
|
65
65
|
# Check if type has length parameter
|
|
66
66
|
# @return [Boolean]
|
|
67
|
-
def
|
|
67
|
+
def length?
|
|
68
68
|
size == 1 || !haslength.nil?
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
# Check if type has precision parameter
|
|
72
72
|
# @return [Boolean]
|
|
73
|
-
def
|
|
73
|
+
def precision?
|
|
74
74
|
size == 2
|
|
75
75
|
end
|
|
76
76
|
|
|
@@ -47,13 +47,13 @@ module Ea
|
|
|
47
47
|
|
|
48
48
|
# Check if document has string content
|
|
49
49
|
# @return [Boolean]
|
|
50
|
-
def
|
|
50
|
+
def content?
|
|
51
51
|
!str_content.nil? && !str_content.empty?
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
# Check if document has binary content
|
|
55
55
|
# @return [Boolean]
|
|
56
|
-
def
|
|
56
|
+
def binary_content?
|
|
57
57
|
!bin_content.nil? && !bin_content.empty?
|
|
58
58
|
end
|
|
59
59
|
end
|
|
@@ -46,13 +46,13 @@ module Ea
|
|
|
46
46
|
|
|
47
47
|
# Check if script has content
|
|
48
48
|
# @return [Boolean]
|
|
49
|
-
def
|
|
49
|
+
def content?
|
|
50
50
|
!script.nil? && !script.empty?
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
# Check if script has notes
|
|
54
54
|
# @return [Boolean]
|
|
55
|
-
def
|
|
55
|
+
def notes?
|
|
56
56
|
!notes.nil? && !notes.empty?
|
|
57
57
|
end
|
|
58
58
|
end
|
|
@@ -140,16 +140,14 @@ module Ea
|
|
|
140
140
|
end
|
|
141
141
|
end
|
|
142
142
|
|
|
143
|
-
# Get list of enabled tables. In blob-free mode
|
|
144
|
-
#
|
|
145
|
-
#
|
|
143
|
+
# Get list of enabled tables. In blob-free mode blob-declaring
|
|
144
|
+
# tables stay enabled — their metadata loads normally while the
|
|
145
|
+
# loader excludes the blob columns themselves; blob content then
|
|
146
|
+
# resolves on demand via Database#blob_value.
|
|
146
147
|
#
|
|
147
148
|
# @return [Array<TableDefinition>] Array of enabled table definitions
|
|
148
149
|
def enabled_tables
|
|
149
|
-
|
|
150
|
-
return all if include_blobs
|
|
151
|
-
|
|
152
|
-
all.reject { |t| t.blob_columns&.any? }
|
|
150
|
+
tables&.select(&:enabled) || []
|
|
153
151
|
end
|
|
154
152
|
|
|
155
153
|
# Get table configuration by table name
|
|
@@ -106,19 +106,20 @@ module Ea
|
|
|
106
106
|
db = @connection.connection
|
|
107
107
|
|
|
108
108
|
database = Database.new(@qea_path, db)
|
|
109
|
+
# Kept for on-demand blob fetches after load (the connection
|
|
110
|
+
# itself closes in ensure; Database reopens per fetch).
|
|
111
|
+
database.blob_connection = @connection
|
|
109
112
|
|
|
110
113
|
@config.enabled_tables.each do |table_def|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
records = load_table_records(db, table_name)
|
|
115
|
-
database.add_collection(collection_name, records)
|
|
114
|
+
records = load_table_records(db, table_def)
|
|
115
|
+
database.add_collection(table_def.collection_name, records)
|
|
116
116
|
end
|
|
117
117
|
|
|
118
118
|
database.freeze
|
|
119
119
|
ensure
|
|
120
|
-
# All tables are in memory; nothing
|
|
121
|
-
#
|
|
120
|
+
# All tables are in memory; nothing keeps the handle open, and
|
|
121
|
+
# an open handle locks the file on Windows. Blob fetches go
|
|
122
|
+
# through Database#blob_value, which reopens per call.
|
|
122
123
|
@connection.close
|
|
123
124
|
end
|
|
124
125
|
|
|
@@ -139,7 +140,7 @@ module Ea
|
|
|
139
140
|
end
|
|
140
141
|
|
|
141
142
|
@connection.with_connection do |db|
|
|
142
|
-
load_table_records(db,
|
|
143
|
+
load_table_records(db, table_def)
|
|
143
144
|
end
|
|
144
145
|
end
|
|
145
146
|
|
|
@@ -164,20 +165,22 @@ module Ea
|
|
|
164
165
|
# Load records for a table
|
|
165
166
|
#
|
|
166
167
|
# @param db [SQLite3::Database] Database connection
|
|
167
|
-
# @param
|
|
168
|
+
# @param table_def [Configuration::TableDefinition] Table config
|
|
168
169
|
# @return [Array] Array of model instances
|
|
169
|
-
def load_table_records(db,
|
|
170
|
+
def load_table_records(db, table_def)
|
|
171
|
+
table_name = table_def.table_name
|
|
170
172
|
model_class = MODEL_CLASSES[table_name]
|
|
171
173
|
raise ArgumentError, "No model class for table #{table_name}" unless model_class
|
|
172
174
|
|
|
173
175
|
reader = Infrastructure::TableReader.new(db, table_name)
|
|
174
176
|
return [] unless reader.table_exists?
|
|
175
177
|
|
|
178
|
+
columns = load_columns(reader, table_def)
|
|
176
179
|
total = reader.count
|
|
177
180
|
records = []
|
|
178
181
|
index = 0
|
|
179
182
|
|
|
180
|
-
reader.each_row do |row|
|
|
183
|
+
reader.each_row(columns: columns) do |row|
|
|
181
184
|
index += 1
|
|
182
185
|
record = model_class.from_db_row(scrub_row(row))
|
|
183
186
|
records << record if record
|
|
@@ -197,6 +200,23 @@ module Ea
|
|
|
197
200
|
records
|
|
198
201
|
end
|
|
199
202
|
|
|
203
|
+
# Column subset for the load. In blob-free mode the declared
|
|
204
|
+
# blob columns are cut from the SELECT — the table's metadata
|
|
205
|
+
# still loads and the blob resolves on demand via
|
|
206
|
+
# Database#blob_value.
|
|
207
|
+
#
|
|
208
|
+
# @param reader [Infrastructure::TableReader]
|
|
209
|
+
# @param table_def [Configuration::TableDefinition]
|
|
210
|
+
# @return [Array<String>, nil] columns to select, nil for all
|
|
211
|
+
def load_columns(reader, table_def)
|
|
212
|
+
return nil if @config.include_blobs
|
|
213
|
+
|
|
214
|
+
blobs = Array(table_def.blob_columns)
|
|
215
|
+
return nil if blobs.empty?
|
|
216
|
+
|
|
217
|
+
reader.column_names - blobs
|
|
218
|
+
end
|
|
219
|
+
|
|
200
220
|
# Replace invalid byte sequences (e.g. CP1252 bytes stored by
|
|
201
221
|
# older EA projects) so one bad field no longer drops the whole
|
|
202
222
|
# row at model-build time.
|
|
@@ -44,19 +44,19 @@ module Ea
|
|
|
44
44
|
lines << summary
|
|
45
45
|
lines << ""
|
|
46
46
|
|
|
47
|
-
if result.
|
|
47
|
+
if result.errors?
|
|
48
48
|
lines << section_header("ERRORS", result.errors.size)
|
|
49
49
|
lines << format_messages(result.errors)
|
|
50
50
|
lines << ""
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
if result.
|
|
53
|
+
if result.warnings?
|
|
54
54
|
lines << section_header("WARNINGS", result.warnings.size)
|
|
55
55
|
lines << format_messages(result.warnings)
|
|
56
56
|
lines << ""
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
if result.
|
|
59
|
+
if result.info? && options[:verbose]
|
|
60
60
|
lines << section_header("INFO", result.info.size)
|
|
61
61
|
lines << format_messages(result.info)
|
|
62
62
|
lines << ""
|
|
@@ -87,7 +87,7 @@ module Ea
|
|
|
87
87
|
def summary
|
|
88
88
|
status = if result.valid?
|
|
89
89
|
colorize("✓ VALID", :green, bold: true)
|
|
90
|
-
elsif result.
|
|
90
|
+
elsif result.errors?
|
|
91
91
|
colorize("✗ INVALID", :red, bold: true)
|
|
92
92
|
else
|
|
93
93
|
colorize("⚠ WARNINGS", :yellow, bold: true)
|