Download presentation
Presentation is loading. Please wait.
1
Some Data Models & Mapping to/from UML
A Data Model is an abstract model that describes how data is represented and used.
2
Types of data models Object-based models Record-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 An object-relational database (ORD), is a database management system (DBMS) similar to a relational database, but with an object-oriented database model: objects, classes and inheritance are directly supported in database schemas and in the query language. …at the other extreme are OODBMSes in which the database is essentially a persistent object store for software written in anobject-oriented programming language, with a programming API for storing and retrieving objects, and little or no specific support for querying. A hierarchical database model is a data model in which the data is organized into a tree-like structure. The structure allows representing information using parent/child relationships: each parent can have many children, but each child has only one parent (also known as a 1-to-many relationship). All attributes of a specific record are listed under an entity type. In a database an entity type is the equivalent of a table. The network model is a database model conceived as a flexible way of representing objects and their relationships. Its distinguishing feature is that the schema, viewed as a graph in which object types are nodes and relationship types are arcs, is not restricted to being a hierarchy or lattice. While the hierarchical database model structures data as a tree of records, with each record having one parent record and many children, the network model allows each record to have multiple parent and child records, forming a generalized graph structure. Until the early 1980s the performance benefits of the low-level navigational interfaces offered by hierarchical and network databases were persuasive for many large-scale applications, but as hardware became faster, the extra productivity and flexibility of the relational model led to the gradual obsolescence of the network model in corporate enterprise usage. Object-based Record-based Text-based Object-oriented Entity-relationship Object-relational Hierarchical Network Relational XML
3
Outline Object-oriented Data Model Object-based Record-based
Text-based Entity-relationship Object-relational Hierarchical Network Relational XML Object-oriented
4
From the UML 2.4 Specification
5
The Object-Oriented Model - Simplified
Relationship Generalization Association Owning- Instance Object * name * id : String * Slot 1 0..1 link- Object 1 0..1 member- End 1 specific 2 1 instanceOf Class Property value 1 Value name isAbstract * name isComposite multiplicity Class 1 * owned- Attribute general definingProperty 1 1 Reference Property 1 How should references found in Java be modelled? Operation owned- Attribute name parameters owned- Operation Classes Class Models (class diagrams) Objects Instance Model (object diagrams)
6
The Object-Oriented Model - Levels
Class Association M2 M1 Person Car 1 * name M1 M0 :Car id1:Person name=“Bob” :Car metamodel architecture simplified example
7
Outline Entity-relationship Data Model Object-based Record-based
Text-based Object-oriented Object-relational Hierarchical Network Relational XML Entity-relationship
8
Entity-Relationship model
ER-metamodel (simplified): Role Relationsship 2..* minCardinality maxCardinality name * 1 Entity Attribute 1 name * minCardinality maxCardinality isDerived ER-model example: examiner examination examinee Professor Student 1 * name name
9
Entity-relationship model often an entity-relationship model is mapped to a Relational model Relational model (SQL) Student Student name StudentId name
10
Outline Relational Data Model Object-based Record-based Text-based
Object-oriented UML Entity-relationship Object-relational Hierarchical Network XML Relational
11
Relational model Instance Model
type Relation Tuple Relational-metamodel (strongly simplified): name 1 1..* 1 * * Domain Attribute AttributeValue 1 * name name 1 value Rational-model example: (implemented as tables) Building BuildingId name area Rational-model instance Example: (Implemented as tables) Building BuildingId name area b1 Luftslott 300 b7 Galleriet 300
12
Outline Mapping Relational Data Model Object-based Record-based
Text-based Object-oriented UML Entity-relationship Object-relational Hierarchical Network XML Relational Mapping
13
Why This Mapping? Object technology, like Java, is in wide use and relational databases are often the preferred approach for storage of persistent information. The relational paradigm is based on mathematical principles: Set theory. The object paradigm is somewhat different (even if a class can be seen as the description of sets of objects): Inheritance, encapsulation,….
14
Why This Mapping Continues...
In the object paradigm objects are traversed by following links between objects. 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 may lead to loss of information.)
15
UML to Relational Mapping:
Class to Table Class diagram b is a derived attribute. C a : Integer c : Double /b : Integer NB! Not all classes are persistent. Table Table: C A: Integer C: Double
16
UML to Relational Mapping: one-to-one associations
X Y x_pkey x_a1 y_pkey y_a1 1 Total participation Class diagram Object diagram X1 Y2 X2 Y3 X3 Y1 x_pkey Tables: Three different solutions x_a1 y_pkey y_a1 Table: XY Table: X and Y Table: Y and X
17
UML to Relational Mapping: one-to-many associations
Object diagram X Y x_pkey x_a1 y_pkey y_a1 1 * Class diagram X1 Y2 X2 Y1 Y3 X3 Y4 X4 Tables: One possible solution y_pkey y_a1 x_pkey x_a1 Table: Y Table: X
18
UML to Relational Mapping: many-to-many associations
Object diagram X1 Y2 Y3 X2 Y1 X4 Y4 X3 X Y x_pkey x_a1 y_pkey y_a1 * Class diagram Tables: One possible solution y_pkey y_a1 x_a1 Table: Y x_pkey Table: X Table: XY
19
Mapping to UML
20
LearningModuleSearch
Mapping to Tables unitId name description LearningModule typeId typeId name Type Type name 1 1 LearningModule * * Search searchId word Search name word description * * * * LearningModuleSearch SQL LearningModuleId searchId CREATE TABLE LearningModule (id INTEGER, name VARCHAR(150), description VARCHAR(500), typeId INTEGER) …
21
Outline XML Data Model Object-based Record-based Text-based
Object-oriented UML Entity-relationship Object-relational Hierarchical Network Relational XML
22
[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"?>
23
[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.
24
Outline Mapping XML Data Model Object-based Record-based Text-based
Object-oriented UML Entity-relationship Object-relational Hierarchical Network Relational XML Mapping
25
Using XML for Storing Data
Simple PIM :Journal :JournalRecord name=“Ola” SSN=“1” description=“May be a little bit fat?” * Journal JournalRecord 1 :Journal :JournalRecord name:String SSN:String description:String name=“Kari” SSN=“2” description=“Lack of iron.” :JournalRecord 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>
26
XML metamodel Structure
An XML Schema functioning as model Instance Model Element {ordered} name * ….. 0..1 Node Attribute container value type TextNode RootNode documentName XML Shema (= XML model) example (simplified): <xsd:schema …. > <xsd:element name = “Building” type = “BuildingType”/> <xsd:complexType name=" BuildingType"> <xsd:attribute name=“name" type="xsd:string"/> <xsd:attribute name=“area" type="xsd:integer"/> </xsd:complexType> ….. Each XML document consists of nodes (in the model represented by Node class) and each node can contain either attributes (represented by Attribute class) or nested nodes. Both attribute and node have name (this and the Contains association are the reasons why there is a root abstract class named Element), in addition attribute has a value. Contains association expressing the fact that a node can contain both attributes and nodes is ordered on the elements end – this is because order of nodes is significant in XML. Text nodes are represented by a separate subclass of Node named TextNode. As each XML document consists of exactly one root node, it is convenient to define a separate subclass of Node class called RootNode for representing a root node in a document. This class also represents the document itself – it contains an additional attribute documentName. XML document (= instance of some XML schema)): <?xml version=1.0” …> … <Building name=“Luftslottet" area = 300/> …..
27
HIA Project: Modeling Accessibility Constraints
XHTML-document (XML) eksample: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " <html xmlns=" 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=" alt="" /> <br /> <font color="black">Participants at the EIAO Kickoff meeting in Grimstad, </font> </body> </html>
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.