persistency (4)
TRANSCRIPT
-
8/3/2019 Persistency (4)
1/24
Development Methodologies
Mapping Design Models to the Data Layer
-
8/3/2019 Persistency (4)
2/24
Data Layer
The general goal of an object-oriented design is tomodel a business process or set of processes
The goal of a data layer design is to model the
business data Typically a relational database
Mapping from system objects to data entities can bedifficult if the system contains
Complex class structure Large unstructured objects
Object inheritance
-
8/3/2019 Persistency (4)
3/24
Using Databases
3 approaches have been developed for the
management of the object storage:
Object relational mapping
ORDBMS
OODBMS
-
8/3/2019 Persistency (4)
4/24
Object Relational mapping
Most business database application use
relational databases
Need to map object in the database to tables
in the database
The mapping needs to be carefully considered
to allow data to be represented and accessed
as efficiently as possible
-
8/3/2019 Persistency (4)
5/24
RDBMS terminology
A relational database can contain one or manytables.
Tables make up the basic storage structure of arelational database management system.
A table holds the data about something in thereal world, such as employees, departments, orsalaries
A single row, or record, represents all data for a
particular employee. The order of rows stored ina table is insignificant. You can specify an orderwhen you retrieve data from a table.
-
8/3/2019 Persistency (4)
6/24
The class model
Artefact produced to represent the logical
structure of a system.
It captures both the data requirement and the
behaviour of the objects.
Behaviour is captured using the operations
that are defined for the class.
-
8/3/2019 Persistency (4)
7/24
Object-oriented Principles
Abstraction: indicates the process of identifying theessential aspects of an entity. Typically it relates to
Identifying an object
And what it does
Then deciding if it should be implemented
Encapsulation: An object contains both the datastructure and the set of operations which can beused to manipulate it
Information Hiding : External aspects of an objectare separated from its Internal details (these arehidden from the outside world)
-
8/3/2019 Persistency (4)
8/24
Relationship
Association : relationship between 2 classes.
The relationship may be functional or
structural
Aggregation: form of association that implies
Inheritance: a means of factoring out
common behaviour into generalised classes
-
8/3/2019 Persistency (4)
9/24
-
8/3/2019 Persistency (4)
10/24
-
8/3/2019 Persistency (4)
11/24
UML data profile
Table
column
-
8/3/2019 Persistency (4)
12/24
Stereotyped operations
Behaviour is represented as stereotypedoperations:
A primary key constraint (PK);
A Foreign key constraint (FK);
An index constraint (Index); A trigger (Trigger);
A uniqueness constraint (Unique);
A stored procedure (Proc) - not formally part of the dataprofile, but an example of a possible modellingtechnique; and a
Validity check (Check).
-
8/3/2019 Persistency (4)
13/24
-
8/3/2019 Persistency (4)
14/24
-
8/3/2019 Persistency (4)
15/24
Class model to Relational model
Step 1: Model classes
Step 2:
Identify persistent objects Step3:
Assume each persistent class maps to onerelational table
Step4: Map attributes to columns
Not all attributes are persistent
-
8/3/2019 Persistency (4)
16/24
Class model to Relational model
-
8/3/2019 Persistency (4)
17/24
Step 5:
Select an inheritance strategy
Filtered mapping
Each class hierarchy has a single corresponding table thatcontains all the inherited attributes for all elements - this table is
therefore the union of every class in the hierarchy
Horizontal mapping
Each class in the hierarchy has a corresponding table of only the
attributes accessible by that class (including inherited attributes). Vertical mapping
Each generation in the class hierarchy has a table containing only
that generation's actual attributes.
Class model to Relational model
-
8/3/2019 Persistency (4)
18/24
Step 6:
For each class add a unique object identifier
It is often more convenient to implement absolute
identity using OID's rather than business related
primary keys
Class model to Relational model
-
8/3/2019 Persistency (4)
19/24
Step 7a:
Map associations to foreign keys
Each association in the class model create a foreign key
from the child to the parent table
Class model to Relational model
-
8/3/2019 Persistency (4)
20/24
Step 7b:
Map Aggregation and Composition
A weak aggregation could be implemented using
either an intermediate table (for the many-to-many case)
a foreign key in the aggregated class/table (one-to-many case). In the case of the many-to-many relationship, if the parent is
deleted, the entries in the intermediate table for that entity mustalso be deleted also. In the case of the one-to-many relationship, ifthe parent is deleted, the foreign key entry (ie. 'owner') must becleared.
In the case of composition, the use of a foreign key is mandatory,with the added constraint that on deletion of the parent the partmust be deleted also
Class model to Relational model
-
8/3/2019 Persistency (4)
21/24
Step 8:
Model behaviour
Issue: Should one map some or all class behaviour to
the functional capabilities provided by databasevendors in the form of triggers, stored procedures,
uniqueness and data constraints, and relational
integrity.
Class model to Relational model
-
8/3/2019 Persistency (4)
22/24
Relational Database Issues
Because the relational model is simple, relational
databases ...
have a "simple" formal model and semantics
support data independence (physical & logical)
have good ad-hoc query facilities
have good storage management facilities: recovery;backup
etc.
good concurrency
are fast and efficient
-
8/3/2019 Persistency (4)
23/24
Relational Database Issues contd.
But when building application
data in the application does not map well to table
heterogeneous collections
only fixed number of built-in types is available
It is not possible to represent/manipulate complex entities
as a single unit
The business rules and logical rules are written as
independent procedures, functions or triggers.
-
8/3/2019 Persistency (4)
24/24
Further Considerations
Manual ORM process outlined to date
Existing libraries/techniques for ORM
Hibernate / Nhibernate
QuickDB Orm
Service Data Objects