1. Trang chủ
  2. » Công Nghệ Thông Tin

PATTERNS OF DATA MODELING- P14 pot

5 248 0
Tài liệu đã được kiểm tra trùng lặp

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

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 148,55 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

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 a

Trang 1

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;

Trang 2

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

Edge table edgeID dgID edgeName sourceNodeID sinkNodeID

B c

d

e

F

A

f

g

Figure 3.24 Node and edge directed graph: Populated tables

Node table

node

ID

dgID node

Name

Edge table edgeID dgID edgeName sourceNodeID sinkNodeID

Y X

r s t

Trang 3

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 1 1

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

quantity name

*

*

Trang 4

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>

0 1

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

Trang 5

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

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

TỪ KHÓA LIÊN QUAN