PATTERNS OF DATA MODELING- P18 pptx

5 207 0
PATTERNS OF DATA MODELING- P18 pptx

Đang tải... (xem toàn văn)

Thông tin tài liệu

66 Chapter 4 / Undirected Graph Template Figure 4.7 shows a model for the LinkedIn network using the node and edge undirected graph template. The LinkedIn Web site manages extensive data about members that Figure 4.7 does not show as the emphasis is on the template. 4.2 Connection Undirected Graph Template 4.2.1 UML Template Figure 4.8 elaborates the node and edge template, promoting the connection between nodes and edges to an entity type. Figure 4.8, as stated, does not permit unconnected Nodes. You could add a relationship between UDG and Node if unconnected Nodes were important. A UDG (undirected graph) is a set of nodes and a set of edges that connect nodes. You need not show UDG in a use of the template. A Node is an entity type whose records are Figure 4.6 Node and edge undirected graph: Populated tables. B c d e C D E F A f g hi Node table node ID node Name udg ID 1 A1 2 B1 3 C1 4 D1 5 E1 6 F1 Edge table edge ID edge Name udg ID 51 c1 52 d1 53 e1 54 f1 55 g1 56 h1 57 i1 Node_Edge table node ID edge ID 151 351 152 452 153 553 254 Node_Edge table (cont) node ID edge ID 554 355 655 456 656 557 657 * 2 Figure 4.7 Node and edge undirected graph: Personal networking model. Member name Link emailAddress password 4.2 Connection Undirected Graph Template 67 organized as an undirected graph. An Edge is a coupling between Nodes. A Connection is the linking between a Node and an Edge. With this template the names of nodes and edges are globally unique. There is no context to provide an alternative approach to naming. Figure 4.8 lacks the constraint that related nodes and edges must all belong to the same undirected graph. 4.2.2 IDEF1X Template Figure 4.9 restates Figure 4.8 with the IDEF1X notation. The following are foreign keys: udgID references UDG, nodeID references Node, and edgeID references Edge. The combi- nation of nodeID + edgeID need not be unique for a Connection as a Node and Edge can con- nect twice. 4.2.3 SQL Queries Figure 4.10 and Figure 4.11 show SQL queries for common traversals of the template. The colon prefix denotes variable values that must be provided for each query. 4.2.4 Sample Populated Tables Figure 4.12 and Figure 4.13 show connection undirected graph tables populated with data. The values of the IDs are arbitrary, but internally consistent. <UDG> <Node> <Edge> 0 1 1 * 21 Figure 4.8 Connection undirected graph: UML template. Use when there is data for the connection itself or edges connect to the same node. * <Connection> connectionID Connection udgID (FK) nodeID (FK) edgeID (FK) Figure 4.9 Connection undirected graph: IDEF1X template. nodeID nodeName (AK1.1) Node edgeID edgeName (AK1.1) Edge udgID UDG 68 Chapter 4 / Undirected Graph Template Figure 4.10 Connection undirected graph: SQL query. Find the edges that connect to a node and how often they connect. SELECT E.edgeID, E.edgeName, COUNT(*) AS edgeCount FROM Node as N INNER JOIN Connection AS C ON N.nodeID = C.nodeID INNER JOIN Edge AS E ON C.edgeID = E.edgeID WHERE N.nodeID = :aNodeID GROUP BY E.edgeID, E.edgeName ORDER BY E.edgeName; Figure 4.11 Connection undirected graph: SQL query. Find the nodes for an edge and how often they connect. SELECT DISTINCT N.nodeID, N.nodeName, COUNT(*) AS nodeCount FROM Edge AS E INNER JOIN Connection AS C ON E.edgeID = C.edgeID INNER JOIN Node AS N ON C.nodeID = N.nodeID WHERE E.edgeID = :anEdgeID GROUP BY N.nodeID, N.nodeName ORDER BY N.nodeName; B c d e C D E F A f g hi Node table node ID node Name 1 A 2 B 3 C 4 D 5 E 6 F Connection table connec tionID node ID edge ID udg ID 1 1511 2 3511 3 1521 4 4521 5 1531 6 5531 7 2541 Figure 4.12 Connection undirected graph: Populated tables. Edge table edge ID edge Name 51 c 52 d 53 e 54 f 55 g 56 h 57 i Connection table (cont) connec tionID node ID edge ID udg ID 8 5541 9 3551 10 6551 11 4561 12 6561 13 5571 14 6571 4.3 Undirected Graph Changing over Time Template 69 4.2.5 Examples Figure 4.14 illustrates the template. A manufacturing plant can have a variety of equipment that is connected by piping. For stress calculations, all that matters is that the equipment is connected. Stress calculations ensure that piping does not break under the load of forces such as wind and temperature changes. 4.3 Undirected Graph Changing over Time Template This template adds time intervals to the Node and Edge entity types from Section 4.1. 4.3.1 UML Template Figure 4.15 shows the template for the node and edge undirected graphs that change over time, extending the template in Figure 4.2. The template in Figure 4.15 cannot handle edges that connect twice to the same node. A UDG (undirected graph) is a set of nodes and a set of edges that connect nodes. (Note: in an undirected graph all the nodes need not be connected.) You need not show UDG in a Figure 4.13 Connection undirected graph: Populated tables. Node table node ID node Name 11 X 12 Y Connection table connec tionID node ID edge ID udg ID 21 11 11 2 22 12 11 2 23 11 12 2 Edge table edge ID edge Name 11 r 12 s 13 t Connection table (cont) connec tionID node ID edge ID udg ID 24 12 12 2 25 11 13 2 26 11 13 2 YX r s t Figure 4.14 Connection undirected graph: Equipment and piping model. Equipment Piping 1 * 21 Nozzle ManufacturingPlant 1 * 70 Chapter 4 / Undirected Graph Template use of the template. A Node is an entity type whose records are organized as an undirected graph. An Edge is a coupling between Nodes. With this template the names of nodes and edges are globally unique. There is no context to provide an alternative approach to naming. 4.3.2 IDEF1X Template Figure 4.16 restates Figure 4.15 with the IDEF1X notation. The following are foreign keys: udgID references UDG, nodeID references Node, and edgeID references Edge. In Figure 4.16 the node name can change over time (three part candidate key—nodeName + effective- Date + expirationDate), but the node name could also be invariant over time (candidate key of nodeName alone). Similarly the edge name could be invariant over time. 4.3.3 SQL Queries Figure 4.17 and Figure 4.18 show SQL queries for common traversals of the template. The colon prefix denotes variable values that must be provided for each query. With this template an edge cannot connect twice to the same node, so there is no need to group nodes in Figure 4.18. 4.3.4 Sample Populated Tables Figure 4.19 shows tables populated with data for the node and edge undirected graph chang- ing over time. The values of the IDs are arbitrary, but internally consistent. A null effective- * 2 <UDG> 0 1 0 1 ** Figure 4.15 Undirected graph changing over time: UML template. Use when history must be recorded and no edges connect to the same node. <Node> effectiveDate expirationDate <Edge> effectiveDate expirationDate Figure 4.16 Undirected graph changing over time: IDEF1X template. nodeID udgID (FK) nodeName (AK1.1) Node edgeID udgID (FK) edgeName (AK1.1) Edge Node_Edge nodeID (FK) edgeID (FK) effectiveDate (AK1.2) expirationDate (AK1.3) effectiveDate (AK1.2) expirationDate (AK1.3) udgID UDG . Nodes were important. A UDG (undirected graph) is a set of nodes and a set of edges that connect nodes. You need not show UDG in a use of the template. A Node is an entity type whose records. combi- nation of nodeID + edgeID need not be unique for a Connection as a Node and Edge can con- nect twice. 4.2.3 SQL Queries Figure 4.10 and Figure 4.11 show SQL queries for common traversals of the. Tables Figure 4.12 and Figure 4.13 show connection undirected graph tables populated with data. The values of the IDs are arbitrary, but internally consistent. <UDG> <Node> <Edge> 0

Ngày đăng: 05/07/2014, 06:20

Mục lục

    PATTERNS OF DATA MODELING

    Who Should Read This Book?

    What You Will Find

    Comparison with Other Books

    1.1 What Is a Model?

    1.3 What Is a Pattern?

    1.4 Why Are Patterns Important?

    1.7 Aspects of Pattern Technology

    Part I: Mathematical Templates

    2.5 Tree Changing over Time Template

Tài liệu cùng người dùng

Tài liệu liên quan