PATTERNS OF DATA MODELING- P14 pot

5 247 0
PATTERNS OF DATA MODELING- P14 pot

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

Thông tin tài liệu

46 Chapter 3 / Directed Graph Template 3.3.3 SQL Queries Figure 3.20, Figure 3.21, and Figure 3.22 show SQL queries for common traversals of the template. The colon prefix denotes variable values that must be provided for each query. Figure 3.19 Node and edge directed graph: IDEF1X template. nodeID dgID (FK) nodeName (AK1.1) Node edgeID dgID (FK) edgeName (AK1.1) Edge sourceNodeID (FK) sinkNodeID (FK) dgID DG Figure 3.20 Node and edge directed graph: SQL query. Find the edges that originate from a node. SELECT E.edgeID, E.edgeName FROM Edge AS E INNER JOIN Node AS Source ON E.sourceNodeID = Source.nodeID WHERE Source.nodeID = :aSourceNodeID ORDER BY E.edgeName; Figure 3.21 Node and edge directed graph: SQL query. Find the edges that terminate at a node. SELECT E.edgeID, E.edgeName FROM Edge AS E INNER JOIN Node AS Sink ON E.sinkNodeID = Sink.nodeID WHERE Sink.nodeID = :aSinkNodeID ORDER BY E.edgeName; Figure 3.22 Node and edge directed graph: SQL query. Find the source and sink nodes for an edge. SELECT Src.nodeID AS srcNodeID, Src.nodeName AS srcNodeName, Sink.nodeID AS sinkNodeID, Sink.nodeName AS sinkNodeName FROM Edge AS E INNER JOIN Node AS Src ON E.sourceNodeID = Src.nodeID INNER JOIN Node AS Sink ON E.sinkNodeID = Sink.nodeID WHERE E.edgeID = :anEdgeID; 3.3 Node and Edge Directed Graph Template 47 3.3.4 Sample Populated Tables Figure 3.23 and Figure 3.24 show node and edge directed graph tables populated with data. The values of the IDs are arbitrary, but internally consistent. Figure 3.23 Node and edge directed graph: Populated tables. Node table node ID dgID node Name 1 1A 2 1B 3 1C 4 1D 5 1E 6 1F Edge table edgeID dgID edgeName sourceNodeID sinkNodeID 51 1c 1 3 52 1d 1 4 53 1e 1 5 54 1f 2 5 55 1g 3 6 56 1h 4 6 57 1i 5 6 B c d e C D E F A f g hi Figure 3.24 Node and edge directed graph: Populated tables. Node table node ID dgID node Name 11 2X 12 2Y Edge table edgeID dgID edgeName sourceNodeID sinkNodeID 61 2 r 11 12 62 2 s 11 12 63 2 t 11 11 YX r s t 48 Chapter 3 / Directed Graph Template 3.3.5 Examples The node and edge directed graph is the most common representation. Figure 3.25 shows an example for published flights. Airlines operate flights between airports. A PublishedFlight refers to the published de- scription of air travel between two airports. The frequency indicates the days of the week for which the PublishedFlight applies. A PublishedFlight consists of a sequence of Published- FlightLegs that describe the travel from airport to airport. Figure 3.26 shows an excerpt of a model for supply chain tracing for food manufacture. The application traces foodstuffs (MaterialLots) as they proceed from the farm to manufac- turers, distributors, and eventually the marketplace (various SupplyChainStages). Using the node and edge template, intervening MaterialLots connect a network of SupplyChainStages. A SupplyChainStage may have any number of MaterialLots as input and any number as output. A MaterialLot may enter and exit at most one SupplyChainStage. Although the mod- el does not enforce it (application code must enforce it), the entering and exiting MaterialLot for a SupplyChainStage must be different. 3.4 Connection Directed Graph Template 3.4.1 UML Template Figure 3.27 elaborates the node and edge template, promoting the connection between nodes and edges to an entity type. Figure 3.27, as stated, does not permit unconnected Nodes. You could add a relationship between DG and Node if unconnected Nodes were important. Figure 3.25 Node and edge directed graph: Airline flight model. PublishedFlight frequency airlineName airlineCode Airline 0 11 flightNumber PublishedFlightLeg scheduledDepartureTime scheduledDuration 1 {ordered} * iataCode airportName Airport * * 1 1 scheduledOrigin scheduledDestination in out * * 0 1 0 1 MaterialLot materialLotType SupplyChainStage supplyChainStageType Figure 3.26 Node and edge directed graph: Supply chain tracing model. quantityname * * 3.4 Connection Directed Graph Template 49 A DG (directed graph) is a set of nodes and a set of directed edges that connect nodes. You need not show DG in a use of the template. A Node is an entity type whose records are organized as a directed graph. An Edge is a coupling from a source Node to a sink Node. A Connection is the linking between a Node and an Edge. Each Connection may be a source or a sink. With this template the names of nodes and edges are globally unique. There is no context to provide an alternative approach to naming. Figure 3.27 lacks the constraint that nodes and edges may only have connections for one directed graph. The template also lacks the constraint that an edge must have one source node and one sink node. 3.4.2 IDEF1X Template Figure 3.28 restates Figure 3.27 with the IDEF1X notation. The following are foreign keys: dgID references DG, nodeID references Node, and edgeID references Edge. 3.4.3 SQL Queries Figure 3.29, Figure 3.30, and Figure 3.31 show SQL queries for common traversals of the template. The colon prefix denotes variable values that must be provided for each query. <DG> <Node> <Edge> 0 1 1 * 21 Figure 3.27 Connection directed graph: UML template. Use when it is important to store data about the connection itself. * <Connection> sourceOrSink connectionID Connection dgID (FK) nodeID (FK) edgeID (FK) sourceOrSink Figure 3.28 Connection directed graph: IDEF1X template. DG nodeID nodeName (AK1.1) Node edgeID edgeName (AK1.1) Edge dgID 50 Chapter 3 / Directed Graph Template 3.4.4 Sample Populated Tables Figure 3.32 and Figure 3.33 show connection directed graph tables populated with data. The values of the IDs are arbitrary, but internally consistent. For brevity, the Connection tables omit the dgID column. Figure 3.29 Connection directed graph: SQL query. Find the edges that originate from a node. SELECT E.edgeID, E.edgeName FROM Edge AS E INNER JOIN Connection AS C ON E.edgeID = C.edgeID AND C.sourceOrSink = ‘source’ INNER JOIN Node AS Source ON C.nodeID = Source.nodeID WHERE Source.nodeID = :aSourceNodeID ORDER BY E.edgeName; Figure 3.30 Connection directed graph: SQL query. Find the edges that terminate at a node. SELECT E.edgeID, E.edgeName FROM Edge AS E INNER JOIN Connection AS C ON E.edgeID = C.edgeID AND C.sourceOrSink = ‘sink’ INNER JOIN Node AS Sink ON C.nodeID = Sink.nodeID WHERE Sink.nodeID = :aSinkNodeID ORDER BY E.edgeName; Figure 3.31 Connection directed graph: SQL query. Find the source and sink nodes for an edge. SELECT Source.nodeID AS sourceNodeID, Source.nodeName AS sourceNodeName, Sink.nodeID AS sinkNodeID, Sink.nodeName AS sinkNodeName FROM Edge AS E INNER JOIN Connection AS C1 ON E.edgeID = C1.edgeID AND C1.sourceOrSink = ‘source’ INNER JOIN Node AS Source ON C1.nodeID = Source.nodeID INNER JOIN Connection AS C2 ON E.edgeID = C2.edgeID AND C2.sourceOrSink = ‘sink’ INNER JOIN Node AS Sink ON C2.nodeID = Sink.nodeID WHERE E.edgeID = :anEdgeID . published de- scription of air travel between two airports. The frequency indicates the days of the week for which the PublishedFlight applies. A PublishedFlight consists of a sequence of Published- FlightLegs. Directed Graph Template 49 A DG (directed graph) is a set of nodes and a set of directed edges that connect nodes. You need not show DG in a use of the template. A Node is an entity type whose records. the node and edge template, intervening MaterialLots connect a network of SupplyChainStages. A SupplyChainStage may have any number of MaterialLots as input and any number as output. A MaterialLot

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