25
Association Relationship Association Relationship Transformation of XML Transformation of XML Schemas to Object–Relational Schemas to Object–Relational Databases Databases Nathalia Devina Widjaya, David Nathalia Devina Widjaya, David Taniar Taniar Wenny Rahayu, Eric Pardede Wenny Rahayu, Eric Pardede Bandung, 11 September Bandung, 11 September 2002 2002

Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

Embed Size (px)

Citation preview

Page 1: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

Association Relationship Association Relationship

Transformation of XML Schemas to Transformation of XML Schemas to

Object–Relational DatabasesObject–Relational Databases

Nathalia Devina Widjaya, David TaniarNathalia Devina Widjaya, David Taniar

Wenny Rahayu, Eric PardedeWenny Rahayu, Eric Pardede

Bandung, 11 September 2002Bandung, 11 September 2002

Page 2: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

Structure of PresentationStructure of Presentation

BackgroundBackground

ObjectivesObjectives

Association RelationshipAssociation Relationship

Related WorkRelated Work

Proposed Transformation MethodologyProposed Transformation Methodology

Conclusion and Future WorkConclusion and Future Work

Page 3: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

BackgroundBackground

The popularity of XML is growing and is gradually accepted as the The popularity of XML is growing and is gradually accepted as the

standard for describing and interchanging data between various standard for describing and interchanging data between various

systems and databases on the Internetsystems and databases on the Internet

XML now offers XML Schema definition language as a substitution XML now offers XML Schema definition language as a substitution

of DTD. It provides richer facilities for defining and constraining the of DTD. It provides richer facilities for defining and constraining the

content of XML documentscontent of XML documents

With the wide acceptance of the OO conceptual models, more With the wide acceptance of the OO conceptual models, more

systems are modeled and expressed with OO notation. This systems are modeled and expressed with OO notation. This

situation suggests the necessity to integrate the OO conceptual situation suggests the necessity to integrate the OO conceptual

models and XML.models and XML.

Page 4: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

ObjectivesObjectives

The goal of this work is to present a coherent way to transform the The goal of this work is to present a coherent way to transform the

XML schema into ORDB using Oracle 9XML schema into ORDB using Oracle 9i i features modelsfeatures models

This transformation is important so that all the data that are created This transformation is important so that all the data that are created

using XML schema can be transformed to the database using using XML schema can be transformed to the database using

Oracle format and features, without eliminating the object relational Oracle format and features, without eliminating the object relational

featuresfeatures

XML Schema ORDB (Oracle 9i) Translator

Page 5: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

Objectives (2)Objectives (2) The emphasis of this paper is on the transformation of The emphasis of this paper is on the transformation of association association

relationshiprelationship to help people conveniently generate Oracle database to help people conveniently generate Oracle database

The work presented in this paper is actually part of a larger The work presented in this paper is actually part of a larger

research project on research project on Transformation from XML Schema to Object-Transformation from XML Schema to Object-

Relational Databases.Relational Databases.

(i)(i) transformation of aggregation and inheritance relationship from transformation of aggregation and inheritance relationship from

XML Schema to ORDBXML Schema to ORDB

(ii)(ii) transformation of association relationship from XML Schema transformation of association relationship from XML Schema

to ORDBto ORDB

Page 6: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

Association RelationshipAssociation Relationship ORDB was introduced to improve RDB performance and has ORDB was introduced to improve RDB performance and has

become popular because it improves the limitations of RDB such as become popular because it improves the limitations of RDB such as

lack of support for new types and composite data valueslack of support for new types and composite data values

Since ORDB has OO features, it encapsulates the static (including Since ORDB has OO features, it encapsulates the static (including

association relationship) as well as dynamic aspects of objectsassociation relationship) as well as dynamic aspects of objects

The The associationassociation relationship represents a “connection” between relationship represents a “connection” between

object instances. Basically, it is a reference from one object to object instances. Basically, it is a reference from one object to

another that provides access paths among objects in a system. another that provides access paths among objects in a system.

The objects are connected through an association link. The link can The objects are connected through an association link. The link can

have a specified cardinality: one-to-one, one-to-many, many-to-have a specified cardinality: one-to-one, one-to-many, many-to-

manymany

Page 7: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

Related WorkRelated Work Most existing work has focused on methods to map RDB to an XML Most existing work has focused on methods to map RDB to an XML

database for database interoperability. Some works still used DTD database for database interoperability. Some works still used DTD

and some have used XML schema. and some have used XML schema.

The previous works include mapping referential integrity constraints The previous works include mapping referential integrity constraints

from RDB to XML, semantic data modeling using XML schemas, from RDB to XML, semantic data modeling using XML schemas,

