February,2006 Advanced DB System Object Relational Model Prof: Dr Rahgozar Euhanna Ghadimi, Mostafa Keikha Discussion, Implementation.

Slides:



Advertisements
Similar presentations
Chapter 10: Designing Databases
Advertisements

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
CSC 570 Notes for Chapter 10 Advanced Topics in Relational Databases.
GI Systems and Science January 30, Points to Cover  Recap of what we covered so far  A concept of database Database Management System (DBMS) 
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 28 Database Systems I The Relational Data Model.
Chapter 3 An Introduction to Relational Databases.
Database Systems More SQL Database Design -- More SQL1.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
Attribute databases. GIS Definition Diagram Output Query Results.
RIZWAN REHMAN, CCS, DU. Advantages of ORDBMSs  The main advantages of extending the relational data model come from reuse and sharing.  Reuse comes.
Advanced Database CS-426 Week 13 – Object Relational Databases.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
An Introduction to Hibernate Matt Secoske
Database Design and Introduction to SQL
IST Databases and DBMSs Todd S. Bacastow January 2005.
Object and object-relational databases 1. Object databases vs. Object-relational databases Object databases Stores complex objects – Data + functions.
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
The Relational Model These slides are based on the slides of your text book.
44220: Database Design & Implementation Logical Data Modelling Ian Perry Room: C48 Tel Ext.: 7287
Agenda What is Hibernate Spring Integration Questions Overview
DBMS Lecture 9  Object Database Management Group –12 Rules for an OODBMS –Components of the ODMG standard  OODBMS Object Model Schema  OO Data Model.
Relational Data Model, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 1 The Relational Model Chapter 3.
Module Title? DBMS Introduction to Database Management System.
The Relational Model. Review Why use a DBMS? OS provides RAM and disk.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
NHibernate in Action Web Seminar at UMLChina By Pierre Henri Kuaté 2008/08/27
CS609 Introduction. Databases Current state? Future?
Shaowen Wang CyberInfrastructure and Geospatial Information Laboratory (CIGI) Department of Geography and National Center for Supercomputing Applications.
CHAPTER 14 USING RELATIONAL DATABASES TO PROVIDE OBJECT PERSISTENCE (ONLINE) © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database.
Hibernate Query Language Make SQL be object oriented – Classes and properties instead of tables and columns – Polymorphism – Associations – Much less verbose.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
Object/Relational Mapping with Hibernate Practical ORM.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 2: Intro to Relational.
Modern Database Techniques Part 1: Object Oriented Databases 3. Different Kinds of OODB.
Object Oriented Analysis and Design 1 Chapter 7 Database Design  UML Specification for Data Modeling  The Relational Data Model and Object Model  Persistence.
Lecture2: Database Environment Prepared by L. Nouf Almujally & Aisha AlArfaj 1 Ref. Chapter2 College of Computer and Information Sciences - Information.
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
1 Mapping to Relational Databases Presented by Ramona Su.
Hibernate Introduction - 1 Present by Eric Yu. BeanSoft | 2 Content Understanding object/relational persistence Introduction Architecture The core interfaces.
Object-Relational Mapping with Hibernate Brian Sam-Bodden Principal Partner Integrallis Software, LLC. August 1 - 5, 2005.
An Introduction to Object/Relational Persistence and Hibernate Yi Li
1 CS457 Object-Oriented Databases Chapters as reference.
Creating and Maintaining Geographic Databases. Outline Definitions Characteristics of DBMS Types of database Relational model SQL Spatial databases.
A U.S. Department of Energy Office of Science Laboratory Operated by The University of Chicago Argonne National Laboratory Office of Science U.S. Department.
OODBMS: Introduction and Logical Database Design
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool The problem fixed by ORM Advantage Hibernate Hibernate Basic –Hibernate sessionFactory –Hibernate Session.
Database Systems Lecture 1. In this Lecture Course Information Databases and Database Systems Some History The Relational Model.
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
Object-Relational Model. Review: Data Models Hierarchical Network ER (Pure) Relational (Pure) Object-oriented (ODMG) Object-relational (since SQL:1999)
Hibernate Basics. Basics What is persistence? Persistence in Object Oriented Applications? Paradigm Mismatch.  The Problem of Granularity.  The Problem.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
Object storage and object interoperability
CPT-S Advanced Databases 11 Yinghui Wu EME 49.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
IST 210 Object Oriented Database. IST 210 Object-Oriented Concepts  Abstract Data Types  Class definition, provides extension to complex attribute types.
Chapter 1: Introduction. 1.2 Database Management System (DBMS) DBMS contains information about a particular enterprise Collection of interrelated data.
Faeez, Franz & Syamim.   Database – collection of persistent data  Database Management System (DBMS) – software system that supports creation, population,
CS 440 Database Management Systems Stored procedures & OR mapping 1.
Hibernate Java Persistence API. What is Persistence Persistence: The continued or prolonged existence of something. Most Applications Achieve Persistence.
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.
More SQL: Complex Queries, Triggers, Views, and Schema Modification
More SQL: Complex Queries,
Translation of ER-diagram into Relational Schema
Object/Relational Mapping with Hibernate
More SQL: Complex Queries, Triggers, Views, and Schema Modification
02 - The Relational Database Model
Presentation transcript:

