PATTERNS OF DATA MODELING- P17 pps

5 201 0
PATTERNS OF DATA MODELING- P17 pps

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

Thông tin tài liệu

3.7 Chapter Summary 61 Template name Synopsis UML template Use when Frequency Simple DG Treats all nodes the same. Edges are unim- portant; nodes have the same kind of data. The DG is acyclic. Occasional Structured DG Differentiates leaf nodes from branch nodes. Edges are unim- portant; branch nodes and leaf nodes have differ- ent data. The DG is acyclic. Occasional Node and edge DG Treats nodes and edges as peers. Nodes and edges can both have data; there can be multiple edges between a pair of nodes. Common Connection DG Promotes the con- nection between a node and an edge to an entity type. There is data for the connection itself as well as for nodes and edges. Occasional Simple DG changing over time Stores multiple variants of a DG. Extract a particu- lar DG by speci- fying a time. A DG changes over time; edges are unimportant. The DG is acy- clic. Seldom Node and edge DG changing over time Stores multiple variants of a DG. Extract a particu- lar DG by speci- fying a time. A DG changes over time; edges are important. Occasional Table 3.1 Summary of the Directed Graph Templates Note: This table can help you choose among the directed graph templates. 62 Chapter 3 / Directed Graph Template Bibliographic Notes Page 89 of [Hay-1996] has an example of projects that involve the node and edge directed graph. References [Hay-1996] David C. Hay. Data Model Patterns: Conventions of Thought. New York, New York: Dorsett House, 1996. 63 4 Undirected Graph Template The undirected graph is also a term from graph theory. An undirected graph is a set of nodes and a set of edges. Each edge connects two nodes (which may be the same). The nodes of an undirected graph can have any number of edges. Undirected graphs arise for applications with important topology or connectivity. For example, the network of members on the LinkedIn Web site is an undirected graph. Figure 4.1 shows two examples of undirected graphs. There are three templates for undirected graphs. • Node and edge undirected graph. Regards nodes and edges as peers. Use as the de- fault template when there are no edges that connect to the same node. • Connection undirected graph. Promotes the connection between a node and an edge to an entity type. Use when there is data for the connection itself. • Undirected graph changing over time. Stores variants of a node and edge undirected graph. A particular undirected graph can be extracted by specifying a time. Use when the history of an undirected graph must be recorded. Figure 4.1 Sample undirected graphs. An undirected graph is a set of nodes and a set of edges that connect the nodes. B c d e C D E F A f g hi YX r s t 64 Chapter 4 / Undirected Graph Template There is no undirected graph counterpart to the simple and structured templates of directed graphs. The simple counterpart violates the symmetry antipattern (see Chapter 8). The struc- tured counterpart shares a similar flaw as it is not clear which end of an edge should be the parent and which should be the child. In principle, it would be possible to add time intervals to the connection template, but we have never seen a need for this in practice. 4.1 Node and Edge Undirected Graph Template 4.1.1 UML Template Figure 4.2 shows the UML template for node and edge undirected graphs. A UDG (undirected graph) is a set of nodes and a set of edges that connect nodes. (Note: in an undirected graph all nodes do not have to be connected.) You need not show UDG in a 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. Figure 4.2 lacks the constraint that related nodes and edges must all belong to the same undirected graph. The template also cannot handle edges that connect twice to the same node (the “2” in Figure 4.2 refers to two different nodes); use the connection undirected graph if an edge connects twice to the same node. 4.1.2 IDEF1X Template Figure 4.3 restates Figure 4.2 with the IDEF1X notation. The following are foreign keys: udgID references UDG, edgeID references Edge, and nodeID references Node. The “2” mul- tiplicity in Figure 4.2 becomes “many” multiplicity in a database design. 4.1.3 SQL Queries Figure 4.4 and Figure 4.5 show SQL queries for common traversals of the template. The co- lon prefix denotes variable values that must be provided for each query. <UDG> <Edge><Node> 0 1 0 1 ** * 2 Figure 4.2 Node and edge undirected graph: UML template. Use as the default template when no edges connect to the same node. 4.1 Node and Edge Undirected Graph Template 65 4.1.4 Sample Populated Tables Figure 4.6 shows node and edge undirected graph tables populated with data. The values of the IDs are arbitrary, but internally consistent. 4.1.5 Examples Undirected graphs occur only occasionally and when they occur, the node and edge template is often appropriate. The LinkedIn Web site is popular for professional networking. Members can connect to other members and find those who are closely connected via intermediate colleagues. Such contacts can be useful for seeking employers, seeking employees, and sharing information. An undirected graph is the proper representation because there is a lack of direction in con- nections between members. It does not matter who initiated the contact; all that matters is that pairs of members are connected. Furthermore, it makes no sense for a member to con- nect to himself or herself. Thus the limitation of the node and edge template is not a problem. Figure 4.3 Node and edge undirected graph: IDEF1X template. nodeID udgID (FK) nodeName (AK1.1) Node edgeID udgID (FK) edgeName (AK1.1) Edge Node_Edge nodeID (FK) edgeID (FK) udgID UDG Figure 4.4 Node and edge undirected graph: SQL query. Find the edges for a node. 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 ORDER BY E.edgeName; Figure 4.5 Node and edge undirected graph: SQL query. Find the nodes for an edge. 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 ORDER BY N.nodeName; . Template Bibliographic Notes Page 89 of [Hay-1996] has an example of projects that involve the node and edge directed graph. References [Hay-1996] David C. Hay. Data Model Patterns: Conventions of Thought. New York,. An undirected graph is a set of nodes and a set of edges. Each edge connects two nodes (which may be the same). The nodes of an undirected graph can have any number of edges. Undirected graphs. same kind of data. The DG is acyclic. Occasional Structured DG Differentiates leaf nodes from branch nodes. Edges are unim- portant; branch nodes and leaf nodes have differ- ent data. The

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