|
Mapping Classes to Relational Tables (Continued)
To instantiate a FullTime employee object, we only need to read from one table:
select name, dob, hiredate, ssn,
payrate from FullTime
where name = 'Sarah Jackson'
Similarly, we can update an Exempt employee by writing to one table:
update Exempt set dob=
"06/30/1962", set hiredate=
"06/15/1997", set ssn=
"567-89-0123", set salary =
52000.00
where name = 'Nicky Colson'
Note that updating unchanged columns is not necessary, but will highlight some of the differences between horizontal/union mapping and vertical mapping. To remove an object:
delete from Manager where name =
'Susan Jekel'
In the next case, we need to perform the query on each of the horizontal tables and return the combined results to find employees hired since "01/01/1998":
select name, dob, hiredate, ssn,
payrate from PartTime
where hiredate >= "01/01/1998"
select name, dob, hiredate, ssn,
payrate from FullTime
where hiredate >= "01/01/1998"
select name, dob, hiredate, ssn,
salary from Exempt
where hiredate >= "01/01/1998"
select name, dob, hiredate, ssn,
salary from Manager
where hiredate >= "01/01/1998"
Part 2 of this article will take a look at union and vertical inheritance mapping and include SQL examples for creating, reading, updating, removing, and retrieving objects under those approaches.
About the Author
Richard Jensen is a senior architect at Persistence Software.
Back to top
|