Presentation is loading. Please wait.

Presentation is loading. Please wait.

March 27, 200291.3913 R McFadyen1 OR Mapping - Example When we map this structure to a Relational Database, we are creating an object-to-relational mapping.

Similar presentations


Presentation on theme: "March 27, 200291.3913 R McFadyen1 OR Mapping - Example When we map this structure to a Relational Database, we are creating an object-to-relational mapping."— Presentation transcript:

1 March 27, 200291.3913 R McFadyen1 OR Mapping - Example When we map this structure to a Relational Database, we are creating an object-to-relational mapping. We need to define the relational database schema and specify which class(es) map to which relation(s), and whether the associations are mapped to relations or to foreign keys. Suppose we have the following class model: Program name type description Course name credit description * * Offering slot room contains * offer In question 4 on assignment 4, you are asked to design an object to relational mapping. The answer must indicate the resulting the relational database and the mapping.

2 March 27, 200291.3913 R McFadyen2 Example - recall patterns for O-R mappings O-R Mapping The Representing Objects as Tables pattern says that each class will be represented in the RDb by a separate table (relation). The Object Identifier pattern tells us that each table representing a class will have the OID as the PK. The Representing Object Associations as Tables pattern gives us several options: use an association table to represent the association (for 1-1 and 1-m) we can choose to use a Foreign Key for a 1-1 we can choose to merge the two classes into one table etc

3 March 27, 200291.3913 R McFadyen3 Example - mapping ClassMaps to Relation Program Course AssociationMaps to Relation/FKey containsTable: Contains offerFK in Offering (refers to Course) Offering O-R Mapping, for the given class model we could decide: Course Program

4 March 27, 200291.3913 R McFadyen4 Example - mapping Relational Schema Program Course Offering nametypedescription slotroom namecreditdescription Contains pOID oOID cOID pOID cOID Illustrates the structure of the relations PKs are underlined. FKs are indicated via dashed lines. cOID

5 March 27, 200291.3913 R McFadyen5 Example - mapping Table structure with some sample records Program Course nametypedescription C Programming3This course introduces … pOID 256 3-yearR123 4-yearR...334 Java Programming3...256 Systems Analysis3...456 namecreditdescriptioncOID A 3-year programme of studies in Business Computing

6 March 27, 200291.3913 R McFadyen6 Example - application models Note that these relational structures are very different from the class structures that application programs would use. For example, a course object will contain, within it, its offerings: public class Course { private Hashtable Offerings = new Hashtable(); … course_offering = new Offering (…) Offerings.put (…, course_offering); } Part of the complexity of a system that uses objects and tuples/rows in an RDb is the translation from/to the other. A collection of course offerings Adding a course offering to the collection


Download ppt "March 27, 200291.3913 R McFadyen1 OR Mapping - Example When we map this structure to a Relational Database, we are creating an object-to-relational mapping."

Similar presentations


Ads by Google