chapter 11 data management layer design

52
Slide 1 Chapter 11 Data Management Layer Design

Upload: basil-bird

Post on 04-Jan-2016

76 views

Category:

Documents


4 download

DESCRIPTION

Chapter 11 Data Management Layer Design. Data Management Layer. Choose object-persistence format to support the system Problem domain objects drive object storage design Design of Data Storage Must optimize processing efficiency Data access and manipulation - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Chapter 11 Data Management Layer Design

Slide 1

Chapter 11Data Management Layer Design

Page 2: Chapter 11 Data Management Layer Design

Slide 2

Data Management LayerChoose object-persistence format to support the system

Problem domain objects drive object storage design

Design of Data StorageMust optimize processing efficiency

Data access and manipulationSeparate problem domain classes from storage formatHandle all communication with the database

Page 3: Chapter 11 Data Management Layer Design

Slide 3

Object Persistence Formats

Files (Sequential and Random)Relational databasesObject-relational databases Object-oriented databases

Page 4: Chapter 11 Data Management Layer Design

Slide 4

Customer Order File

Page 5: Chapter 11 Data Management Layer Design

Slide 5

Sequential and Random Access Files

Sequential access files allow sequential operations

Read, write, and searchEfficient for report writingSearches are not efficient because an average of 50% of records have to be accessedTwo versions

Ordered unordered

Page 6: Chapter 11 Data Management Layer Design

Slide 6

Random Access Files

Allow only random or direct file operationsGood for finding and updating a specific objectInefficient report writing

Page 7: Chapter 11 Data Management Layer Design

Slide 7

Application File Types

Master FilesLook-up filesTransaction filesAudit fileHistory file

Page 8: Chapter 11 Data Management Layer Design

Slide 8

Relational DatabasesCollection of tables

Comprised of fields that define entitiesPrimary key has unique values in each row of a tableForeign key is primary key of another table

Tables related to each otherPrimary key field of a table is a field of another table and called a foreign keyRelationship established by a foreign key of one table connecting to the primary key of another table

Page 9: Chapter 11 Data Management Layer Design

Slide 9

Customer Order Database

Page 10: Chapter 11 Data Management Layer Design

Slide 10

Database Management System (DBMS)

Software that creates and manipulates a databaseRDBMS is a DBMS for a relational databaseRDBMS usually support Referential Integrity

Page 11: Chapter 11 Data Management Layer Design

Slide 11

Referential Integrity

the idea of ensuring that values linking the tables together through the primary and foreign keys are valid and correctly synchronized.

Page 12: Chapter 11 Data Management Layer Design

Slide 12

Referential Integrity Example

Cust. ID is a primary key for the customer tableCust. ID is a foreign key for the order tableA violation of referential integrity would happen if an order was entered in the order table for a Cust. ID that had not been entered into the customer table firstAn RDBMS prevents such a record from being entered

Page 13: Chapter 11 Data Management Layer Design

Slide 13

Example of Referential Integrity

Page 14: Chapter 11 Data Management Layer Design

Slide 14

Structured Query Language (SQL)

Standard language for accessing data in tablesSQL Commands

Create, edit, and delete tablesAdd, edit, and delete dataDisplay data from one or more related tablesDisplay data computed from data in one or more related tables

Page 15: Chapter 11 Data Management Layer Design

Slide 15

Object-Relational Databases

Relational database management systems with extensions that handle object storage in the relational table structureThis is done by user defined types

Example: Create a map data type

Page 16: Chapter 11 Data Management Layer Design

Slide 16

Vendors Support ORDBMS

SQL designed for simple data typesVendors extend SQL to handle user data types in Object Relational DatabasesUsually they don’t support most object oriented features e.g. inheritance

Page 17: Chapter 11 Data Management Layer Design

Slide 17

Object-Oriented Databases (OODBMS)

Add persistence extensions to an object-oriented programming languageCreate a entirely separate database management system

Page 18: Chapter 11 Data Management Layer Design

Slide 18

OODBMS Terminology

Extent is a collection of objectsSet of instances associated with a particular class (RDBMS table)Each instance of a class has a unique identifier called an object IDReferential integrity still importantSupports a form of inheritance

Page 19: Chapter 11 Data Management Layer Design

Slide 19

OODBMS Support

Allow repeating groups or multivalued attributesSupports multimedia or other complex data applications

CAD/CAMFinancial servicesGeographic information systemsHealth care

Page 20: Chapter 11 Data Management Layer Design

Slide 20

Major Strengths & Weaknesses

FilesVery efficient for given taskManipulation done by OOPLRedundant data usually results

RDBMSProven commercial technologyHandle diverse dataNo support for object orientation

Page 21: Chapter 11 Data Management Layer Design

Slide 21

More Strengths and Weaknesses

ORDBMSInherit RDBMS strengthsSupport complex data typesLimited support for object-orientation (vendor dependent)

OODBMSSupport complex data typesSupport object-orientation directlyStill maturing (lacks skilled labor and may have a steep learning curve)

Page 22: Chapter 11 Data Management Layer Design

Slide 22

Criteria for Object Persistence Formats

Data types supportedTypes of application systems (transaction processing, DSS, …)Existing Storage FormatsFuture NeedsOther miscellaneous Criteria (cost, concurrency control, …)

Page 23: Chapter 11 Data Management Layer Design

Slide 23

Mapping Objects to Object-Persistence Formats

Page 24: Chapter 11 Data Management Layer Design

Slide 24

Multiple Inheritance Effect Rules

Results when you have more than one super classRule 1a. Add an attribute(s) to the OODBMS class to represent the additional super classRule 1b. Flatten the inheritance hierarchy and remove additional super classes from the design

