Department of Geoinformation Science Technische Universität Berlin WS 2006/07 Geoinformation Technology: lecture 3 Mapping of OO Models onto Tables Prof.

Slides:



Advertisements
Similar presentations
Three-Step Database Design
Advertisements

Relational data integrity
Department of Geoinformation Science Technische Universität Berlin WS 2006/07 Geoinformation Technology: lecture 9b Triangulated Networks Prof. Dr. Thomas.
Relational Database Design Via ER Modelling
IS698: Database Management Min Song IS NJIT. The Relational Data Model.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Department of Geoinformation Science Technische Universität Berlin WS 2006/07 Geoinformation Technology: lecture 9a Triangulated Networks Prof. Dr. Thomas.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
Geographic Information Systems
Lecture 2: Entity/Relationship modelling
Chapter 11 Data Management Layer Design
Chapter 4: Object-Oriented Data Modeling
Unified Modeling Language
Exam 2 Review Dr. Bernard Chen Ph.D. University of Central Arkansas.
Chapter 91 ER & EER to Relational Mapping. Chapter 92 ER to Relational Mapping Step 1: For each regular entity type E in the ER schema, create a relation.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Relational Database Design by ER- and EER-to-Relational Mapping.
ER- and EER-to-Relational Mapping
1 Relational model concepts Key constraints Referential integrity constraint Steen Jensen, autumn 2013.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
1 Introduction to modeling Relational modelling Slides for this part are based on Chapters 11 from Halpin, T. & Morgan, T. 2008, Information Modeling and.
Data Access Patterns Some of the problems with data access from OO programs: 1.Data source and OO program use different data modelling concepts 2.Decoupling.
April 10, 2002Applied Discrete Mathematics Week 10: Relations 1 Counting Relations Example: How many different reflexive relations can be defined on a.
1 The Relational Database Model. 2 Learning Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical.
Object Oriented Analysis and Design 1 Chapter 7 Database Design  UML Specification for Data Modeling  The Relational Data Model and Object Model  Persistence.
9/7/2012ISC329 Isabelle Bichindaritz1 The Relational Database Model.
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
1.1 CAS CS 460/660 Relational Model. 1.2 Review E/R Model: Entities, relationships, attributes Cardinalities: 1:1, 1:n, m:1, m:n Keys: superkeys, candidate.
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
Fall 2010 CS4310 Requirements Engineering A Brief Review of UML & OO Dr. Guoqiang Hu Department of Computer Science UTEP 1.
Object-Relational Modeling. What Is a Relational Data Model? Based on the concept of relations (tables of data) Relationships established by matching.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
ITEC 3220A Using and Designing Database Systems Instructor: Prof Z. Yang Course Website: 3220a.htm
Object-Oriented Modeling: Static Models. Object-Oriented Modeling Model the system as interacting objects Model the system as interacting objects Match.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
DatabaseIM ISU1 Chapter 7 ER- and EER-to-Relational Mapping Fundamentals of Database Systems.
ER/EER to Relational Mapping Chapter 9. STEP 1 ENTITY TYPE E (non weak) -> NEW RELATION T RELATION T: – includes all simple attributes (non composite,
1 ER Modeling BUAD/American University Mapping ER modeling to Relationships.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall 1 Chapter 5 (Part a): Logical Database Design and the Relational Model Modern Database Management.
Jennifer Widom Relational Databases The Relational Model.
Department of Geoinformation Science Technische Universität Berlin WS 2006/07 Geoinformation Technology: lecture 2 (b) Object Modeling Prof. Dr. Thomas.
Lecture 4: Logical Database Design and the Relational Model 1.
Week 2 Lecture The Relational Database Model Samuel ConnSamuel Conn, Faculty Suggestions for using the Lecture Slides.
Enhanced Entity-Relationship and UML Modeling. 2.
OODBMS and ORDBMS. Background Object-oriented software, based on the principles of user-defined datatypes, along with inheritance and polymorphism, is.
High-level Database Models Prof. Yin-Fu Huang CSIE, NYUST Chapter 4.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
Lecture # 14 Chapter # 5 The Relational Data Model and Relational Database Constraints Database Systems.
Chapter 71 The Relational Data Model, Relational Constraints & The Relational Algebra.
COP Introduction to Database Structures
Logical Database Design and the Rational Model
Entity-Relationship Model
CPSC-310 Database Systems
CIS 207 The Relational Database Model
Geographic Information Systems
Translation of ER-diagram into Relational Schema
Geo-Databases: lecture 7 Database design
Relational Databases The Relational Model.
Relational Databases The Relational Model.
Chapter 8: Mapping a Conceptual Design into a Logical Design
Relational Database Design by ER- and EER-to-Relational Mapping
Geo-Databases: lecture 2 The Relational Data Model
ITEC 3220A Using and Designing Database Systems
Geo-Databases: lecture 5 Data Manipulation in SQL
Geo-Databases: lecture 6 Data Integrity
Geo-Databases: lecture 3 Simple Queries in SQL
Geo-Databases: lecture 4 Complex Queries in SQL
Introduction to modeling
Presentation transcript:

Department of Geoinformation Science Technische Universität Berlin WS 2006/07 Geoinformation Technology: lecture 3 Mapping of OO Models onto Tables Prof. Dr. Thomas H. Kolbe Institute for Geodesy and Geoinformation Science Technische Universität Berlin Credits: This material is mostly an english translation of the course module no. 2 (‘Geoobjekte und ihre Modellierung‘) of the open e-content platform

2 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Mapping onto Tables

3 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Mapping onto Tables: Overview  Motivation of the relational data model  From objects to tables  Mapping of objects  Keys  Mapping of relationships  Referential integrity  Special cases: aggregation and generalization,  Queries to databases  Further simplification  Structures of ESRI ArcMap

4 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Relational Data Model: Motivation  until now... Mapping of reality onto structures and processes of an information system Description of the logical structure of the data, its properties, its behavior and its interrelationships  now... How are the data mapepd onto the structures of a concrete database system? Relational data model

5 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Mapping: From Objects to Tables state district municipality n - name: string - inhabitants: number - area: number + getname( ): string + getinhabitants( ):number + getarea( ): number - name: string - inhabitants: number - area: number + getname( ): string + getinhabitants( ):number + getarea( ): number - name: string - inhabitants: number - area: number + getname( ): string + getinhabitants( ):number + getarea( ): number n Classes and associations are represented by tables, i.e. relations

6 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Mapping: Terms and Concepts A relational database consists of one or more tables (relations)  The columns of a table are called attributes and are typed wrt. a value domain  The rows of a table are called tuples  Each relation is identified by a relation name  The set of attributes together with the relation name determine the structure of a table, the relational schema nameA1A1... ANAN Relational schemaattribute tuple attribute value

7 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Mapping: Rules for Objects Every class corresponds (at least) to one table  The name of the table corresponds to the name of the class  Each object attribute corresponds to a table attribute (only for scalar valued attributes)  Typically an „identifier" is introduced as an additional table attribute representing the identity of the object  The identifier forms the primary key of the table  Methods are not taken into account  Representation of the relational schema: NAME (identifier, attribute 1,..., attribute n) class attribute 1 attribute 2... attribute n

8 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Example for Object Mapping Rules Relational schema of the class ‘municipality‘: municipality(Id: number, name: string, inhabitants: number, area: number) municipality - name: string - inhabitants: number - area: number + getname( ): string + getinhabitants( ):number + getarea( ): number municipality Idnameinhabitantsarea Alfter Bornheim

9 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Mapping: Keys Minimal set of attributes, whose values identify a tuple unambiguously within a relation Please note:  an identifier attribute does not have to be introduced in any case; also existing attributes can be used  advantage of an identifier attribute: a simple type (like an integer number) can be chosen  In the following, identifiers are generally used nameA1A1... ANAN tuple Attributes, which are used as the primary key, are shown underlined

10 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Mapping: Example for Keys At Technische Universität Berlin, a student is identified by its matriculation number In Berlin, a student is identifiable only by the combination of its matriculation number and the respective university name student matriculation number student matriculation number Univ TUB...

11 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Mapping: Associations – The General Case General case: m:n association  Every relationship is represented by its own table; the name of the relationship turns into the name of the table  Associations may relate more than two classes (see lower UML model)  Involved classes are represented by their keys (identifier); the keys are the attributes of the relationship  The set of all attributes forms the key of the table  Representation of the relational schema: NAME(key class 1,..., key class n) class 1 class 2 class 1 class 2 class 3

12 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Example for the General Case river(riverId: number, name: string, length: number) country(countryId: number, name: string, inhabitants: number, area: number) flows_through(riverId: number, countryId: number) country - name: string - inhabitants: number - area: number + getname( ): string + getinhabitants( ):number + getarea( ): number river - name: string - length: number + getname( ): string + getlength( ):number m n flows through

13 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Mapping: Referential Integrity  Integrity assumption: existence of the associated tuples ("referential integrity"): For attributes of a relationship table there exist identifiers in the relations of the involved classes  Error case: A "pointer" to an object that leads into the void ("Dangling Pointer")

14 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Example for a Dangling Pointer flows_through riverIdcountryId 1 … (=Rheinland-Pfalz) 10 (=NRW) 2 (=Bayern) riverriverIdname 1 2 … … Rhein Donau … Elbe Weser length … ?

15 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Mapping: Special Case 1:n Relationship Refinement / simplification of the general mapping schema for n:m associations  Aggregation and composition usually are 1:n relationships an object of class 1 (aggregate class) is in relation with n objects of class 2 (component class)  Relational schema: NAME(aggregateClassId, componentClassId)  Question: Why is the key of the component class key of the relationship table?  Integration / elimination of relations The relationship is added as a further attribute to the component class (see example on next slide) Please note: This is an integration of relations having the same key! Advantage: Saving of an additional table

16 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Example for the Integration of Relations instead of use an equivalent representation district( districtId, name, inhabitants, area) municipality( municipalityId, name, inhabitants, area) AGGDistrictMunicipality( municipalityId, districtId) district( districtId, name, inhabitants, area) municipality( municipalityId, name, inhabitants, area, districtId)

17 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Mapping: Special Case 1:1 Relationship Refinement / simplification of the general mapping schema for n:m associations  An object of class 1 is in relation with exactly one object of class 2  Relational schema: NAME(class_1_Id, class_2_Id)  Question: What about choosing the key in this case?  Integration / elimination of relations in principle analogously to the 1:n relationship however, rule for the 1:n relationship is only partially applicable, because different integration scenarios possible - depending on the election of the key

18 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Example for the Mapping of a 1:1 Relationship Professor -PersNo. -Name -First Name Room -RoomNo. -Size -Location Office 11 Professor( ProfId, PersNo, Name, FirstName) Room( RoomId, RoomNo, Size, Location) Office(ProfId, RoomId) Professor( ProfId, PersNo, Name, FirstName, RoomId) Room( RoomId, RoomNo, Size, Location)

19 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Mapping of the Generalization Association  Generalization is a 1:1 relationship (between tables!)  There is no explicit relationship that is representable as a relation (table) – there exists only a hierarchy of classes  Two options for modelling generalization associations Option 1: Extend the relations (tables) representing the superclass and all subclasses by an additional attribute objectId, which realizes the connection between superclass and subclass -or adopt the primary key of the top most superclass (transitively) in any subclass Option 2: Extend all tables representing the subclasses by the attributes of the superclass

20 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Generalization Example – Option 1 geomFigure(objectId, centerpoint, visible) triangle(objectId, a,b,c) geomFigure -centerpoint: point -visible: boolean +display() +delete() +move() circle -radius: number +display() +delete() rectangle -a: number -b: number +display() +delete() triangle -a: number -b: number -c: number +display() +delete() In order to get the full information about a triangle, the relations geomFigure and triangle must be joined.

21 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Generalization Example – Option 2 triangle(objectId, centerpoint, visible, a,b,c) geomFigure -centerpoint: point -visible: boolean +display() +delete() +move() circle -radius: number +display() +delete() rectangle -a: number -b: number +display() +delete() triangle -a: number -b: number -c: number +display() +delete() There are only specialized relations. The inheritance is no longer visible. No instances of geomFigure possible

22 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Example Query for Joining Information DISTRICT( districtId, name, inhabitants, area) MUNICIPALITY( municipalityId, name, inhabitants, area, districtId) Query the names of the municipalities of the district “Rhein-Sieg“ with more than inhabitants SELECT municipality.name FROM MUNICIPALITY, DISTRICT WHERE municipality.inhabitants > AND MUNICIPALITY.districtId = DISTRICT.districtId AND DISTRICT.name = ‘Rhein-Sieg‘

23 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Simplified Mappings: Example for Maps In some cases, further considerations lead to even simpler table structures

24 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Simplified Mappings: Table Structure of a Map PROPERTY(propertyId, owner) POLYGON(polygonId, parcelId, propertyId) EDGE(edgeId, polygon1, polygon2, node1, node2) NODE(nodeId,X,Y) Exercise 1: In which sense does this relational schema conflicts with the rules introduced in the lecture? Exercise 2: Discuss to what extent this relational schema reflects the UML-diagram correctly. propertyparcelpolygon point node edge -X: number -Y: number -owner: person * * 3...* restricts geometry

25 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Simplified Mappings: Example Query propertyparcelpolygon point node edge -X: number -Y: number -owner: person * * 3...* restricts geometry Query: Which are the neighbour polygons of the polygon with the ID X? SELECT polygon1 FROM edge WHERE polygon2 = X UNION SELECT polygon2 FROM edge WHERE polygon1 = X

26 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 Tables in ArcMap

27 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 ArcMap: Structures  A Layer in ArcMap is the representation of a set of objects of the same geometry type (point, polygon or polyline)  The theme of these geo-objects is represented by an associated table  Each row of the associated table corresponds to one geo-object  Aggregation is implicit (by the identifier) Example: There is not an object „Spree" but only individual polylines, that form the river Spree  Queries on the table in SQL Arc Map document table layer data frames

28 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 ArcMap: Federal States

29 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 ArcMap: States, Government-districts and Districts

30 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 ArcMap: Attribute Table of the Districts

31 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 ArcMap: Identif. of a District with the Mouse

32 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 ArcMap: States and Rivers

33 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 ArcMap: Attribute Table of the Rivers

34 T. H. Kolbe – Geoinformation Technology: lecture 3 Department of Geoinformation Science WS 2006/07 References Kemper, Alfons, André Eickler: Datenbanksysteme. 3. Auflage - Oldenbourg, München, Wien, 1999 Rumbaugh, James et al.: Object-Oriented Modeling and Design. Prentice Hall, 1991