February,2006 Advanced DB System Object Relational Model Prof: Dr Rahgozar Euhanna Ghadimi, Mostafa Keikha Discussion, Implementation

February,2006 Advanced DB System Foreword  “ Object databases will gain ground, but their share of the world ’ s data will still be very small. The big change will come from the relational databases as they extend their databases to support more object-oriented features. ” Martin Fowler, Oracle Press, 1999

February,2006 Advanced DB System outline  History of DB Models  Object-Relational Model  Base features  Concepts  Examples  Object Relation mapping (ORM)  “ Modern ” ORM Solutions  Conclusion

February,2006 Advanced DB System History of DB Models  1950 File Systems, Punched Cards  1960 Hierarchical (IMS IBM Mainframes)  1970 Network (CODASYL, IDMS)  1980 Relational (ORACLE, DB2, Sybase)  1990 Object-Oriented, Object-Relational (O2, ORACLE9i)

February,2006 Advanced DB System Relational Model  Emergence of data model  Data independence  High-level approach  Standardization  Built-in data types  Little abstraction  Separation between data and operations

February,2006 Advanced DB System Object-Oriented Model  Complex application datatypes  Object Abstraction  Encapsulation of behavior  High performance for specific application  No backwards compatibility  Closely tied to language and application

February,2006 Advanced DB System Object-Relational Model  Synthesis of two worlds  Upward compatibility  Robustness of mature systems  Legacy problems  Backward Compatibility

February,2006 Advanced DB System Main Features Relation is still the fundamental abstraction, with integration of OO features  Structured Types Non-atomic types  Methods Special operations can be defined for a type  References Pointers to tuples  SQL-99 includes many of the object-relational features to be described.

February,2006 Advanced DB System Structured Types - I  Attributes of relation schemas can be  Atomic  Relation schemas: Nested Relations

February,2006 Advanced DB System Structured Types - II 4NF1NF Nested

February,2006 Advanced DB System Structured Types  UDT – User Defined Type  A UDT can be the type of a table  A UDT can be the type of an attribute belonging to some table  A UDT can inherit from another UDT CREATE TYPE T AS ;

February,2006 Advanced DB System Nested Relations Example CREATE TYPE AddressType AS ( street CHAR(50), city CHAR(20) ); CREATE TYPE AddressTypeTable AS TABLE OF AddressType; CREATE TYPE StarType AS ( name CHAR(30), address AddressTypeTable ); CREATE TABLE MovieStar OF StarType;

February,2006 Advanced DB System Methods – SQL99  Special operations defined for a type  In SQL, implementation defined with Presistent Stored Modules (PSM) language METHOD m() RETURNS ;

February,2006 Advanced DB System Methods - Example CREATE TYPE AddressType AS ( street CHAR(50), city CHAR(20) ) METHOD houseNumber() RETURNS CHAR(10); CREATE METHOD houseNumber() RETURNS CHAR(10) FOR AddressType BEGIN … END;

February,2006 Advanced DB System References - I  Allow a tuple t refer to a tuple s rather than including s in t

February,2006 Advanced DB System References - II  If attribute A has a type that is a reference to a tuple in relation with schema R, we denote A as A(*R)  If A is a set of references, we denote A as A({*R})

February,2006 Advanced DB System References – SQL99 - I  A table which type is a UDT may have a reference column that serves as its “ ID ” In CREATE TABLE statement, add REF IS Where is either  SYSTEM_GENERATED : DBMS generates unique IDs  DERIVED : DBMS uses primary key of the relation for IDs

