Lecture 6
Lecture 6
2008/2/19 1
Data conversion: Customerized Program Approach
Definitions of
source, target,
and mapping
Interpretive
source target
transformer
2008/2/19 3
Interpretive transformer
For instance, the following Cobol structure
Level 0 PERSON
3 LIC# 2
NAME
2008/2/19 4
To translate the above three levels to the following two levels data structure:
Level 0 PERSON
Translator
generator
Specialized
source target
program
Convert
catalog
CONVERT PL/1
program Restructurer Procedure
(CONVERT)
Statement 1 compiler phase COP 1
Statement 2 COP 2
: DEFINE :
: Compiler :
CONVERT Execution
Catalogue Schedule
2008/2/19 7
As an example, consider the following hierarchical database:
ITEMNO DESC
2008/2/19 8
Its DEFINE statements can be described in the following where
for each DEFINE statement, a code is generated to allocate a
new subtree in the internal buffer.
GROUP DEPT:
OCCURS FROM 1 TIMES;
FOLLOWED BY EOF;
PRECEDED BY HEX ‘01’;
:
END EMP;
GROUP PROJ:
OCCURS FROM 0 TIMES;
PRECEDED BY HEX ‘03’;
:
END PROJ;
2008/2/19 9
END DEPT;
For each user-written CONVERT statement, we can produce a customized
program. Take the DEPT FORM from the above DEFINE statement:
Lu?c d? Lu?c d?
quan h? quan h?
ngu?n dích
L? a ch?n?
Business requirements
A company has two regions A and B.
•Each region forms its own departments.
•Each department approves many trips in a year.
•Each staff makes many trips in a year.
•In each trip, a staff needs to hire cars for
transportation.
•Each hired car can carry many staff for each trip.
•A2008/2/19
staff can be either a manager or an engineer. 12
Data Requirements
Where ID = Inclusion Dependence, Underlined are primary keys and “*” prefixed are foreign keys.
2008/2/19 13
Extended Entity Relationship Model for database Trip
Department_id
Department_id
Classification Region_A Region_B
Classification
Department_id
Department Salary
1
R1
m
Trip Trip_id
m
R2
1
Staff_id Car_model
Name People
m Assignment n Car Size
DOB Description
2008/2/19
Staff_id Staff_id 14
Manager Engineer
Title Title
Schema for target relational database Trip
Create Table Car
(CAR_MODEL character (10),
SIZE character (10),
DESCRIPT character (20),
STAFF_ID character (5),
primary key (CAR_MODEL))
UPDATE trip_ora52.TRIP
SET DEPT_ID= 'AA001'
, CAR_MODEL= 'MZ-18 '
, STAFF_ID= 'B001'
, CAR_MODEL= 'MZ-18 '
, STAFF_ID= 'B001'
WHERE TRIP_ID='T0002'
UPDATE trip_ora52.TRIP
SET DEPT_ID= 'AB001'
, CAR_MODEL= 'SA-38 '
, STAFF_ID= 'A002'
, CAR_MODEL= 'SA-38 '
, STAFF_ID= 'A002'
WHERE TRIP_ID='T0003'
UPDATE trip_ora52.TRIP
SET DEPT_ID= 'BB001'
, CAR_MODEL= 'SA-38 '
, STAFF_ID= 'D002'
, CAR_MODEL= 'SA-38 '
2008/2/19 19
, STAFF_ID= 'D002'
WHERE TRIP_ID='T0004'
Data Integration
Step 1: Merge by Union
Relation Ra
A1 A2
Relation Rx
a11 a21
A1 A2 A3
a12 a22
a11 a21 null
a14 a32
2008/2/19 20
Step 2: Merge classes by
generalization
Relation Ra Relation Rx1
A1 A2 A1 A2 Relation Rx
a11 a21 a11 a21
A1 A2 A3
a12 a22 a12 a22
a11 a21 null
==> a12 a22
Relation Rb Relation Rx2 null
2008/2/19 21
Step 3: Merge classes by
inheritance
Relation Rb Relation Rxb
A1 A2 A1 A2 A3
==>
Relation Ra Relation Rxa
A1 A3 A1 A3
2008/2/19 22
Step 4 Merge classes by
aggregation
Relation Rx
Relation Ra Relation Rx’
Relation Rx1
A1 A2 A1 A3 A5 A1 A2 A1 A3 *A5
a11 a21 a11 a31 a11 a21
a51 a11 a31 a51
a12 a22 a12 a32 a51 a12 a22 a12 a32 a51
2008/2/19 23
Step 5 Merge classes by
categorization
Relation Ra Relation Ra
A1 A2 A1 A2
Relation Rx
a11 a21 a11 a21
A1 A4
a12 a22 a12 a22
a11 a41
2008/2/19 25
Step 7 Merge relationship by
Relation Ra
subtype
Relation Rb Relation Xa Relation Xc
A1 A2 A3 *A1 A1 A2 *A3 *A1
a11 a21 a31 a11 a11 a21 a31 a11
a12 a22 a32 a12 a12 a22 a32 a12
a33 null
2008/2/19 26
Data conversion from relational into XML
Step 3:
Data XML Document
Relational
Conversion
Databse
2008/2/19 27
Methodology of converting RDB into XML
2008/2/19 30
Step 2: Data Conversion from Relational into
XML document
2008/2/19 31
Step 2.1 Defining a Root Element
To select a root element, we must put its relevant
information into an XML schema. Relevance
concerns with the entities that are related to a
selected entity by the user. The relevant classes
include the selected entity and all its relevant entities
that are navigable.
2008/2/19 32
Entity A * *
1 1 * *
R1 R4 * Selected Entity
n *n
Entity B Entity E
1 1
1 1
R2
2008/2/19 R3 R5 R7 33
Step 2.1 Mapping Cardinality
from RDB to XML
A1 A1
Entity A Element A
A2 A2
1
1
Schema
B1 B1
Entity B Element B
B2 Translation B2
2008/2/19 36
One-to-many cardinality
EER Model DTD Graph
A1 A1
Entity A Element A
A2 A2
1
R *
n Schema
B1 Translation B1
Entity B Element B
B2 B2
2008/2/19 38
Many-to-many cardinality
EER Model DTD Graph
A1
Entity A
A2
R A1 B1
n A2 Element A Element R Element B B2
A_id B_id
B1
Entity B
B2 Schema A_idref B_idref
Translation DTD
<!ELEMENT A EMPTY>
<!ATTLIST A A1 CDATA #REQUIRED>
Relational Schema <!ATTLIST A A2 CDATA #REQUIRED>
<!ATTLIST A A_id ID #REQUIRED>
Relation A(A1, A2) <!ELEMENT R EMPTY>
Relation B(B1, B2) <!ATTLIST R A_idref IDREF #REQUIRED>
Relation R(*A1, *B1) <!ATTLIST R B_idref IDREF #REQUIRED>
<!ELEMENT B EMPTY>
<!ATTLIST B B1 CDATA #REQUIRED>
2008/2/19 <!ATTLIST B B2 CDATA #REQUIRED> 39
<!ATTLIST B B_id ID #REQUIRED>
Many-to-many cardinality
Relation A
A1 A2 XML Document
a11 a21
<A A1="a11" A2="a21" A_id="1"></A>
a12 a22
<B B1="b11" B2="b21" B_id="2"></B>
<R A_idref="1" B_idref="2"></R>
Relation B
B1 B2 Data
<A A1="a12" A2="a22" A_id="3"></A>
b11 b21 Conversion <B B1="b12" B2="b22" B_id="4"></B>
b12 b22 <R A_id="3" B_idref="4"></R>
2008/2/19 40
Case Study
Consider a case study of a Hospital Database
System. In this system, a patient can have
many record folders. Each record folder can
contain many different medical records of the
patient. A country has many patients. Once a
record folder is borrowed, a loan history is
created to record the details about it.
2008/2/19 41
Hospital Relational Schema
Relation Patient (HK_ID, Patient_Name)
Relation Record_Folder (Folder_No, Location, *HKID)
Relation Medical_Record (Medical_Rec_No,
Create_Date, Sub_Type, *Folder_No)
Relation Borrower (*Borrower_No, Borrower_Name)
Relation Borrow (*Borrower_No, *Folder_No)
2008/3/1 43
Borrower_Name Table Borrower_no Borrower_name
B1 Johnson
B11 Choy
B21 Fung
B22 Lok
2008/2/19 44
Step 1 Reverse engineer relational database into an EER model
Patient
belong
n
Medical n 1 Record
contain Borrower
Folder Folder
1 1
by has
n
m
Borrow
2008/2/19 45
Step 2 Translate EER model into
DTD Graph and DTD
In this case study, suppose we concern the
patient medical records, so the entity Patient is
selected. Then we define a meaningful name
for the root element, called Patient_Records.
We start from the entity Patient in the EER
model and then find the relevant entities for it.
The relevant entities include the related entities
that are navigable from the parent entity.
2008/2/19 46
Translated Document Type Definition Graph
Patient
Records
Patient
Record
Folder
* *
Medical
Borrow
Folder
Borrower
2008/2/19 47
Translated Document Type Definition
2008/3/1 48
Transformed XML document
Patient_Records>
<Patient Country_No="C0001" HKID="E3766849" Patient_Name="Smith">
<Record_Folder Folder_No="F_21" Location="Hong Kong">
<Borrow Borrower_No="B1">
<Borrower Borrower_name=“Johnson" />
</Borrow>
<Borrow Borrower_No="B11">
<Borrower Borrower_name=“Choy" />
</Borrow>
<Borrow Borrower_No="B21">
<Borrower Borrower_name=“Fung" />
</Borrow>
<Borrow Borrower_No="B22">
<Borrower Borrower_name=“Lok" />
</Borrow>
<Medical_Record Medical_Rec_No="M_311999" Create_Date="Jan-1-1999“, Sub_Type="W"></Medical_Record>
<Medical_Record Medical_Rec_No="M_322000" Create_Date="Nov-12-1998“, Sub_Type="W"></Medical_Record>
<Medical_Record Medical_Rec_No="M_352001" Create_Date="Jan-15-2001“, Sub_Type="A"></Medical_Record>
<Medical_Record Medical_Rec_No="M_362001" Create_Date="Feb-01-2001“, Sub_Type="A"></Medical_Record>
</Record_Folder>
<Record_Folder Folder_No="F_24" Location="New Territories">
<Borrow Borrower_No="B22">
<Borrower Borrower_name=“Lok" />
</Borrow>
<Medical_Record Medical_Rec_No="M_333333" Create_Date="Mar-03-01“, Sub_Type="A"></Medical_Record>
</Record_Folder>
</Patient>
2008/2/19 49
Reading Assignment
Chapter 4 Data Conversion of “Information
Systems Reengineering and Integration”
by Joseph Fong, Springer Verlag, pp.160-
198.
2008/2/19 50
Lecture review question 6
How do you compare the pros and cons of
using “Logical Level Translation Approach”
with “Customized Program Approach” in
data conversion?
2008/2/19 51
CS5483 Tutorial Question 6
Convert the following relational database into an XML document:
Relation Car_rental
Car_model Staff_ID *Trip_ID
MZ-18 A002 T0001
MZ-18 B001 T0002
R-023 B004 T0001
R-023 C001 T0004
SA-38 A001 T0003
SA-38 A002 T0001
Relation Trip
Trip_ID *Department_ID
T0001 AA001
T0002 AA001
T0003 AB001
T0004 BA001
Relation Department
Department_ID Salary
AA001 35670
AB001 30010
BA001 22500
2008/3/1 52