OO - Lecture 4 Tutorial Review Associations Inheritance of Functions Polymorphism.

Slides:



Advertisements
Similar presentations
Copyright  Oracle Corporation, All rights reserved. 3 Displaying Data from Multiple Tables.
Advertisements

Displaying Data from Multiple Tables. Objectives After completing this lesson, you should be able to do the following: Write SELECT statements to access.
BACS 485—Database Management Advanced SQL Overview Advanced DDL, DML, and DCL Commands.
12-1 Copyright  Oracle Corporation, All rights reserved. What Is a View? EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
Restricting and sorting data 16 May May May Created By Pantharee Sawasdimongkol.
Bogdan Shishedjiev SQL1 SQL Reminder of SQL. Bogdan Shishedjiev SQL 2 Subsets of language Data definition language (DDL) –Domain definition –Schema definition.
1Eyad Alshareef Enhanced Guide to Oracle 10g Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
Copyright  Oracle Corporation, All rights reserved. 6 Writing Correlated Subqueries.
SQL zSeQueL zSQL zSQL ybetter support for Algebraic operations zSQL Post-Relational yrow and column types, stored procedures, triggers,
The Relational Data Model zE.F Codd A Relational Data Model for Large Shared Data Banks (1970) zThe basic model used by Access, Oracle, DB2 zAll Relational.
Session 3: SQL (B): Parts 3 & 4 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram.
ERM to SQL. Abstraction Layers Conceptual –What data is held An Image and its meta-data Entity-Relationship model (ERM) Logical –How data is organised.
Logical Operators Operator AND OR NOT Meaning Returns TRUE if both component conditions are TRUE Returns TRUE if either component condition is TRUE Returns.
Dr. Philip Cannata 1 Doug Tolbert Unisys Doug Tolbert has been involved with OMG since the early 1990s. He is.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Introduction to Objects & Databases These.
o At the end of this lesson, you will be able to:  Describe the life-cycle development phases  Discuss the theoretical and physical aspects of a relational.
Copyright  Oracle Corporation, All rights reserved. I Introduction.
4-1 Copyright  Oracle Corporation, All rights reserved. Data Manipulation Language (DML)
4-1 Copyright  Oracle Corporation, All rights reserved. Displaying Data from Multiple Tables.
Dr. Philip Cannata 1 Programming Languages Prolog Part 3 SQL & Prolog.
Lecture 8 Database Theory & Practice (2) : The Relational Data Model UFCEKG-20-2 Data, Schemas & Applications.
Displaying Data from Multiple Tables (Join). EMPNO DEPTNO LOC NEW YORK CHICAGO NEW YORK DALLAS.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Introduction to Relational Databases &
MSc IT UFIE8K-15-M Data Management Prakash Chatterjee Room 3P16
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Cursors These slides are licensed under.
Subqueries.
An Introduction To SQL - Part 1 (Special thanks to Geoff Leese)
Copyright س Oracle Corporation, All rights reserved. I Introduction.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
SQL- DQL (Oracle Version). 2 SELECT Statement Syntax SELECT [DISTINCT] column_list FROM table_list [WHERE conditional expression] [GROUP BY column_list]
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Basic SQL These slides are licensed under.
Session 2: SQL (A): Parts 1 and 2 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram.
4 Displaying Data from Multiple Tables Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina,
Copyright س Oracle Corporation, All rights reserved. 4 Displaying Data from Multiple Tables.
I-1 Copyright س Oracle Corporation, All rights reserved. Data Retrieval.
SQL: Part 2 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram. Not for commercial.
Copyright  Oracle Corporation, All rights reserved. 12 Creating Views.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Subqueries These slides are licensed under.
An Introduction To SQL Part 2 (Special thanks to Geoff Leese)
1 Information Retrieval and Use (IRU) An Introduction To SQL Part 2.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Object-Relational Database Programming.
Copyright س Oracle Corporation, All rights reserved. I Introduction.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Relational State Assertions These slides.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Collection Operators These slides are.
Oracle CONNECT BY function JAVA WEB Programming. Emp 테이블의 내용 ( 상 / 하급자 계층구조 ) SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
2-1 Limiting Rows Using a Selection “…retrieve all employees in department 10” EMP EMPNO ENAME JOB... DEPTNO 7839KINGPRESIDENT BLAKEMANAGER CLARKMANAGER.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Grouping These slides are licensed under.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Collection Operators These slides are.
Copyright س Oracle Corporation, All rights reserved. 12 Creating Views.
Copyright  Oracle Corporation, All rights reserved. 2 Restricting and Sorting Data.
Displaying Data from Multiple Tables (Join) Displaying Data from Multiple Tables (Join) Displaying Data from Multiple Tables (Join Displaying Data from.
Copyright  Oracle Corporation, All rights reserved. 4 Displaying Data from Multiple Tables.
Displaying Data from Multiple Tables. Objectives After completing this lesson, you should be able to do the following: –Write SELECT statements to access.
4 Displaying Data from Multiple Tables. 4-2 Objectives At the end of this lesson, you should be able to: Write SELECT statements to access data from more.
Communicating with a RDBMS Using SQL Database SQL> SELECT loc 2 FROM dept; SQL> SELECT loc 2 FROM dept; SQL statement is entered Statement is sent to database.
Relational Normalization Theory
Displaying Data from Multiple Tables
Displaying Data from Multiple Tables
Subqueries.
Writing Correlated Subqueries
What Is a View? EMPNO ENAME JOB EMP Table EMPVU10 View
(SQL) Displaying Data from Multiple Tables
Lecture 16 : The Relational Data Model
Lecture 16 : The Relational Data Model
Displaying Data from Multiple Tables
Copyright © Ellis Cohen
Presentation transcript:

OO - Lecture 4 Tutorial Review Associations Inheritance of Functions Polymorphism

EMP-DEPT example Three relations: Department : DEPT Employee : EMP Salary Grade : SALGRADE

Dept DeptnoDnameLoc 10AccountingNew York 20ResearchDallas 30SalesChicago 40OperationsBoston GradeLosalHisal 1£700.00£1, £1,201.00£1, £1,401.00£2, £2,001.00£3, £3,001.00£99, Salgrade Table

EMP - table ( reduced) EmpnoEnameMgr Sal Deptno 7369SMITH7902 £ ALLEN7698£1, WARD7698£1, JONES7839£2, MARTIN7698£1, BLAKE7839£2, CLARK7839£2, SCOTT7566£3, KING£5, TURNER7698£1, ADAMS7788£1, JAMES7698 £ FORD7566£3, MILLER7782£1,

dept Emp salgrade Deptno (Pk) dname loc Empno (Pk) ename job hiredate sal comm mgr (Fk-->emp) deptno (Fk-Dept) manages Losal hisal grade

Review AGGREGATION E.g. the Step-function type, or latlong type Each part belongs exclusively to its parent If you delete the parent, you delete all the parts Parts can’t move to another parent How is Dept-Emp different? latlong dm Latitude Longitude emp dept

Associations Departments and employees have independent existence Relationship can be changed - employee can move department If Dept deleted, relationship removed but not the employee. ASSOCIATION

Dept Deptno : String Dname : String Location : String Emp Empno : String Ename : String Hiredate : Date Job : String Sal : Money Comm : Money 1 0..* 1

Foreign key solution In a relational DB, we implement a 1-Many association as : –primary key on DEPT e.g. DEPTNO –column in EMP containing values of DEPTNO To navigate from emp to dept: select ename, dname from emp, dept where emp.deptno=dept.deptno;

Object reference solution create or replace type staff as object ( … deptno number(4), deptref ref dept, … update staffs s set deptref = (select ref(d) from depts d where d.deptno = s.deptno); A field which contains a reference to another object ( here a dept object) Get a reference (pointer) to a dept object select s.ename,s.deptref.dname from staffs s; Just follow the reference

Kinds of Employee Suppose we want to include contractors as well as salaried employees. Contractors have the same basic data but the wages are calculated from an hourly rate and the number of hours worked. How can we represent this variation?

Use inheritance Contractor hourrate : Money hours : Number Staff Empno : String Ename : String Hiredate : Date Job : String Salaried Sal : Money Comm : Money

Inheritance of attributes What attributes has a salaried staff? What attributes has a contractor?

Inheritance of Functions Days worked: –the number of days worked can be calculated by subtracting hiredate from sysdate (todays date) [not quite right !] Where can we place this function? How do we calculate the days worked for a salaried staff? For a contractor?

A member function member function daysWorked return number is begin return hiredate - sysdate; end ;

Inheritance of functions Contractor hourrate : Money hours : Number Staff Empno : String Ename : String Hiredate : Date Job : String daysWorked() : Number Salaried Sal : Money Comm : Money

Inheritance at work Attributes are inherited when an object is constructed (at birth):- –emp staff; –emp:= salaried(7499,'ALLEN','13 jun 93', ‘Analyst’, 1600,300); Functions are inherited dynamically - when called –emp.daysWorked() How? System looks at Salaried type first, but no daysWorked(), so looks in supertype - Staff Attributes from staff Attributes from salaried

Specialisation of functions Each kind of staff needs its own calculation of annualSal –one for salaried using 12*sal + comm –one for contractors using hours * hourrate so provide a different function (with the same name) in each subtype.

overriding member function annualsal return number is begin return hourrate * hours; end; In Contractor Multiple Function definitions In Salaried overriding member function annualsal return number is begin return sal*12 + comm; end; Same function name - different function implementations for each subtype

In Staff (the super type) create or replace type staff as object ( ….. not instantiable member function annualsal return number) not instantiable not final; No implementation of this function in Staff (so there must be one in every subtype) Type can have subtypes Cannot create instances (objects) of this type - Abstract

Polymorphism Consider a function in Dept to calculate the total wage bill (in the department) It will call annualSal() on each of its employees in turn But some are Salaried, some are Contractors?

Polymorphism ‘ many shapes’ member function annualtotal return number is tot number(12,2); sal number(12,2); cursor deptstaff is select s.annualsal() as sal from staffs s where s.deptno = self.deptno; begin tot:=0; for ts in deptstaff loop tot := tot + ts.sal; end loop; return tot; end; Some are Salaried, some are Contractors Appropriate function implementaion is executed s takes on the ‘shape’ of different kinds of Staff Select all the staff in the department

Further Extensions How would you do this? Add children to staff –each staff member can have up to 20 children, recording just their names and dob Implement the salary table Add another type of staff - volunteer staff are paid a simple annual gratuity

Next Week Tutorial –Work with tutor on the Emp-Dept case study and its implementation –Understand what has been done so far –Add some extensions Lecture –Processes UML diagrams Scenarios Process models