hybrid database schema to map a subset of XML documents onto hybrid database schema to map a subset of XML documents onto

database structures, generic-transforming rules from the OOCM to database structures, generic-transforming rules from the OOCM to

XML schema, etc.XML schema, etc.

The transformation of generalization and aggregation relationship The transformation of generalization and aggregation relationship

from the XML Schema to ORDB has been done earlier as a first part from the XML Schema to ORDB has been done earlier as a first part

of the projectof the project

Page 8: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

Proposed Transformation Proposed Transformation MethodologyMethodology

There are 3 parts of association relationships that will be There are 3 parts of association relationships that will be

transformed, one-to-one association, one-to-many association and transformed, one-to-one association, one-to-many association and

many-to-many associationmany-to-many association

The method that we use to implement the association relationship in The method that we use to implement the association relationship in

Oracle is using Oracle is using object referencesobject references ( (REFREF). Instead of connecting two ). Instead of connecting two

tables through the values of the associated primary key and foreign tables through the values of the associated primary key and foreign

key, this method allows one to directly connecting two tables key, this method allows one to directly connecting two tables

through referencing attributethrough referencing attribute

Page 9: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

One-to-One RelationshipOne-to-One Relationship

The example that is used in this section is the relationship between The example that is used in this section is the relationship between

lecturer and officelecturer and office

For one-to-one association relationship, it is important to determine For one-to-one association relationship, it is important to determine

the participation of the objects to decide location of the foreign keys the participation of the objects to decide location of the foreign keys

in relational systemin relational system

Lecturer Office 1 has 1 HAS1 1

Page 10: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

One-to-One RelationshipOne-to-One Relationship (2) (2)

The Transformation steps:The Transformation steps:

1.1. From the XML Schema, element with partial participation will From the XML Schema, element with partial participation will

be recognized by statement minOccurs =”0” maxOccurs =”1” . be recognized by statement minOccurs =”0” maxOccurs =”1” .

First, create an object for the one with partial participation First, create an object for the one with partial participation

(office) with its attributes(office) with its attributes

……<complexType><complexType><sequence><sequence><element ref=”office” minOccurs=”0” maxOccurs= “1” /><element ref=”office” minOccurs=”0” maxOccurs= “1” /><element ref=”lecture” minOccurs=”0” maxOccurs=“unbounded”/><element ref=”lecture” minOccurs=”0” maxOccurs=“unbounded”/></sequence></sequence>……

Page 11: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

One-to-One RelationshipOne-to-One Relationship (3) (3)

……</element></element><element name = “office”> <element name = “office”> <attribute name = “officeid” type = “string” use = “required”/><attribute name = “officeid” type = “string” use = “required”/></element>…</element>…

CREATE OR REPLACE TYPE Office_T AS OBJECTCREATE OR REPLACE TYPE Office_T AS OBJECT (office_id(office_id VARCHAR2(10));VARCHAR2(10));

Page 12: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

One-to-One RelationshipOne-to-One Relationship (4) (4)

2.2. Create another object for the one with total participation, Create another object for the one with total participation,

lecture, with the attributes and a REF that refers to office typelecture, with the attributes and a REF that refers to office type

<element name = “lecture”><element name = “lecture”>……<attribute name = “lectureid” type = “string” use = “required” /><attribute name = “lectureid” type = “string” use = “required” /><attribute name = “lectureName” type = “string” use = “optional” />…<attribute name = “lectureName” type = “string” use = “optional” />…

CREATE OR REPLACE TYPE Lecture_T AS OBJECTCREATE OR REPLACE TYPE Lecture_T AS OBJECT (lecture_id(lecture_id VARCHAR2 (10),VARCHAR2 (10), lecture_namelecture_name VARCHAR2 (50),VARCHAR2 (50), lecture_officelecture_office REF office_T)REF office_T)

Page 13: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

One-to-One RelationshipOne-to-One Relationship (5) (5)

3.3. Lastly, we create one table for ‘Lecture’ and another one for Lastly, we create one table for ‘Lecture’ and another one for

‘Office’. Each table has its id as well as the constraints‘Office’. Each table has its id as well as the constraints

CREATE TABLE Office OF Office_TCREATE TABLE Office OF Office_T

(office_id NOT NULL,(office_id NOT NULL,

PRIMARY KEY (office_id));PRIMARY KEY (office_id));

CREATE TABLE Lecture OF Lecture_TCREATE TABLE Lecture OF Lecture_T

(lecture_id NOT NULL, (lecture_id NOT NULL,

PRIMARY KEY (lecture_id));PRIMARY KEY (lecture_id));

Page 14: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

One-to-Many RelationshipOne-to-Many Relationship

The example that is used in this section is the relationship between The example that is used in this section is the relationship between

