Presentation is loading. Please wait.

Presentation is loading. Please wait.

Nov 20, 200291.3913 R McFadyen1 Persistent Objects Key ideas/definitions UML representations Mapping patterns Transactional states Example Some commercial.

Similar presentations


Presentation on theme: "Nov 20, 200291.3913 R McFadyen1 Persistent Objects Key ideas/definitions UML representations Mapping patterns Transactional states Example Some commercial."— Presentation transcript:

1 Nov 20, 200291.3913 R McFadyen1 Persistent Objects Key ideas/definitions UML representations Mapping patterns Transactional states Example Some commercial products Sections (Ch 34) Intro, 1, 2, 4, 5, 6, 7, 8, 9, 16, 19

2 Nov 20, 200291.3913 R McFadyen2 Persistent Objects Persistent objects are objects that continue to exist after the application program terminates (contrast to transient objects) Persistence is provided by a DBMS ACID property “D” Two main categories OODBMS RDBMS

3 Nov 20, 200291.3913 R McFadyen3 Persistent Objects To use an RDBMS, we require an object to relational mapping service persistence service is a subsystem within the Technical Services Layer mismatch between record-oriented and object-oriented representations of data recommendation is to buy, not to build provides functions such as store, retrieve, modify, commit, rollback

4 Nov 20, 200291.3913 R McFadyen4 Key Ideas Mapping There are two schemas: object and relational. We need a mapping that translates from one to the other. Object Identity Records and objects have a unique identifier Materialization/Dematerialization need to be able to translate the non-object representation to an object representation, and vice versa Lazy Materialization Some objects are not materialized all-at-once; part of the object may be done first, and other parts later on (contrast to eager materialization)

5 Nov 20, 200291.3913 R McFadyen5 > stereotype We can indicate tables in UML using the stereotype: >

6 Nov 20, 200291.3913 R McFadyen6 Patterns Representing Objects as Tables Object Identifier Representing Object Associations as Tables one-to-one one-to-many many-to-many many-to-many with an Association Class Aggregation and Composition Superclass/Subclass

7 Nov 20, 200291.3913 R McFadyen7 Each class becomes a table Representing Objects as Tables pattern define a table for each persistent object class Some mappings are straight forward We require 1NF tables ClassAn objectThe table Many of these patterns mentioned come from a paper “Crossing Chasms: A Pattern Language for Object-RDBMS” published in 1996 in Pattern Languages of Program Design

8 Nov 20, 200291.3913 R McFadyen8 OIDs Objects have an OID that is used as the PK in a relational table. Each object is uniquely mapped to a row in the table Object Identifier Pattern assign an OID to each record and object

9 Nov 20, 200291.3913 R McFadyen9 Façade Persistence subsystem will have a Façade that provides access to its services façade Requesting a ProductSpecification with a specific OID

10 Nov 20, 200291.3913 R McFadyen10 Representing Relationships in Tables Representing Object Associations as Tables pattern one-to-one place an OID FK in one or both tables representing the objects in the association or, create an associative table that records the OIDs of each object in the association or, could merge the two classes into one table Consider StoreRegister houses 11

11 Nov 20, 200291.3913 R McFadyen11 Representing Relationships in Tables Representing Object Associations as Tables pattern one-to-many create an associative table that records the OIDs of each object in relationship or, could use a Foreign Key on the Many side Consider ProductCatalogProductSpecification contains 11..*

12 Nov 20, 200291.3913 R McFadyen12 Representing Relationships in Tables Representing Object Associations as Tables pattern many-to-many create an associative table that records the OIDs of each object in relationship CompanyPerson employs **

13 Nov 20, 200291.3913 R McFadyen13 Representing Relationships in Tables Representing Object Associations as Tables pattern many-to-many AND with an Association Class create an associative table that records the OIDs of each object in relationship... CompanyPerson employs ** Employment

14 Nov 20, 200291.3913 R McFadyen14 Representing Relationships in Tables Representing Object Associations as Tables pattern many-to-many AND with an Association Class create an associative table that records the OIDs of each object in relationship... Person marries * * Marriage

