PATTERNS OF DATA MODELING- P15 pptx

5 257 0
PATTERNS OF DATA MODELING- P15 pptx

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

Thông tin tài liệu

3.4 Connection Directed Graph Template 51 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 source OrSink 1 151source 2 351sink 3 152source 4 452sink 5 153source 6 553sink 7 254source Figure 3.32 Connection directed 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 source OrSink 8 554sink 9 355source 10 655sink 11 456source 12 656sink 13 557source 14 657sink B c d e C D E F A f g hi Figure 3.33 Connection directed graph: Populated tables. Node table node ID node Name 11 X 12 Y Connection table connec tionID node ID edge ID source OrSink 21 11 61 source 22 12 61 sink 23 11 62 source Edge table edge ID edge Name 61 r 62 s 63 t Connection table (cont) connec tionID node ID edge ID source OrSink 24 12 62 sink 25 11 63 source 26 11 63 sink YX r s t 52 Chapter 3 / Directed Graph Template 3.4.5 Example The connection template is sometimes helpful for representing directed graphs as Figure 3.34 illustrates. A manufacturing plant can have a variety of equipment that is connected by piping. Nozzles connect piping to equipment and have a direction of normal fluid flow. 3.5 Simple DG Changing over Time Template There are two templates for directed graphs that can change over time. The first (this section) is based on the simple directed graph. The second (next section) is based on the node and edge directed graph. It is also possible to extend the connection template for variations over time, but I have never seen it used in practice. 3.5.1 UML Template The template for simple directed graphs that change over time (Figure 3.35) is similar to the tree template in Section 2.5. Figure 3.35 separates an entity from its directed graph position (node) because the timeline for an entity can differ from that of its involvement in a graph. A DG (directed graph) is a set of nodes and a set of directed edges that connect nodes. (Note: in a directed graph all the nodes do not have to be connected.) You need not show DG Equipment Piping 211 * Figure 3.34 Connection directed graph: Equipment and piping model. Nozzle sourceOrSink ManufacturingPlant 1 * Figure 3.35 Simple directed graph changing over time: UML template. Use when edges are unimportant and history must be recorded. root {Each node has at least one parent except for root nodes.} 0 1 <Node> effectiveDate expirationDate <Binding> effectiveDate expirationDate ** 11 <DG> <Entity> effectiveDate expirationDate <NodeLink> effectiveDate expirationDate ** 11parent child * {There cannot be any cycles.} 3.5 Simple DG Changing over Time Template 53 in a use of the template. A Node is a position within a directed graph. The distinction be- tween parent and child causes the sense of direction that effects directed edges. Figure 3.35 adds the constraint that each node has at least one parent except for root nodes. (The template itself is more permissive and lacks this constraint.) In general, a direct- ed graph may have cycles but this template disallows them. (A cycle starts at a node and after traversing a series of edges reaches the starting node.) Since this template is based on a tree template, it doesn’t make sense to permit cycles. This template is already complex, so it is best to handle node names in a simple manner. Each node has a globally unique name and there is no provision to vary node name by con- text. The effective and expiration dates permit Node and Entity data to vary over time. 3.5.2 IDEF1X Template Figure 3.36 restates Figure 3.35 with the IDEF1X notation. The following are foreign keys: dgID references DG, nodeID references Node, entityID references Entity, parentNodeID ref- erences Node, and childNodeID references Node. In Figure 3.36 the node name can change over time (three part candidate key—node- Name + effectiveDate + expirationDate), but the node name could also be invariant over time (candidate key of nodeName alone). Note that the handling of time reflects a limitation of relational DBMSs. It would be better to use time intervals but most relational DBMSs only support points in time. 3.5.3 SQL Queries Figure 3.37 and Figure 3.38 show SQL queries for common traversals of the template. The colon prefix denotes variable values that must be provided for each query. bindingID Binding effectiveDate expirationDate nodeID (FK) entityID (FK) nodeID Node nodeName (AK1.1) effectiveDate (AK1.2) expirationDate (AK1.3) entityID Entity effectiveDate expirationDate nodeLinkID NodeLink effectiveDate expirationDate parentNodeID (FK) childNodeID (FK) Figure 3.36 Simple directed graph changing over time: IDEF1X template. dgID (FK) dgID DG 54 Chapter 3 / Directed Graph Template Figure 3.37 Simple directed graph changing over time: SQL query. Find the parents for a child node. SELECT Parent.nodeID AS parentNodeID, Parent.nodeName AS parentNodeName FROM Node AS Child INNER JOIN NodeLink AS NL ON Child.nodeID = NL.childNodeID INNER JOIN Node AS Parent ON NL.parentNodeID = Parent.nodeID WHERE Child.nodeID = :aChildNodeID AND (Child.effectiveDate IS NULL OR :aDate >= Child.effectiveDate) AND (Child.expirationDate IS NULL OR :aDate <= Child.expirationDate) AND (NL.effectiveDate IS NULL OR :aDate >= NL.effectiveDate) AND (NL.expirationDate IS NULL OR :aDate <= NL.expirationDate) AND (Parent.effectiveDate IS NULL OR :aDate >= Parent.effectiveDate) AND (Parent.expirationDate IS NULL OR :aDate <= Parent.expirationDate) ORDER BY Parent.nodeName; Figure 3.38 Simple directed graph changing over time: SQL query. Find the children for a parent node. SELECT Child.nodeID AS childNodeID, Child.nodeName AS childNodeName FROM Node AS Child INNER JOIN NodeLink AS NL ON Child.nodeID = NL.childNodeID INNER JOIN Node AS Parent ON NL.parentNodeID = Parent.nodeID WHERE Parent.nodeID = :aParentNodeID AND (Child.effectiveDate IS NULL OR :aDate >= Child.effectiveDate) AND (Child.expirationDate IS NULL OR :aDate <= Child.expirationDate) AND (NL.effectiveDate IS NULL OR :aDate >= NL.effectiveDate) AND (NL.expirationDate IS NULL OR :aDate <= NL.expirationDate) AND (Parent.effectiveDate IS NULL OR :aDate >= Parent.effectiveDate) AND (Parent.expirationDate IS NULL OR :aDate <= Parent.expirationDate) ORDER BY Child.nodeName; 3.5 Simple DG Changing over Time Template 55 3.5.4 Sample Populated Tables Figure 3.39 shows tables populated with data for the simple directed graph changing over time. The values of the IDs are arbitrary, but internally consistent. A null effectiveDate means that a Node applies indefinitely from the past. A null expirationDate means that a Node applies indefinitely into the future. In accordance with the template, there are no ex- plicit edges and edges are represented via the coupling between nodes. As in Section 3.1, the template cannot express directed graphs with multiple edges be- tween a pair of nodes. For brevity, the Node table omits the dgID column. This simple ex- ample does not populate Binding and Entity. 3.5.5 Example Figure 3.40 revisits the example from Section 2.5. The management structure can be a ma- trix, instead of a simple hierarchy; then a person can report to more than one manager at the Directed graph, 1 July 2000 0100 Node table node ID node Name effective Date expiration Date 1 J 2 K 3 L 4 M 5 X 6 N1 July 2000 0100 7 O1 July 2000 0300 Directed graph, 1 July 2000 0300 NodeLink table node link ID effective Date expiration Date parent Node ID child Node ID 1 12 2 13 3 24 4 25 5 35 6 1 July 2000 0100 36 7 1 July 2000 0300 37 Figure 3.39 Simple directed graph changing over time: Populated tables. NM LK J X OM LK J X . because the timeline for an entity can differ from that of its involvement in a graph. A DG (directed graph) is a set of nodes and a set of directed edges that connect nodes. (Note: in a directed. node name could also be invariant over time (candidate key of nodeName alone). Note that the handling of time reflects a limitation of relational DBMSs. It would be better to use time intervals. Changing over Time Template 53 in a use of the template. A Node is a position within a directed graph. The distinction be- tween parent and child causes the sense of direction that effects directed

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

  • Đang cập nhật ...

Tài liệu liên quan