February,2006 Advanced DB System References – SQL99 – I - Example CREATE TYPE MovieType AS ( title CHAR(30), year INTEGER ); CREATE TABLE Movie OF MovieType ( REF IS movieID DERIVED, PRIMARY KEY (title, year) );

February,2006 Advanced DB System References – SQL99 - II Reference to a tuple of type T REF(T) Reference to tuples in relation R, where R is a table whose type is the UDT T REF(T) SCOPE R

February,2006 Advanced DB System References – SQL99 - II – Example CREATE TYPE StarType AS ( name CHAR(30), address AddressType, bestMovie REF(MovieType) SCOPE Movie ); NameAddressbestMovie Hamill streetcity Sunset Blvd LA

February,2006 Advanced DB System Object Relation mapping (ORM)  although OR DBs solve many problems, they are not so much practical.  Why?  ORM

February,2006 Advanced DB System What do RDBs do well?  Work with large amounts of data  Searching, sorting  Work with sets of data  Joining, aggregating  Sharing  Concurrency (Transactions)  Many applications  Integrity  Constraints  Transaction isolation

February,2006 Advanced DB System What do RDBs do badly?  Modeling  No polymorphism  Fine grained models are difficult  Business logic  Stored procedures (really they are sufficient?) Goal: Take advantage of those things that relational databases do well Without leaving the language of objects / classes Final goal :Do less work, Happy DBA

February,2006 Advanced DB System “ Modern ” ORM Solutions  Transparent Persistence  Persistent/transient instances  Automatic Dirty Checking  Transitive Persistence  Lazy Fetching  Outer Join Fetching  Runtime SQL Generation

February,2006 Advanced DB System Auction Object Model

February,2006 Advanced DB System Persistent Class  Default constructor  Get/set pairs  Collection property is an interface type  Identifier property public class AuctionItem { private Long _id; private Set _bids; private Bid _successfulBid private String _description; public Long getId() { return _id; } private void setId(Long id) { _id = id; } public String getDescription() { return _description; } public void setDescription(String desc) { _description=desc; } … }

February,2006 Advanced DB System XML Mapping  Readable metadata  Column / table mappings  Candidate key generation strategy  Collection metadata  Fetching strategies <set name= “ bids ” cascade= “ all ” lazy= “ true ” >

February,2006 Advanced DB System Dirty Checking  Retrieve an AuctionItem and change description Session session = sessionFactory.openSession(); Transaction tx = s.beginTransaction(); AuctionItem item = (AuctionItem) session.get(ActionItem.class, itemId); item.setDescription(newDescription); tx.commit(); session.close();

February,2006 Advanced DB System Transitive Persistence  Retrieve an AuctionItem and create a new persistent Bid Bid bid = new Bid(); bid.setAmount(bidAmount); Session session = sf.openSession(); Transaction tx = session.beginTransaction(); AuctionItem item = (AuctionItem) session.get(ActionItem.class, itemId); bid.setItem(item); item.getBids().add(bid); tx.commit(); session.close();

February,2006 Advanced DB System Detachment  Retrieve an AuctionItem and create a new persistent Bid Session session = sf.openSession(); Transaction tx = session.beginTransaction(); AuctionItem item = (AuctionItem) session.get(ActionItem.class, itemId); tx.commit(); session.close(); item.setDescription(newDescription); Session session2 = sf.openSession(); Transaction tx = session2.beginTransaction(); session2.update(item); tx.commit(); session2.close();

February,2006 Advanced DB System Optimizing Data Access  Eager (Outer Join) Fetching  Lazy Fetching  Batch Fetching

February,2006 Advanced DB System Outer Join Fetching AuctionItem item = (AuctionItem) s.get(ActionItem.class, itemId); SELECT … FROM AUCTION_ITEM ITEM LEFT OUTER JOIN BID BID1 ON BID1.ITEM_ID = ITEM.ITEM_ID LEFT OUTER JOIN BID BID2 ON BID2.BID_ID = ITEM.SUCCESSFUL_BID WHERE ITEM.ITEM_ID = ?

February,2006 Advanced DB System Lazy Fetching AuctionItem item = (AuctionItem) session.get(ActionItem.class, itemId); SELECT … FROM AUCTION_ITEM ITEM WHERE ITEM.ITEM_ID = ? Iterator iter = item.getBids().iterate(); SELECT … FROM BID BID WHERE BID.ITEM_ID = ? item.getSuccessfulBid().getAmount(); SELECT … FROM BID BID WHERE BID.BID_ID = ?