customer and ordercustomer and order

Customer Order 1 has * HAS1 *

Page 15: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

One-to-Many Relationship (2)One-to-Many Relationship (2) The Transformation steps:The Transformation steps:

1.1. An element with a complex type in XML Schema, which does An element with a complex type in XML Schema, which does

not have reference inside it, is transformed by creating an not have reference inside it, is transformed by creating an

object in ORDB with all the attributesobject in ORDB with all the attributes

<xs:element name = “customer” type = “customerType” / ><xs:element name = “customer” type = “customerType” / >……<xs:complexType name = “customerType”><xs:complexType name = “customerType”>……</xs:complexType></xs:complexType>

Page 16: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

One-to-Many Relationship (3)One-to-Many Relationship (3)

<xs:complexType name = “customerType”><xs:complexType name = “customerType”><xs:attribute name = “customerName” type=“xs:string”/><xs:attribute name = “customerName” type=“xs:string”/><xs:attribute name = “shippingAddress” type=”xs:string”/><xs:attribute name = “shippingAddress” type=”xs:string”/><xs:attribute name = “shippingCity” type=”xs:string”/><xs:attribute name = “shippingCity” type=”xs:string”/><xs:attribute name = “shippingState” type=”xs:string”/><xs:attribute name = “shippingState” type=”xs:string”/><xs:attribute name = “shippingPostalCode” <xs:attribute name = “shippingPostalCode” type=”xs:integer”/>type=”xs:integer”/></xs:complexType>…</xs:complexType>…

CREATE OR REPLACE TYPE Customer_T AS OBJECTCREATE OR REPLACE TYPE Customer_T AS OBJECT (customer_id(customer_id VARCHAR2 (10),VARCHAR2 (10), customer_namecustomer_name VARCHAR2 (50),VARCHAR2 (50), shipping_addressshipping_address VARCHAR2 (100),VARCHAR2 (100), shipping_cityshipping_city VARCHAR2 (20),VARCHAR2 (20), shipping_stateshipping_state VARCHAR2 (20),VARCHAR2 (20), shipping_postalcodeshipping_postalcode NUMBER)NUMBER)

Page 17: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

One-to-Many RelationshipOne-to-Many Relationship (4) (4)

2.2. For another element in the complex type that has reference to For another element in the complex type that has reference to

another element, create another object and write all the another element, create another object and write all the

attributes. The minOccurs = “1” and maxOccurs = attributes. The minOccurs = “1” and maxOccurs =

“unbounded” in XML will be shown by using REF in Oracle“unbounded” in XML will be shown by using REF in Oracle

……

<xs:sequence><xs:sequence>

<xs:element name = “order” type= “ orderType” <xs:element name = “order” type= “ orderType”

minOccurs= “1” max Occurs = “unbounded” / >minOccurs= “1” max Occurs = “unbounded” / >

……

<xs:complexType name = “orderType”><xs:complexType name = “orderType”>

……

Page 18: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

One-to-Many Relationship (5)One-to-Many Relationship (5)

……

<xs:complexType name = “orderType”><xs:complexType name = “orderType”>

<xs:attribute name =”orderID” type=”xs:integer”/><xs:attribute name =”orderID” type=”xs:integer”/>

<xs:attribute name = “orderDate” type= “xs:date”/><xs:attribute name = “orderDate” type= “xs:date”/>

</xs:complexType></xs:complexType>

CREATE OR REPLACE TYPE Order_T AS OBJECTCREATE OR REPLACE TYPE Order_T AS OBJECT

(order_id(order_id VARCHAR2(10),VARCHAR2(10),

order_dateorder_date DATE,DATE,

order_customer order_customer REF Customer_T)REF Customer_T)

Page 19: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

One-to-Many RelationshipOne-to-Many Relationship (6) (6)

3.3. Lastly, create a table for each type. Each table has its id as Lastly, create a table for each type. Each table has its id as

well as the constraintswell as the constraints

CREATE TABLE Customer OF Customer_TCREATE TABLE Customer OF Customer_T

(customer_id (customer_id NOT NULL, NOT NULL,

PRIMARY KEY (customer_id));PRIMARY KEY (customer_id));

CREATE TABLE Order OF Order_TCREATE TABLE Order OF Order_T

(order_id (order_id NOTNULL,NOTNULL,

PRIMARY KEY (order_id));PRIMARY KEY (order_id));

Page 20: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

Many-to-Many RelationshipMany-to-Many Relationship

The example that is used is the relationship between student and The example that is used is the relationship between student and

coursecourse

Student Course 1 has * ENROLLS_IN* *

Page 21: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

Many-to-Many Relationship (2)Many-to-Many Relationship (2)