Page 25: Chapter 11 Data Management Layer Design

Slide 25

Mapping to Single I-B OODBMS

Page 26: Chapter 11 Data Management Layer Design

Slide 26

Using Rule 1aAdded an attribute to Class1-OODBMS that represents an association with Super-Class2-OODBMS,Added attributes to Class2-OODBMS that represents an association with Super-Class2-OODBMS,Added a pair of attributes to SuperClass2-OODBMS that represents an association with Class1-OODBMS and Class2-OODBMS, for completeness sale, andAdded associations between Class2-OODBMS and SuperClass2-OODBMS and Class1-OODBMS and SuperClass2-OODBMS that have the correct multiplicities and the XOR constraint explicitly shown.

Page 27: Chapter 11 Data Management Layer Design

Slide 27

Mapping PDO to ORDBMS

Page 28: Chapter 11 Data Management Layer Design

Slide 28

Mapping Table to PD Classes

Page 29: Chapter 11 Data Management Layer Design

Slide 29

Mapping PD Objects to RDBMS Schema

Rule 1: Map all concrete problem domain classes to the RDBMS tables. Rule 2: Map single valued attributes to columns of the tables.Rule 3: Map methods to stored procedures or to program modules.Rule 4: Map single-valued aggregation and association relationships to a column that can store the key of the related tableRule 5: Map multi-valued attributes and repeating groups to new tables and create a one-to-many association from the original table to the new ones.Rule 6: Map multi-valued aggregation and association relationships to a new associative table that relates the two original tables together. Copy the primary key from both original tables to the new associative tableRule 7: For aggregation and association relationships of mixed type, copy the primary key from the single-valued side (1..1 or 0..1) of the relationship to a new column in the table on the multi-valued side (1..* or 0..*) of the relationship that can store the key ofthe related tableRule 8a: Ensure that the primary key of the subclass instance is the same as the primary key of the superclass..

ORRule 8b: Flatten the inheritance

Page 30: Chapter 11 Data Management Layer Design

Slide 30

Mapping RDBMS Tables to Problem Domain Classes

Page 31: Chapter 11 Data Management Layer Design

Slide 31

Optimize RDBMS Object Storage

No redundant dataWastes spaceAllow more room for error

Few null values in tablesDifficult to interpret

Page 32: Chapter 11 Data Management Layer Design

Slide 32

Example of Non-normalized Data

Page 33: Chapter 11 Data Management Layer Design

Slide 33

Normalization

Page 34: Chapter 11 Data Management Layer Design

Slide 34

Normalization ExampleOriginal Model

Page 35: Chapter 11 Data Management Layer Design

Slide 35

3NF Normalized Model

Page 36: Chapter 11 Data Management Layer Design

Slide 36

Problems with RDBMS

To access data in multiple tables, the tables must be joinedThis can result in many database operations and lead to huge tables and slow processing

Page 37: Chapter 11 Data Management Layer Design

Slide 37

Speeding up access

Denormalization – Adds data from one table to another in order to speed processing and eliminate a join operationExample: Add customer last name to order table to avoid joining order to customer to get just last name

Page 38: Chapter 11 Data Management Layer Design

Slide 38

Example

Page 39: Chapter 11 Data Management Layer Design

Slide 39

Denormalization Candidates

Lookup Tablesone-to-one relationshipsinclude a parent entity’s attributes in its child entity on the physical data model

Page 40: Chapter 11 Data Management Layer Design

Slide 40

Clustering

Interfile clustering Arrange records on storage media so that similar records are stored close togetherinter-file cluster would be similar to storing peanut butter, jelly, and bread next to each other in a grocery store since they are often purchased together.

Page 41: Chapter 11 Data Management Layer Design

Slide 41

IndexingAn index in data storage is like an index in the back of a textbook; it is a mini table that contains values from one or more columns in a table and the location of the values within the table.A query can use an index to find the locations of only those records that are included in the query answer, and a table can have an unlimited number of indexes but too many can add overhead

Page 42: Chapter 11 Data Management Layer Design

Slide 42

Indexing Example

Page 43: Chapter 11 Data Management Layer Design

Slide 43

Estimating Data Storage Size

sum the values of the average width of each column (field) to find total record sizeAdd overhead (vendor may provide an estimate)Estimate the number of records you plan to have in the database

Page 44: Chapter 11 Data Management Layer Design

Slide 44

Data Sizing Example

Page 45: Chapter 11 Data Management Layer Design

Slide 45

DESIGNING DATA ACCESS AND MANIPULATION CLASSES

Design data access and manipulation classesPrevent data management functionality from creeping into the problem domain classes

Page 46: Chapter 11 Data Management Layer Design

Slide 46

Mapping PD Objects

Page 47: Chapter 11 Data Management Layer Design

Slide 47

CD Selections Example

Most of the data would be text and numbers Thus a relational database would be able to handle the data effectivelyHowever, images for the catalog require complex data objects for sound and video

Page 48: Chapter 11 Data Management Layer Design

Slide 48

Looking at the Data Needs

Page 49: Chapter 11 Data Management Layer Design

Slide 49

Object Persistent Design

Page 50: Chapter 11 Data Management Layer Design

Slide 50

Optimizing Application

Page 51: Chapter 11 Data Management Layer Design

Slide 51

Problem Domain Layer

Page 52: Chapter 11 Data Management Layer Design

Slide 52

SummaryChoose an object-persistent format

Files (sequential or Random Access)Databases (RDBMS, ORDBMS, OODBMS)

Map problem domain objects to DataOptimizing object storage

NormalizationDenormalization, clustering, Indexes

Design Data Access and Manipulation Classes