Скачать презентацию Persistent Objects Persistent objects are objects that continue Скачать презентацию Persistent Objects Persistent objects are objects that continue

f37194fc3ca8eb1b7661656334bd2f60.ppt

  • Количество слайдов: 25

Persistent Objects Persistent objects are objects that continue to exist after the application program Persistent Objects Persistent objects are objects that continue to exist after the application program terminates Persistence is provided by a DBMS • ACID properties … “D” Two main categories • OODBMS • RDBMS 2 nd edition Chapter 34: 3 rd edition Chapter 38: Intro, 1, 2, 4, 5, 6, 7, 8, 9, 16, 17, 19 March 2005 92. 3913 R Mc. Fadyen 1

Architectural layers User Interface Application Technical Services March 2005 Nextgen. POS Relational Database 92. Architectural layers User Interface Application Technical Services March 2005 Nextgen. POS Relational Database 92. 3913 R Mc. Fadyen Mapping Service 2

Persistent Objects To use an RDBMS for Next. Gen. POS, we require an object Persistent Objects To use an RDBMS for Next. Gen. POS, 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 : buy, not build • provides functions such as store, retrieve, modify, commit, rollback March 2005 92. 3913 R Mc. Fadyen 3

Key Ideas Mapping There are two schemas: object and relational. We need a mapping 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 March 2005 92. 3913 R Mc. Fadyen 4

Patterns Representing Objects as Tables Object Identifier Representing Object Associations as Tables one-to-one one-to-many-to-many Patterns Representing Objects as Tables Object Identifier Representing Object Associations as Tables one-to-one one-to-many-to-many with an Association Class Aggregation and Composition Superclass/Subclass March 2005 92. 3913 R Mc. Fadyen 5

Each class becomes a table Representing Objects as Tables pattern define a table for 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 1 NF tables Class An object The 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 March 2005 92. 3913 R Mc. Fadyen 6

<<Table>> stereotype We can indicate tables in UML using the stereotype: <<Table>> Note you <

> stereotype We can indicate tables in UML using the stereotype: <
> Note you can use UML for designing relational databases March 2005 92. 3913 R Mc. Fadyen 7

OIDs Object Identifier Pattern assign an OID to each record and object i. e. OIDs Object Identifier Pattern assign an OID to each record and object i. e. We augment the attributes with a new attribute that we refer to as the OID We can use the OID to prevent from instantiating the same object twice and to help find an instance 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 March 2005 92. 3913 R Mc. Fadyen 8

Façade Persistence subsystem will have a Façade that provides access to its services façade Façade Persistence subsystem will have a Façade that provides access to its services façade The façade is implemented using Singleton March 2005 92. 3913 R Mc. Fadyen Requesting a Product. Specification with a specific OID 9

Representing Relationships in Tables Representing Object Associations as Tables pattern one-to-one place an OID 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 Store March 2005 1 1 houses 92. 3913 Register R Mc. Fadyen 10

Representing Relationships in Tables Representing Object Associations as Tables pattern one-to-many create an associative 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 Product. Catalog March 2005 1 1. . * contains 92. 3913 Product. Specification R Mc. Fadyen 11

Representing Relationships in Tables Representing Object Associations as Tables pattern many-to-many create an associative 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 Company March 2005 * * employs 92. 3913 Person R Mc. Fadyen 12

Representing Relationships in Tables Representing Object Associations as Tables pattern many-to-many AND with an 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 and attributes of the association class Company * * employs Person Employment March 2005 92. 3913 R Mc. Fadyen 13

Representing Relationships in Tables Representing Object Associations as Tables pattern many-to-many AND with an 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 March 2005 Marriage * marries 92. 3913 R Mc. Fadyen 14

Representing Relationships in Tables Representing Object Associations as Tables pattern Aggregation and Composition 1. Representing Relationships in Tables Representing Object Associations as Tables pattern Aggregation and Composition 1. . * Sale Programme contains * 1. . * contains Sales. Line. Item Course Treat as 1 -to-many and many-to-many associations (Aside: Note that relational integrity rules/triggers may need to be defined. ) March 2005 92. 3913 R Mc. Fadyen 15

Representing Relationships in Tables Representing Object Associations as Tables pattern Superclass/Subclass Payment Cash. Payment Representing Relationships in Tables Representing Object Associations as Tables pattern Superclass/Subclass Payment Cash. Payment Credit. Payment Cheque. Payment 3 basic choices: • all classes represented as separate tables, • only the ‘leaf’ classes, or • one table for all Others are possible (see 91. 3902/3) March 2005 92. 3913 R Mc. Fadyen 16

OR Mapping - Example Suppose we have the following class model: Program name type OR Mapping - Example Suppose we have the following class model: Program name type * contains Course * name description credit Offering * slot offer room description 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. March 2005 92. 3913 R Mc. Fadyen 17

Example - recall patterns for O-R mappings O-R Mapping • The Representing Objects as 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 March 2005 92. 3913 R Mc. Fadyen 18

Example - mapping O-R Mapping, for the given class model we could decide: Class Example - mapping O-R Mapping, for the given class model we could decide: Class Program Course Offering Maps to Relation Program Course Offering Association Maps to Relation/FKey contains Table: Contains offer FK in Offering (refers to Course) March 2005 92. 3913 R Mc. Fadyen 19

Example - mapping Relational Schema Program p. OID name Offering o. OID slot Course Example - mapping Relational Schema Program p. OID name Offering o. OID slot Course c. OID name type description • Attributes room c. OID • PKs underlined. credit description Contains c. OID p. OID March 2005 Illustrates the structure of the relations 92. 3913 R Mc. Fadyen • FKs indicated via dashed lines. 20

Example - mapping Table structure with some sample records Program p. OID 123 334 Example - mapping Table structure with some sample records Program p. OID 123 334 name 3 -year 4 -year Course c. OID 256 333 456 name C Programming Java Programming Systems Analysis March 2005 type R R description A 3 -year programme of studies in Business Computing . . . credit 3 3 3 92. 3913 description This course introduces …. . . R Mc. Fadyen 21

Example - application models Note that these relational structures are very different from the Example - application models Note that these relational structures are very different from the class structures that OO programs would use. For example, a course object will contain, within it, its offerings: public class Course ings course offer llection of A co { private Hashtable Offerings = new Hashtable(); … course_offering = new Offering (…) Offerings. put (…, course_offering); ollection ring to the c urse offe } Adding a co Part of the complexity of a system that uses objects and tuples/rows in an RDb is the translation from/to the other. March 2005 92. 3913 R Mc. Fadyen 22

Object to Relational Mapping Products EJB-related products providing object to relational mapping services • Object to Relational Mapping Products EJB-related products providing object to relational mapping services • Co. Base • Top. Link • en. Jin March 2005 92. 3913 R Mc. Fadyen 23

Object to Relational Mapping Products en. Jin: the following is from: http: //www. versant. Object to Relational Mapping Products en. Jin: the following is from: http: //www. versant. com/products/enjin/whitepapers/WP_Benchmark-011022 r 4 -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-torelational impedance mismatch, and which successfully improves both the response times and transaction throughput of applications deployed on J 2 EE application servers such as IBM's Web. Sphere. March 2005 92. 3913 R Mc. Fadyen 24

Object to Relational Mapping Products Top. Link a commercial product (Oracle) that provides object Object to Relational Mapping Products Top. Link a commercial product (Oracle) 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 Top. Link 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. March 2005 92. 3913 R Mc. Fadyen 25