Data Models Mapping to UML A Data Model

  • Slides: 24
Download presentation
Data Models & Mapping to UML A Data Model is an abstract model that

Data Models & Mapping to UML A Data Model is an abstract model that describes how data is represented and used. 1

Types of data models • Object-based models – Object-oriented model – Entity-relationship model –

Types of data models • Object-based models – Object-oriented model – Entity-relationship model – Object-relational • Text-based models – XML • Record-based models – Hierarchical model – Network model – Relational model Data Model Object-based Object-oriented Entity-relationship Record-based Object-relational Hierarchical Network Text-based Relational XML 2

Outline Data Model Object-based Entity-relationship Record-based Object-relational Hierarchical Network Text-based Relational XML Object-oriented 3

Outline Data Model Object-based Entity-relationship Record-based Object-relational Hierarchical Network Text-based Relational XML Object-oriented 3

The Object-Oriented Model - Simplified Relationship Generalization * Association name * name : String

The Object-Oriented Model - Simplified Relationship Generalization * Association name * name : String 0. . 1 1 specific Class name general is. Abstract 1 1 1 2 Owning. Instance Object member. End Property * name ownedis. Composite Attribute multiplicity link 1 Object 1 instance. Of 1 value * defining. Property 1 Reference Property Operation owned. Operation name parameters classes Slot 0. . 1 Value Class 1 * owned. Attribute objects Instance Model 4

The Object-Oriented Model - Levels Association Class M 2 M 1 Person name 1

The Object-Oriented Model - Levels Association Class M 2 M 1 Person name 1 * Car M 1 M 0 : Car : Person name=“Bob” : Car metamodel architecture example 5

Outline Data Model Object-based Object-oriented Record-based Object-relational Hierarchical Network Text-based Relational XML Entity-relationship 6

Outline Data Model Object-based Object-oriented Record-based Object-relational Hierarchical Network Text-based Relational XML Entity-relationship 6

Entity-Relationship model ER-metamodel (simplified): Role Relationsship 2. . * min. Cardinality max. Cardinality name

Entity-Relationship model ER-metamodel (simplified): Role Relationsship 2. . * min. Cardinality max. Cardinality name * 1 Entity name 1 Attribute * min. Cardinality max. Cardinality is. Derived ER-model example: Professor name examiner 1 examination examinee * Student name 7

Entity-relationship model often an entity-relationship model is mapped to a Relational model (SQL) 8

Entity-relationship model often an entity-relationship model is mapped to a Relational model (SQL) 8

Outline Data Model Object-based Object-oriented UML Entity-relationship Record-based Object-relational Hierarchical Text-based Network XML Relational

Outline Data Model Object-based Object-oriented UML Entity-relationship Record-based Object-relational Hierarchical Text-based Network XML Relational Mapping 9

Relational model Relational-metamodel (strongly simplified): name Rational-model instance example: Instance Model Tuple 1 1.

Relational model Relational-metamodel (strongly simplified): name Rational-model instance example: Instance Model Tuple 1 1. . * 1 Domain Rational-model (relational schema) example: type 1 * * Attribute name 1 * Attribute. Value value Building. Id name area b 1 Luftslott 300 b 7 Galleriet 300 10

 • Object technology, like Java, is in wide use and relational databases are

• Object technology, like Java, is in wide use and relational databases are the preferred approach for storage of persistent information. • The relational paradigm is based on mathematical principles: Set theory. The object paradigm has a quite different basis: Inheritance, encapsulation, …. 11

 • In the object paradigm objects are traversed by following links between objects

• In the object paradigm objects are traversed by following links between objects (a link can be an instance of an ordinary association). In the relational paradigm rows in different tables are connected with foreign keys (joining rows in different tables). • (Mapping from UML class diagrams to tables and then back to class diagrams will lead to loss of information. ) 12

Class diagram B is a derived attribute. C a : Integer c : Double

Class diagram B is a derived attribute. C a : Integer c : Double /b : Integer NB! Not all classes are persistent. Table: C A: Integer C: Double 13

Class diagram Object diagram Total participation X x_pkey x_a 1 Y 1 1 X

Class diagram Object diagram Total participation X x_pkey x_a 1 Y 1 1 X 1 y_pkey y_a 1 Y 2 X 3 Y 1 Tables: Three different solutions Table: XY x_pkey x_a 1 y_pkey y_a 1 Table: X and Y Table: Y and X x_pkey x_a 1 y_pkey y_a 1 x_pkey x_a 1 14

Object diagram Class diagram X 1 X x_pkey x_a 1 Y 1 * y_pkey

Object diagram Class diagram X 1 X x_pkey x_a 1 Y 1 * y_pkey y_a 1 Y 2 X 2 Y 3 X 3 Y 4 Y 1 X 4 Tables: One possible solution Table: X Table: Y x_pkey x_a 1 y_pkey y_a 1 x_pkey 15

