42
Company LOGO OODB and XML Database Management Systems – Fall 2012 Matthew Moccaro

OODB and XML

  • Upload
    tanith

  • View
    49

  • Download
    1

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

Page 1: OODB and XML

Company

LOGO

OODB and XML

Database Management Systems – Fall 2012

Matthew Moccaro

Page 2: OODB and XML

Outline

1. OODB

2. OODB AND SQL

3. XML

4. XML Queries

Page 3: OODB and XML

Object Databases

Object Databases

Page 4: OODB and XML

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.

Page 5: OODB and XML

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

Page 6: OODB and XML

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

Page 7: OODB and XML

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.

Page 8: OODB and XML

Object Vs. Relational: Part 1

Object Database Relational Database

Contains Classes

which are:

Sets of Objects

Contains Relations

which are:

Sets of Tuples

Page 9: OODB and XML

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…

Page 10: OODB and XML

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

Page 11: OODB and XML

OODB

TEXT TEXT

The Conceptual Object Data Model

• Helps us to understand OODB.

• Let’s take a better look at:

• Objects• Classes• Types

Page 12: OODB and XML

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

Page 13: OODB and XML

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

Page 14: OODB and XML

The Conceptual Object Data Model

TEXT TEXT

Types

• Types could be:• Basic• Reference• Tuple• Set

• Subtype and Supertype

Page 15: OODB and XML

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.

Page 16: OODB and XML

Object Databases

Object Databases and SQL

Page 17: OODB and XML

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.

Page 18: OODB and XML

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’))

Page 19: OODB and XML

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));

Page 20: OODB and XML

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.

Page 21: OODB and XML

XML

XML

Page 22: OODB and 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….

Page 23: OODB and XML

XML Example File

<?xml version=“1.0” encoding=“UTF-8” ?>

First, we can start by making an XML declaration…..

Page 24: OODB and XML

XML Example File

<?xml version=“1.0” encoding=“UTF-8” ?>

<!- - Written By: Matt - - >

Comments are done as <!-- Comment -->

Page 25: OODB and XML

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.

Page 26: OODB and XML

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.

Page 27: OODB and XML

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?

Page 28: OODB and XML

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.

Page 29: OODB and XML

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.

Page 30: OODB and XML

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….

Page 31: OODB and XML

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” >

Page 32: OODB and XML

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….

Page 33: OODB and XML

XML Queries

XML Queries

Page 34: OODB and XML

XML Queries

XMLSchema

DTDXSLT

XQuery

XPath

XML

Page 35: OODB and XML

XML Query Languages

XPath XSLT XQuery

Solutions for XML Queries

Page 36: OODB and XML

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.

Page 37: OODB and XML

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.

Page 38: OODB and XML

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)

Page 39: OODB and XML

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.

Page 40: OODB and XML

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.

Page 41: OODB and XML

The End

Thank You!

Page 42: OODB and XML

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