Sparx EA has the ability to “visually” link a connector between two elements to a start and end at specific attributes under those elements. A few years ago I dug in to the repository and figured out where and how this information is stored so I can include it in my reports.
If you don’t know what I’m referring to:
- create a class diagram,
- create 2 classes,
- create attributes under those two classes,
- create an association connector between the two classes,
- right click on that connector
- select link to element feature
- select attribute (note the selected parent element is the element that was closest to where you “right clicked” on the connector)
- select one of the attributes
Analysis
Unfortunately Sparx EA’s built in reporting features do not let you use this information, but I found a way to create an SQL script fragment that would let me use this information in my reports. E.g. a list of “connected” attributes.
First was learning how the information about what attribute to point to is stored in the repository. After a bit of searching I found that it’s stored as a name = value pair in the .StyleEx field in the t_connector table.
At this time I can ignore the appended L and R that follow the GUIDs, and I can pretty much ignore the LFEP and LFSP too buy filtering out all attributes that have the selected element as their parent.
SQL Query
For this example the query will return all the attributes connected to Class 1, in this case the only attribute returned will be Attribute 3.
- Select (qAttributes)
- All the connectors starting or ending with the selected element (Class 1, which has the Start_Object_ID = 172 or End_Object_ID = 172) .
- From each of these connectors get the GUIDs of the referenced Attribute(s) from the StyleEX field.
- Select all the Attributes with GUIDs matching those returned by qAttributes. Except the attributes that are children selected element (Object_ID = 172)
Using this query:
- Replace 172 with #ObjectID# to use this query in a template fragment.
- Replace 172 with #CurrentElementID# to use this query in a custom search.
For MS Access (.EAP files) and MySQL
SELECT Name FROM t_attribute INNER JOIN ( SELECT MID(StyleEx,INSTR(StyleEx,'LFSP')+5,38) AS ea_guid FROM t_connector WHERE Start_Object_ID = 172 UNION ALL SELECT MID(StyleEx,INSTR(StyleEx,'LFEP')+5,38) AS ea_guid FROM t_connector WHERE Start_Object_ID = 172 UNION ALL SELECT MID(StyleEx,INSTR(StyleEx,'LFSP')+5,38) AS ea_guid FROM t_connector WHERE End_Object_ID = 172 UNION ALL SELECT MID(StyleEx,INSTR(StyleEx,'LFEP')+5,38) AS ea_guid FROM t_connector WHERE End_Object_ID = 172 ) qAttributes ON qAttributes.ea_guid = t_attribute.ea_guid WHERE t_attribute.Object_ID <> 172
Other Data Base Repositories
The MID and/or INSTR function(s) will likely need to be replaced for this query to work with other Data Bases. For Example:
- Oracle: Replace the MID function with the SUBSTR function. E.g. SUBSTR(StyleEx,INSTR(StyleEx,’LFSP’)+5,38)
- MS SQL: Replace the MID function with the SUBSTRING function, and the INSTR function with the CHARINDEX function. E.g. SUBSTRING(StyleEx,CHARINDEX(‘LFSP’,StyleEx)+5,38)