The Transformation steps:The Transformation steps:

1.1. All elements name that has minOccurs = “1” max Occurs = All elements name that has minOccurs = “1” max Occurs =

“unbounded” need to be created as object in ORDB and write “unbounded” need to be created as object in ORDB and write

all its attributesall its attributes

…… <xs:complexType><xs:complexType>

<xs:sequence><xs:sequence><xs:element name = “students” minOccurs =”1” maxOccurs =“unbounded”><xs:element name = “students” minOccurs =”1” maxOccurs =“unbounded”> <xs:complexType><xs:complexType> … …<xs:element name = “course” minOccurs =”1” maxOccurs = “unbounded”><xs:element name = “course” minOccurs =”1” maxOccurs = “unbounded”> <xs:complexType><xs:complexType> … …

Page 22: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

Many-to-Many Relationship (3)Many-to-Many Relationship (3)

<xs:element name = “student”>…<xs:element name = “student”>…<xs:attribute name =”refCourseID” type= “xs:string” />…<xs:attribute name =”refCourseID” type= “xs:string” />…<xs:attribute name = “studentid” type = “xs:string” />…<xs:attribute name = “studentid” type = “xs:string” />………<xs:element name = “course”>…<xs:element name = “course”>…<xs:attribute name =”refstudentID” type= “xs:string” />…<xs:attribute name =”refstudentID” type= “xs:string” />…<xs:attribute name = “courseid” type = “xs:string” />…<xs:attribute name = “courseid” type = “xs:string” />………

CREATE OR REPLACE TYPE Student_T AS ObjectCREATE OR REPLACE TYPE Student_T AS Object (student_id(student_id VARCHAR2 (10),VARCHAR2 (10), student_namestudent_name VARCHAR2(30))VARCHAR2(30))

CREATE OR REPLACE TYPE Course_T AS ObjectCREATE OR REPLACE TYPE Course_T AS Object (course_id(course_id VARCHAR2(10),VARCHAR2(10), course_namecourse_name VARCHAR2(30))VARCHAR2(30))

Page 23: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

Many-to-Many RelationshipMany-to-Many Relationship (4) (4)2.2. In the XML Schema, each element will be linked to another In the XML Schema, each element will be linked to another

element by using the attribute name that refers to another element by using the attribute name that refers to another

element ID. For those elements create table for each of them element ID. For those elements create table for each of them

in ORDB and add the constraints for the attributesin ORDB and add the constraints for the attributes

……<xs:attribute name =”refCourseID” type= “xs:string” />…<xs:attribute name =”refCourseID” type= “xs:string” />………<xs:attribute name =”refstudentID” type= “xs:string” />…<xs:attribute name =”refstudentID” type= “xs:string” />…

CREATE TABLE Student OF Student_TCREATE TABLE Student OF Student_T (student_id(student_id NOT NULL,NOT NULL, PRIMARY KEY(student_id));PRIMARY KEY(student_id));

CREATE TABLE Course OF Course_TCREATE TABLE Course OF Course_T (course_id(course_id NOT NULL,NOT NULL, PRIMARY KEY (order_id));PRIMARY KEY (order_id));

Page 24: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

Many-to-Many RelationshipMany-to-Many Relationship (5) (5)

3.3. Create another table to keep the relationship between the two Create another table to keep the relationship between the two

connected tables in ORDB. This table will have reference to connected tables in ORDB. This table will have reference to

the participating objectsthe participating objects

CREATE TABLE Enrolls_in CREATE TABLE Enrolls_in

(student(student REF Student_T,REF Student_T,

coursecourse REF Course_T);REF Course_T);

Page 25: Association Relationship Transformation of XML Schemas to Object–Relational Databases Nathalia Devina Widjaya, David Taniar Wenny Rahayu, Eric Pardede

Conclusion and Future WorkConclusion and Future Work

In this paper, we have investigated the transformation from XML In this paper, we have investigated the transformation from XML

schema to the ORDB by using Oracle 9schema to the ORDB by using Oracle 9 i, i, emphasis the transformation emphasis the transformation

of of association relationshipassociation relationship

This transformation is important because people tends to eliminate This transformation is important because people tends to eliminate

the object-oriented conceptual features when they transform XML the object-oriented conceptual features when they transform XML

schema to the database.schema to the database.

Our future work is being planned to investigate more transformation Our future work is being planned to investigate more transformation

from XML schema to ORDB for other XML Schema features that has from XML schema to ORDB for other XML Schema features that has

not been discussed in this paper. Further research should be done to not been discussed in this paper. Further research should be done to

create a query from XML schema to get the data from the Oracle 9create a query from XML schema to get the data from the Oracle 9 ii

databasesdatabases