15 Nov 20, 200291.3913 R McFadyen15 Representing Relationships in Tables Representing Object Associations as Tables pattern Aggregation and Composition... SaleSalesLineItem contains 1..* ProgrammeCourse contains 1..* *

16 Nov 20, 200291.3913 R McFadyen16 Representing Relationships in Tables Representing Object Associations as Tables pattern Superclass/Subclass... Payment CreditPaymentCashPaymentChequePayment 3 basic choices: all concrete classes represented as separate tables, only the ‘leaf’ classes represented as separate tables, or one table for all

17 Nov 20, 200291.3913 R McFadyen17 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

18 Nov 20, 200291.3913 R McFadyen18 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

19 Nov 20, 200291.3913 R McFadyen19 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

20 Nov 20, 200291.3913 R McFadyen20 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 directed lines. cOID

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

22 Nov 20, 200291.3913 R McFadyen22 Example - mapping Table structure with some sample records Contains 123256 303 456 pOIDcOID 123 334 Suppose the 3-year programme comprises ‘C Programming’ and ‘Java Programming’. Suppose the 4-year programme comprises ‘C Programming’, ‘Java Programming’, and ‘Systems Analysis’. Then, the Contains table would be: 334256 303334

23 Nov 20, 200291.3913 R McFadyen23 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

24 Nov 20, 200291.3913 R McFadyen24 Transactional States Persistent objects can be inserted, updated, deleted Transactions are a unit-of-work comprise one or more database operations committed or rolled back Consider states for a persistent object : New, OldClean, OldDirty, OldDelete, and Deleted Figure 34.12 helps us describe how and when a persistent object can be in a certain persistent state. This is useful if you need to design/code this capability, or perhaps to help you evaluate a package providing this service

25 Nov 20, 200291.3913 R McFadyen25 Transactional States New an object is created in the application, but does not exist in the database yet OldClean When a new object is committed, or when an object is first materialized from the database it is old and it is clean (hasn’t been altered by an application) OldDirty When an object that is represented in the database is modified by an application, it is considered dirty (it has values that are not the same as those in the database copy)

26 Nov 20, 200291.3913 R McFadyen26 Transactional States OldDelete When an object that is represented in the database is deleted by an application it is considered deleted, but this is not permanent yet (the transaction has not committed) Deleted An object is considered deleted when the application that deleted it is committed.

27 Nov 20, 200291.3913 R McFadyen27 Transactional States - Fig 34.12 modified This statechart diagram is a succinct representation of the states of an object.

28 Nov 20, 200291.3913 R McFadyen28 Object to Relational Mapping Products EJB-related products providing object to relational mapping services CoCoBase TopLink enJin

29 Nov 20, 200291.3913 R McFadyen29 enJin: the following is from: http://www.versant.com/products/enjin/whitepapers/WP_Benchmark-011022r4-W.pdf “… This object-to-relational bottleneck is often referred to as an 'impedance mismatch', since in order to store data in an RDBMS, objects must be broken down into flat table structures, and to retrieve objects, they must be built up from these RDBMS 'flat' structures. This white paper examines the performance characteristics of a product that has been designed specifically to overcome this object-to- relational impedance mismatch, and which successfully improves both the response times and transaction throughput of applications deployed on J2EE application servers such as IBM's WebSphere. Object to Relational Mapping Products

30 Nov 20, 200291.3913 R McFadyen30 High Level enJin Architecture from http://www.versant.com/products/enjin/whitepapers/WP_Benchmark-011022r4-W.pdf Object to Relational Mapping Products

31 Nov 20, 200291.3913 R McFadyen31 TopLink a commercial product that provides object to relational mapping capability “In an enterprise Java environment, one of the most formidable challenges is storing business objects and components in a relational database (RDB). Oracle TopLink provides developers with the flexibility to map objects and Enterprise Java Beans to a relational database schema with minimal impact on ideal application design or database integrity. The result — developers focused on addressing business needs rather than building infrastructure. Object to Relational Mapping Products


Download ppt "Nov 20, 200291.3913 R McFadyen1 Persistent Objects Key ideas/definitions UML representations Mapping patterns Transactional states Example Some commercial."

Similar presentations


Ads by Google