1 / 6

OR Mapping - Example

OR Mapping - Example. Suppose we have the following class model:. Program. Course. Offering. *. name type description. name credit description. slot room. *. *. contains. offer.

renate
Download Presentation

OR Mapping - Example

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OR Mapping - Example • Suppose we have the following class model: Program Course Offering * name type description name credit description 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. 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. 91.3913 R McFadyen

  2. 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 91.3913 R McFadyen

  3. Example - mapping Association Maps to Relation/FKey contains Table: Contains offer FK in Offering (refers to Course) O-R Mapping, for the given class model we could decide: Class Maps to Relation Program Program Course Course Offering Offering 91.3913 R McFadyen

  4. Example - mapping Relational Schema Program pOID name type description • Illustrates the structure of the relations • PKs are underlined. • FKs are indicated via dashed lines. Offering oOID slot room cOID Course cOID name credit description Contains cOID pOID 91.3913 R McFadyen

  5. Example - mapping Table structure with some sample records Program pOID name type description 123 3-year R A 3-year programme of studies in Business Computing 334 4-year R ... Course cOID name credit description 256 C Programming 3 This course introduces … 256 Java Programming 3 ... 456 Systems Analysis 3 ... 91.3913 R McFadyen

  6. Example - application models A collection of course offerings Adding a course offering to the collection 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. 91.3913 R McFadyen

More Related