4.3 Undirected Graph Changing over Time Template 71 Date means that a Node applies from the past. A null expirationDate means that a Node applies into the future. 4.3.5 Example An extended model (Figure 4.20) could add the aspect of time to the LinkedIn example. Such a model could track the history of members and connections. From firsthand experience with LinkedIn, I know this is a realistic example. Member data (not shown in the model) changes over time. Also links can come and go as users join and leave the Web site. Figure 4.17 Undirected graph changing over time: SQL query. Find the edges that connect to a node. SELECT E.edgeID, E.edgeName FROM Node as N INNER JOIN Node_Edge AS NE ON N.nodeID = NE.nodeID INNER JOIN Edge AS E ON NE.edgeID = E.edgeID WHERE N.nodeID = :aNodeID AND (E.effectiveDate IS NULL OR :aDate >= E.effectiveDate) AND (E.expirationDate IS NULL OR :aDate <= E.expirationDate) AND (N.effectiveDate IS NULL OR :aDate >= N.effectiveDate) AND (N.expirationDate IS NULL OR :aDate <= N.expirationDate) ORDER BY E.edgeName; Figure 4.18 Undirected graph changing over time: SQL query. Find the nodes for an edge. SELECT N.nodeID, N.nodeName FROM Edge AS E INNER JOIN Node_Edge AS NE ON E.edgeID = NE.edgeID INNER JOIN Node AS N ON NE.nodeID = N.nodeID WHERE E.edgeID = :anEdgeID AND (E.effectiveDate IS NULL OR :aDate >= E.effectiveDate) AND (E.expirationDate IS NULL OR :aDate <= E.expirationDate) AND (N.effectiveDate IS NULL OR :aDate >= N.effectiveDate) AND (N.expirationDate IS NULL OR :aDate <= N.expirationDate) ORDER BY N.nodeName; 72 Chapter 4 / Undirected Graph Template Undirected graph, 1 July 2000 0100 B c d e C D E F A f g hi Node table node ID node Name effective Date expiration Date udg ID 1 A1 2 B1 July 2000 0100 1 3 C1 4 D1 5 E1 6 F1 7 G1 July 2000 0300 1 Undirected graph, 1 July 2000 0300 G c d e C D E F A j g hi Figure 4.19 Undirected graph changing over time: Populated tables. Edge table edge ID edge Name effective Date expiration Date udg ID 51 c1 52 d1 53 e1 54 f1 July 2000 0100 1 55 g1 56 h1 57 i1 58 j1 July 2000 0300 1 Node_Edge table nodeID edgeID 151 351 152 452 153 553 254 554 Node_Edge table (cont) nodeID edgeID 355 655 456 656 557 657 558 758 4.4 Chapter Summary 73 4.4 Chapter Summary Undirected graphs occasionally occur and can be a critical issue for representation. There are three templates for undirected graphs that have different trade-offs. • Node and edge undirected graph. Use as the default template when there are no edges that connect to the same node. • Connection undirected graph. Use when it is important to store data about the connec- tion itself or there are edges that connect to the same node. • Undirected graph changing over time. Use when history must be recorded. Table 4.1 summarizes the undirected graph templates. Figure 4.20 Undirected graph changing over time: Personal networking model. * 2 Member name Link emailAddress password effectiveDate expirationDate effectiveDate expirationDate Template name Synopsis UML template Use when Frequency Node and edge undirected graph Treats nodes and edges as peers. No edge con- nects to the same node. Occasional Connection undirected graph Promotes the con- nection between a node and an edge to an entity type. There is data for the connection itself or there is an edge that con- nects to the same node. Occasional Undirected graph changing over time Stores multiple variants of a UDG. Extract a particular UDG by specifying a time. History must be recorded. No edge connects to the same node. Seldom Table 4.1 Summary of the Undirected Graph Templates Note: This table can help you choose among the undirected graph templates. 74 5 Item Description Template There are two templates that involve items and their description. • Item description. Arises when the same model relates data and metadata. The item de- scription template frequently occurs, but is visually less striking than other templates in this book—the template involves only two entity types and one relationship. You must exercise judgment in deciding when one entity type is metadata with regard to another. • Homomorphism. Maps between two Item Description templates and expresses an anal- ogy. The description of item 1 is to item 1 as the description of item 2 is to item 2. The relationship between items connects occurrences. The relationship between descriptions constrains occurrences. 5.1 Item Description Template 5.1.1 UML Template Figure 5.1 shows the UML template for item description. The template involves data (Item) and metadata (ItemDescription) and typically appears when a model concerns both an item and its description. It is important to keep the two planes (data and metadata) separate or the model will be deeply flawed. A color coding or shading convention can be helpful; Figure 5.1 uses a white background for data and a light gray for metadata. The item description template is useful if you cannot fully describe data as software is being developed. The template lets you enter data and its description at run time, as opposed to the more typical approach of defining data structure at compile time. Table 5.1 compares Item and ItemDescription. 5.1 Item Description Template 75 5.1.2 IDEF1X Template Figure 5.2 restates Figure 5.1 with the IDEF1X notation. The following is a foreign key: itemDescriptionID references ItemDescription. 5.1.3 SQL Queries Figure 5.3 and Figure 5.4 show representative SQL queries for the template. The colon prefix denotes variable values that must be provided. 5.1.4 Sample Populated Tables Figure 5.5 shows item description tables populated with data. The values of the IDs are ar- bitrary, but internally consistent. <Item> <ItemDescription> 1 * Metadata Data Figure 5.1 Item description: UML template. Use when the same model relates data and metadata. ItemDescription Item Characterization Metadata Data Flexibility General purpose Specific Volatility Changes slowly Can change quickly Authorization Requires high authori- zation level to modify Depends on the appli- cation Number of records Few records Many records Table 5.1 Comparison of Item (data) and ItemDescription (metadata) Figure 5.2 Item description: IDEF1X template. itemDescriptionID ItemDescription itemID name Item itemDescriptionID (FK) name . background for data and a light gray for metadata. The item description template is useful if you cannot fully describe data as software is being developed. The template lets you enter data and its. involves data (Item) and metadata (ItemDescription) and typically appears when a model concerns both an item and its description. It is important to keep the two planes (data and metadata) separate. description tables populated with data. The values of the IDs are ar- bitrary, but internally consistent. <Item> <ItemDescription> 1 * Metadata Data Figure 5.1 Item description: UML