Upload
tanith
View
49
Download
1
Tags:
Embed Size (px)
DESCRIPTION
OODB and XML. Database Management Systems – Fall 2012. Matthew Moccaro. Outline. 1. OODB. 2. OODB AND SQL. 3. XML. 4. XML Queries. Object Databases. Object Databases. Object Databases. A History. First arrived in the 1980s and 1990s Use objects to represent data with a set of - PowerPoint PPT Presentation
Citation preview
Company
LOGO
OODB and XML
Database Management Systems – Fall 2012
Matthew Moccaro
Outline
1. OODB
2. OODB AND SQL
3. XML
4. XML Queries
Object Databases
Object Databases
Object Databases
A History
• First arrived in the 1980s and 1990s• Use objects to represent data with a set of
attributes. • Developed due to certain limitations of the
very popular relational model.
Let’s take a look at an example of one ofthese limitations.
Limitations Example: Part 1
SSN Name PhoneN Child
111-22-3333 Joe Public 516-123-4567 222-33-4444
111-22-3333 Joe Public 516-345-6789 222-33-4444
111-22-3333 Joe Public 516-123-4567 333-44-5555
111-22-3333 Joe Public 516-345-6789 333-44-5555
222-33-4444 Bob Public 212-987-6543 444-55-6666
222-33-4444 Bob Public 212-987-1111 555-66-7777
222-33-4444 Bob Public 212-987-6543 555-66-7777
222-33-4444 Bob Public 212-987-1111 444-55-6666
Limitations Example: Part 2
SSN Name PhoneN Child
111-22-3333 Joe Public 516-123-4567 222-33-4444
111-22-3333 Joe Public 516-345-6789 222-33-4444
111-22-3333 Joe Public 516-123-4567 333-44-5555
111-22-3333 Joe Public 516-345-6789 333-44-5555
222-33-4444 Bob Public 212-987-6543 444-55-6666
222-33-4444 Bob Public 212-987-1111 555-66-7777
222-33-4444 Bob Public 212-987-6543 555-66-7777
222-33-4444 Bob Public 212-987-1111 444-55-6666
Limitations Example: Part 3
Explanation
• There are several ways around this problem,however, they normally lead to more difficulties.
• More tables, more complex queries.
Our solution can be an OODB. To help explain an object database, let’s compare it to something we are familiar with, the relational model.
Object Vs. Relational: Part 1
Object Database Relational Database
Contains Classes
which are:
Sets of Objects
Contains Relations
which are:
Sets of Tuples
Object Vs. Relational: Part 2
Object Database Relational Database
Components ofan object can be complex types.
Sets, Tuples, Objects…..
Components of a tuple must be primitive types.
Strings, Integers…
Object Vs. Relational: Part 3
Object Database Relational Database
• Objects can have inheritance.
• Objects can have methods.
• Can be all in the same language.
N/A
OODB
TEXT TEXT
The Conceptual Object Data Model
• Helps us to understand OODB.
• Let’s take a better look at:
• Objects• Classes• Types
The Conceptual Object Data Model
TEXT TEXT
Objects
• In this model, each object has an individual ID.• Called an “oid”• Different from a Primary Key• Cannot change for an object
• Values• Can Change• Can be complex
The Conceptual Object Data Model
TEXT TEXT
Classes
• Organizes similar objects• Class called Person contains objects with information regarding each person.
• Classes Have:• Type• Method Signatures• Extent
The Conceptual Object Data Model
TEXT TEXT
Types
• Types could be:• Basic• Reference• Tuple• Set
• Subtype and Supertype
Object-Relational Database
Object Relational Database
Combination of Object and Relational Databases
• Top Level Classes which contain tuples.• These classes are called “relations.”
Tuples are “tuple objects.”
• Top level structure is always a tuple.• Can have complex values.
Object Databases
Object Databases and SQL
Object Databases
A History
• First added to SQL in SQL:1999
• Created with backwards compatibility in mind.
• SQL-92
• Remained in SQL:2003, SQL:2008, and SQL:2011.
Row Type
A New Type
• To create a tuple type in SQL, we can now use the row keyword:
CREATE TABLE Person( Name CHAR(20), Address ROW(Number INTEGER, STREET CHAR(20), ZIP CHAR(5)))
To insert new values:
INSERT INTO Person(Name, Address)VALUES (‘John Doe’, ROW(666, ‘Hollow Rd.’, ‘66666’))
Creating Objects
Creating A Type
• To create an object in SQL, we need to go through a few steps.
1. First we can define a type.
CREATE TYPE StudentType AS( Address ROW(Number INTEGER, STREET CHAR(20), ZIP CHAR(5))) Id INTEGER, Status CHAR(2));
Creating Objects
Creating A Table
2. Next, we can create a new table from our type.
CREATE TABLE Student OF StudentType;
SQL regards the rows of a table declared in this way as objects.
The book introduces many other new concepts in this area.
XML
XML
XML
A History
• XML was first developed in the late 1990s andcame into popularity soon after.
• EXtensible Markup Language
• HTML displays data, XML carries data
• File Extension is .xml
Let’s create a file….
XML Example File
<?xml version=“1.0” encoding=“UTF-8” ?>
First, we can start by making an XML declaration…..
XML Example File
<?xml version=“1.0” encoding=“UTF-8” ?>
<!- - Written By: Matt - - >
Comments are done as <!-- Comment -->
XML Example File
<?xml version=“1.0” encoding=“UTF-8” ?>
<!- - Written By: Matt - - >
<menu> All elements must have an open</menu> and close tag. Close tags have a “/”
Let’s make a menu. So we’ll declare some menu tags.This is called the root element.
XML Example File
<?xml version=“1.0” encoding=“UTF-8” ?>
<!- - Written By: Matt - - >
<menu><entree></entree>
</menu>
Now let’s put an entrée section.
XML Example File
<?xml version=“1.0” encoding=“UTF-8” ?>
<!- - Written By: Matt - - >
<menu><entree>
<name>Sunburnt Chicken</name></entree>
</menu>
Let’s add some details. How about a name?
XML Example File
<?xml version=“1.0” encoding=“UTF-8” ?>
<!- - Written By: Matt - - >
<menu><entree>
<name>Sunburnt Chicken</name><fatgrams>23</fatgrams>
</entree></menu>
And a detail about this entrée.
XML Example File
<?xml version=“1.0” encoding=“UTF-8” ?>
<!- - Written By: Matt - - >
<menu><entree>
<name>Sunburnt Chicken</name><fatgrams>23</fatgrams>
</entree><entree>
<name>Gusto Spaghetti</name> <fatgrams>55</fatgrams></entree>
</menu>
Let’s add an entirely new entrée.
XML Example File
<?xml version=“1.0” encoding=“UTF-8” ?>
<!- - Written By: Matt - - >
<menu><entrée1>
<name>Sunburnt Chicken</name><fatgrams>23</fatgrams>
</entrée1><entrée2>
<name>Gusto Spaghetti</name> <fatgrams>55</fatgrams></entrée2>
</menu>
Attributes can help make things more clear. We could do this….
XML Example File
<?xml version=“1.0” encoding=“UTF-8” ?>
<!- - Written By: Matt - - >
<menu><entrée id = “1”>
<name>Sunburnt Chicken</name><fatgrams>23</fatgrams>
</entrée><entrée id = “2”>
<name>Gusto Spaghetti</name> <fatgrams>55</fatgrams></entrée>
</menu>
But you can also add attributes within a tag.< tagname something = “value” >
XML
XML
• Can be formatted in several ways.• CSS• XSLT
• Documents can be validated by:• XML Schemas• DTDs
Let’s take a look at some XML queries….
XML Queries
XML Queries
XML Queries
XMLSchema
DTDXSLT
XQuery
XPath
XML
XML Query Languages
XPath XSLT XQuery
Solutions for XML Queries
XPath
XPath
• XML Query Language which views XML documents as trees.
• Things such as comments and elements are nodes of these trees.• Allows us to traverse the tree and find a “path” to what we need.
• Gives us an easy to understand language for querying XML Documents.
XSLT
XSLT
• XSL Transformation
• Files usually called stylesheets.• Can be used to query and to format XML• Includes conditional instructions….• More powerful query language which can utilize parts of XPath.
• Certain queries such as joins can still be difficult in XSLT.
XQuery
XQuery
• Built by taking the best parts of two other query languages, XQL and XML-QL.
• Still uses XPath as a syntax for its expressions.
• More similar to SQL:FOR (variable declarations)WHERE (condition)RETURN (result)
SQL/XML
SQL/XML
• Slowly becoming part of the SQL standard.
• Allows us to work directly with XML documents from SQL.
• Many vendors such as Oracle, MS SQL Server, MySQL, and PostgreSQL already have much functionality built-in.
Summary
1. OODB
2. OODB AND SQL
3. XML
4. XML Queries
Object Databases help us to excel where the relational model may be cumbersome.
Allow us to integrate objects into our databases while still utilizing SQL.
A highly customizable language which helps us to represent data almost universally.
Gives us many different languages to use XML to its full potential.
The End
Thank You!
References:
References:
Wagner, Richard and Richard Mansfield. XML for DummiesFor Dummies. 2003.
Kifer, Michael and Arthur Bernstein, and Philip M. Lewis Database SystemsBoston: Pearson Education, 2006
XML Tutorial. W3 Schools. 2012 Web. Nov. 2012http://www.w3schools.com/xml/
SQL/XML. Wikipedia. 2012 Web. Nov. 2012http://en.wikipedia.org/wiki/SQL/XML