Transcript Chapter 4

Chapter 13
Application Design III:
Database & Persistence
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
Chapter Topics












Concepts of data and data management.
Database management systems.
The relational model and its major components.
Database mechanisms that safeguard data
integrity.
SQL, the database management language.
Encapsulating data management: views, stored
procedures and triggers.
The concept and the rules of data normalization.
Intersection tables and the issues they address.
Lookup tables.
The entity-relation diagram (ERD).
Mapping to relational databases.
Persistence layer and serialization.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 2
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 3
Data Management

Data management is the joint responsibility
of Applications and the Database
Management System.

Persistence objects are specialized for
communicating with the database, the
same way that user-interface objects
communicate with the users.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 4
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 5
Data and Data Management

Data are values of variables. In an objectoriented approach, variables belong either
to objects or to the messages that the
objects exchange with each other and with
the outside world.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 6
Attributes of Data

Data are highly abstract values, but they
can be classified in relation to each other
and to their contexts:




Data
Data
Data
Data
can
can
can
can
be quantitative or qualitative.
be discrete or continuous.
be categorical or non-categorical.
be structured or unstructured.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 7
The Context of Data

Data is meaningful only within the context
of a variable, and a variable is meaningful
only within the context of an object.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 8
Data Management

Data management is storing and
organizing data in a manner that can
satisfy the needs of the information system
and its applications.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 9
The Database


A database is an organized collection of data.
A data management system must be able to carry out the
following operations:
Create: accept new data and create entries in
the database.
 Retrieve: find and read the data that the
information system and its users require.
 Update: allow existing data to be changed.
 Delete: permit unneeded data to be removed.


 These four operations are often referred to as CRUD:
Create, Retrieve, Update and Delete.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 10
Interface and Language

A database has an interface that is distinct
from other components of the information
systems. A specialized language is required
to access this interface.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 11
Integrity and Security

A data management system must guard
data against unintentional errors and
intentional sabotage or theft.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 12
The Database Management System (DBMS)

Database management systems are
products that encapsulate and carry out
the responsibilities of data management.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 13
Sequential Access

Sequential access is a method in which
data is grouped in records that are stored
and retrieved serially from beginning to
end.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 14
Early DBMSs

Early database management systems
required the applications to know the
physical layout of data.

The Network Model. this model was based on
the following definition of a database:
 a database is a collection of files
 a file is an ordered collection of entries
 an entry consists of key or keys and data.

The Hierarchical Model. In the hierarchical
model, data records are organized as master
and detail collections.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 15
The Relational Database Management System
(RDBMS)

The relational model presents a logical
view of the database organization and
provides the basis for using a high-level
language for database management.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 16
Object-Oriented Database Management
Systems

An object-oriented database management
system (OODBMS) aims to make
persistence transparent to object-oriented
languages.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 17
The Relational Model

A table is the basic organizational unit of a
relational database.

A table is a rectangular arrangement of
data, composed of columns and rows. A
column is also referred to as an attribute, a
row as a tuple, and their intersection as a
cell.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 18
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 19
The Primary Key

The primary key is an attribute or a set of
attributes whose values uniquely identify a
row.

A key that consists of more than one
column is called a composite key.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 20
The Foreign Key
The foreign key is an attribute in one table
whose value must match the value of a
primary or an alternate key in a different
table.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 21
Data Integrity

A relational database management system
protects data integrity at four levels:
column, row, inter-table and procedural.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 22
Integrity

Attribute integrity is ensured by type definition,
constraints and foreign keys.

Entity integrity is assured by the primary key.

Referential integrity is safeguarding inter-table
references established by foreign keys.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 23
SQL

SQL is the primary language for
communication with relational database
management systems.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 24
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 25

A view is a virtual table that represents a selected
set of attributes from one or more tables
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 26

A stored procedure is a named set of SQL statements that
provides the capability of performing database-related tasks
from within the database itself.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 27
Data Normalization
Normalization is the process of establishing
an optimal table structure based on the
internal data dependencies.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 28
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 29
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 30
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 31
Denormalization

Denormalization might become necessary
due to logical considerations, technological
constraints and performance degradation.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 32
Intersection Tables

An intersection table represents the
relationship between two different entities.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 33
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 34

A self-referencing relationship occurs when two or more
entities of the same kind are related.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 35

Lookup tables represent a range of valid values.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 36
Modeling the Relational Database

The main modeling tool for modeling a
relational database is the EntityRelationship diagram.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 37
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 38
Mapping to Relational Databases

Mapping to a relational database is the
application of relational and normalization
rules to classes and their relationships.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 39
Designing Persistence

Classes.


Attributes


Associations are mapped by a primary-foreign key pairs.
Multiplicity


Repeating attributes must be separated into tables.
Associations


A table must have a primary key.
Repeating Attributes


Class attributes become table attributes (or columns.)
The Primary Key


Entity classes form the overwhelming majority of tables.
Multiplicity is mapped through foreign keys.
Aggregation

To map to a relational database, aggregation must be flattened
into association.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 40

Self-Referencing Aggregation. This pattern, with
many-to-many multiplicity, is very common and must
be solved through an intersection table in the
database.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 41
Inheritance and Aggregation.

Class is an aggregate of
Student and Teacher, but it
also inherits features from
Course and Semester. In
the database, the
relationships are mapped
to the Classes table by one
foreign key for each
relationship.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 42
The Persistence Layer

The persistence layer is a set of
components that manage the
communication between the application
and the DBMS.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 43
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 44
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 45
Next: Patterns



Patterns are how we can learn from other people’s
experience.
A pattern is not a recipe that can be followed
uncritically, or a general-purpose theory from
which specific solutions can be derived, but the
core of the solution to a problem that is
encountered repeatedly.
In simple terms, patterns help us to build wheels
without reinventing them.
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 46
All rights reserved. No part of this publication may be reproduced, stored in a
retrieval system, or transmitted, in any form or by any means, electronic,
mechanical, photocopying, recording, or otherwise, without the prior written
permission of the publisher. Printed in the United States of America.
Copyright © 2009 Pearson Education, Inc.
Publishing as Prentice Hall
© 2009 Pearson Education, Inc. Publishing as Prentice Hall
13- 47