Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
PATTERNS OF DATA MODELING- P19: Models provide the means for building quality software in a predictable manner. Models let developers think deeply about software and cope with large size and complexity. Developers can think abstractly before becoming enmeshed in the details of writing code. Although models are beneficial, they can be difficult to construct. That is where patterns come in. Patterns provide building blocks that help developers construct models faster and better. | 4.3 Undirected Graph Changing over Time Template 71 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.17 Undirected graph changing over time SQL query. Find the edges that connect to a node. 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 Figure 4.18 Undirected graph changing over time SQL query. Find the nodes for an edge. 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. 72 Chapter 4 Undirected Graph Template Undirected graph 1 July 2000 0100 Node table Undirected graph 1 July 2000 0300 Edge table node ID node Name effective Date expiration Date udg ID 1 A 1 2 B 1 July 2000 0100 1 3 C 1 4 D 1 5 E 1 6 F 1 7 G 1 July 2000 0300 1 edge ID edge Name effective Date expiration Date udg ID 51 c 1 52 d 1 53 e 1 54 f 1 July 2000 0100 1 55 g 1 56 h 1 57 i 1 58 j 1 July 2000 0300 1 Node_Edge table nodeID edgeID 1 51 3 51 1 52 4 52 1 53 5 53 2 54 5 54 Node_Edge table cont nodeID .