Object diagram Class diagram X 1 X x_pkey x_a 1 Y * * X

Object diagram Class diagram X 1 X x_pkey x_a 1 Y * * X 2 Y 3 y_pkey y_a 1 Y 4 Y 2 X 4 Y 1 X 3 Tables: One possible solution Table: XY x_pkey x_a 1 x_pkey y_pkey Table: Y y_pkey y_a 1 16

17

17

Learning. Module unit. Id name description type. Id Type name Type type. Id name

Learning. Module unit. Id name description type. Id Type name Type type. Id name 1 Learning. Module * name description * Search * word Search search. Id word Learning. Module. Search Learning. Module. Id search. Id CREATE TABLE Learning. Module (id name description type. Id … INTEGER, VARCHAR(150), VARCHAR(500), INTEGER) 18

Outline Data Model Object-based Object-oriented UML Entity-relationship Record-based Object-relational Hierarchical Network Text-based Relational XML

Outline Data Model Object-based Object-oriented UML Entity-relationship Record-based Object-relational Hierarchical Network Text-based Relational XML Mapping 19

[ref. Wikipedia]: Well-formed documents: XML syntax • As long as only well-formedness is required,

[ref. Wikipedia]: Well-formed documents: XML syntax • As long as only well-formedness is required, XML is a generic framework for storing text or any data whose structure can be represented as a tree. • The document must have exactly one root element. The following is a well-formed XML document: <journal>This is a journal. . </journal> • The root element can be preceded by an optional XML declaration. E. g. , <? xml version="1. 0" encoding="UTF-8"? > 20

[ref. Wikipedia]: Well-formed documents: XML syntax Continues… • The text enclosed by the root

[ref. Wikipedia]: Well-formed documents: XML syntax Continues… • The text enclosed by the root tags may contain an arbitrary number of XML elements. The basic syntax for one element is: <name attribute="value">content</name> “content” may again contain XML elements. Example: <recipe name="bread" prep_time="5 mins" cook_time="3 hours"> <title>Basic bread</title> <ingredient amount="3" unit="cups">Flour</ingredient> … <instructions> <step>Mix all ingredients together. </step> … </instructions </recipe> XML requires that elements be properly nested — elements may never overlap. 21

Using XML for Storing Data Simple PIM Journal name: String SSN: String Journal. Record

Using XML for Storing Data Simple PIM Journal name: String SSN: String Journal. Record description: String : Journal name=“Ola” SSN=“ 1” : Journal name=“Kari” SSN=“ 2” : Journal. Record description=“May be a little bit fat? ” : Journal. Record description=“Lack of iron. ” : Journal. Record Data description=“A slight attack of shopomania? ” <medicalsystem> <journal name=“Ola Norman" ssn=“ 1"> <journalrecord>May be a little bit fat? </journalrecord> </journal> <journal name=“Kari Norman" ssn=“ 2"> <journalrecord>Lack of iron. </journalrecord> <journalrecord>A slight attack of shopomania? </journalrecord> </journal> </medicalsystem> 22

XML metamodel Structure Description of XML Schema Instance Model Element {ordered} name * ….

XML metamodel Structure Description of XML Schema Instance Model Element {ordered} name * …. . 0. . 1 container Text. Node Attribute value type Root. Node document. Name XML Shema (= XML model) example (simplified): <xsd: schema …. > <xsd: element name = “Building” type = “Building. Type”/> <xsd: complex. Type name=" Building. Type"> <xsd: attribute name=“name" type="xsd: string"/> <xsd: attribute name=“area" type="xsd: integer"/> </xsd: complex. Type> …. . XML document (= instance of some XML schema)): <? xml version=1. 0” …> … <Building name=“Luftslottet" area = 300/> …. . 23

Hi. A Project: Modeling Accessibility Constraints XHTML-document (XML) eksample: <!DOCTYPE html PUBLIC "-//W 3

Hi. A Project: Modeling Accessibility Constraints XHTML-document (XML) eksample: <!DOCTYPE html PUBLIC "-//W 3 C//DTD XHTML 1. 0 Transitional//EN" "http: //www. w 3. org/TR/xhtml 1/DTD/xhtml 1 -transitional. dtd"> <html xmlns="http: //www. w 3. org/1999/xhtml" xml: lang="en“ lang="en" > <body> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="generator" content="gedit" /> <title>Test</title> </head> <body bgcolor="yellow"> <img src="http: //www. eiao. net/kickoff. jpg" alt="" /> <font color="black">Participants at the EIAO Kickoff meeting in Grimstad, 2004 -10 -14. </font> </body> </html> 24