February,2006 Advanced DB System Data Access mechanism <many-to-one name= “ successfulBid ” outer-join= “ true ” column= “ SUCCESSFUL_BID_ID ” /> <set name= “ bids ” cascade= “ all ” Lazy= “ true ” >

February,2006 Advanced DB System Optimizing Data Access  Minimize row reads  Use lazy fetching N+1 Selects Problem (too many roundtrips)  Minimize database roundtrips  Use outer join fetching Cartesian Product Problem (huge result set)  (Much less important) Minimize column reads

February,2006 Advanced DB System Optimizing Data Access Solution: Runtime Fetch Strategies 1.Say what objects you need 2.Navigate the object graph

February,2006 Advanced DB System Possible options  Intermediate Query Language  “ Minimal ” OO concepts combine with of ANSI SQL  Native SQL Queries with OO methods (DQE)

February,2006 Advanced DB System Intermediate Query Language  Make SQL be object oriented  Classes and properties instead of tables and columns  Polymorphism  Associations  Much less shorter than SQL  Full support for relational operations  Inner/outer/full joins, cartesian products  Projection  Aggregation (max, avg) and grouping  Ordering  Subqueries  SQL function calls

February,2006 Advanced DB System Intermediate Query Language  IQL is a language for talking about “ sets of objects ”  It unifies relational operations with object models Simplest IQL Query: from AuctionItem i.e. get all the AuctionItems: List allAuctions =session.createQuery(“from AuctionItem”).list();

February,2006 Advanced DB System Intemediate Query Language More realistic example: select item from AuctionItem item join item.bids bid where item.description like ‘ hib% ’ and bid.amount > 100 i.e. get all the AuctionItem s with a Bid worth > 100 and description that begins with “ hib ”

February,2006 Advanced DB System Intermediate Query Language Projection: select item.description, bid.amount from AuctionItem item join item.bids bid where bid.amount > 100 order by bid.amount desc i.e. get the description and amount for all the AuctionItems with a Bid worth > 100

February,2006 Advanced DB System Intermediate Query Language Aggregation: select max(bid.amount), count(bid) from AuctionItem item left join item.bids bid group by item.type order by max(bid.amount)

February,2006 Advanced DB System Intermediate Query Language Runtime fetch strategies: AuctionItem item = session.createQuery( … ).uniqueResult(); //associations already fetched item.getBids().iterator(); item.getSuccessfulBid().getAmount(); from AuctionItem item left join fetch item.bids join fetch item.successfulBid where item.id = 12

February,2006 Advanced DB System Criteria Queries List auctionItems = session.createCriteria(AuctionItem.class).setFetchMode( “ bids ”, FetchMode.EAGER).add( Expression.like( “ description ”, description) ).createCriteria( “ successfulBid ” ).add( Expression.gt( “ amount ”, minAmount) ).list(); Equivalent IQL: from AuctionItem item left join fetch item.bids where item.description like :description and item.successfulbid.amount > :minAmount

February,2006 Advanced DB System Example Queries AuctionItem item = new AuctionItem(); item.setDescription( “ hib ” ); Bid bid = new Bid(); bid.setAmount(1.0); List auctionItems = session.createCriteria(AuctionItem.class).add( Example.create(item).enableLike(MatchMode.START) ).createCriteria( “ bids ” ).add( Example.create(bid) ).list(); Equivalent IQL: from AuctionItem item join item.bids bid where item.description like ‘ hib% ’ and bid.amount > 1.0

February,2006 Advanced DB System Conclusion  whether Object-Relation mapping can be successful forever?  they are continue until they can convert objects to relation.

February,2006 Advanced DB System References [1]. Mapping Objects to Relational Databases: O/R Mapping in Detail, Scott W.ambler July [2] A Relational Model of Data for Large Shared Data Banks, E. F. Codd, [3] Achievement and weaknesses of object oriented databases, Sikha Bagui, Department of Computer Science, University of West Florida, U.S.A, Published by ETH Zurich,2003. [4] On type systems for object oriented database programming language, Yuri Leontiev, M. Tammer Ozsa, Duane Szafron, ACM Computing Surveys,2002 [5] object/Relational Access Layers, a roadmap, Missing Links and More Patterns, wolfgang keller, 3rd European conference of pattern languages of programming and computing [6] DB2's Object-Relational Highlights ibm.com/developerworks/db2/library/techarticle/zeidenstein/0108zeidenstein.html [7]Simple Strategies for Complex Data: Oracle9i Object-Relational Technology