oracle xml db - what's in it for me?

8
www.sagecomputing.com.au www.sagecomputing.com.au Oracle XML DB Oracle XML DB What's in it for me? What's in it for me? Penny Cookson - Managing Director SAGE Computing Services SAGE Computing Services Customised Oracle Training Workshops Customised Oracle Training Workshops and Consulting and Consulting www.sagecomputing.com.au www.sagecomputing.com.au NZOUG Masterclass Series www.sagecomputing.com.au www.sagecomputing.com.au Overview Storage methods – structured and unstructured, pros and cons The XMLType Storing , querying and updating XML using SQL XML schemas XML Validation XML Transformation XML DB repository Using ftp and http for access to XML documents Using webDAV for access to XML documents www.sagecomputing.com.au www.sagecomputing.com.au Overview www.sagecomputing.com.au www.sagecomputing.com.au Why Do I Care? Why Do I Care? XML is the de facto standard for data interchange XML is widely used for content management XML provides flexible data storage Store structured, semi-structured, unstructured data XQuery to become W3C recommendation Security and versioning XMLDB provides: Native server support for storage and processing of XML documents SQL access to XML data Access using standard internet protocols www.sagecomputing.com.au www.sagecomputing.com.au Why XMLDB Why XMLDB Without XML as a datatype With XML as a datatype XML as CLOB Shredded XML Complex Processing in the application Native XMLType data type Process XML like any other data type www.sagecomputing.com.au www.sagecomputing.com.au Functionality Functionality Native storage of XML data using XMLType Built - in methods provided for manipulating/accessing the data Support for W3C XML Schema standard Support for W3C XPath standard Support for W3C XQuery standard Repository stores XML and other documents using path based paradigm Performance optimisations including indexing

Upload: sage-computing-services

Post on 16-Aug-2015

37 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Oracle XML DB - What's in it for me?

www.sagecomputing.com.auwww.sagecomputing.com.au

Oracle XML DB Oracle XML DB What's in it for me?What's in it for me?

Penny Cookson - Managing Director

SAGE Computing ServicesSAGE Computing ServicesCustomised Oracle Training WorkshopsCustomised Oracle Training Workshops

and Consultingand Consultingwww.sagecomputing.com.auwww.sagecomputing.com.au

NZOUG Masterclass Series

www.sagecomputing.com.auwww.sagecomputing.com.au

OverviewStorage methods – structured and unstructured,

pros and consThe XMLTypeStoring , querying and updating XML using SQLXML schemasXML Validation XML Transformation XML DB repositoryUsing ftp and http for access to XML documentsUsing webDAV for access to XML documents

www.sagecomputing.com.auwww.sagecomputing.com.au

Overview

www.sagecomputing.com.auwww.sagecomputing.com.au

Why Do I Care?Why Do I Care?

XML is the de facto standard for data interchangeXML is widely used for content managementXML provides flexible data storageStore structured, semi-structured, unstructured dataXQuery to become W3C recommendationSecurity and versioningXMLDB provides:

Native server support for storage and processing of XML documentsSQL access to XML data

Access using standard internet protocols

www.sagecomputing.com.auwww.sagecomputing.com.au

Why XMLDBWhy XMLDB

Without XML as a datatype

With XML as a datatype

XML as CLOB

Shredded XML

Complex Processing in the application

Native XMLType data type

Process XML like any other data type

www.sagecomputing.com.auwww.sagecomputing.com.au

FunctionalityFunctionality

Native storage of XML data using XMLTypeBuilt- in methods provided for manipulating/accessing the dataSupport for W3C XML Schema standardSupport for W3C XPath standardSupport for W3C XQuery standardRepository stores XML and other documents using path based paradigmPerformance optimisations including indexing

Page 2: Oracle XML DB - What's in it for me?

www.sagecomputing.com.auwww.sagecomputing.com.au

Underlying Technology

www.sagecomputing.com.auwww.sagecomputing.com.au

Is it installed?Is it installed?

DBCA automatically installs XMLDB functionalityInstall manually using catqm.sql and catxdbjXDB user owns repository/xdbconfig.xml stored in repositoryConfigure using Enterprise Manager or manually

www.sagecomputing.com.auwww.sagecomputing.com.au www.sagecomputing.com.auwww.sagecomputing.com.au

XMLTypeXMLType

Native server data typeProvides methods

extract()extractValue()existsNode()schemaValidate()transform()

Unstructured in CLOBSStructured in object type tables created from schemaSemistructuredXMLType views for legacy data

www.sagecomputing.com.auwww.sagecomputing.com.au

XMLType XMLType -- ExamplesExamples

CREATE TABLE res_docs OF XMLType;

CREATE TABLE resource_details (code VARCHAR2(4),description VARCHAR2(50),daily_rate NUMBER(6,2),specification XMLType);

www.sagecomputing.com.auwww.sagecomputing.com.au

XMLType XMLType -- ExamplesExamples

INSERT INTO res_docsVALUES(XMLType('<Equipment serialNo="1000">

<Manufacturer>ACME</Manufacturer><Servicedate>01-JAN-2002</Servicedate><Type>Video Equipment</Type></Equipment>'));

INSERT INTO resource_details(code, description, daily_rate, specification)VALUES('VCR6', 'Video recorder 6',100,XMLType('<Equipment serialNo="1000">

<Manufacturer>ACME</Manufacturer><Servicedate>01-JAN-2002</Servicedate><Type>Video Equipment</Type></Equipment>'));;

Page 3: Oracle XML DB - What's in it for me?

www.sagecomputing.com.auwww.sagecomputing.com.au

Storage MethodsStorage Methods

Entire document in a single CLOBFast storage and retrieval of entire documentPreserves original documentStore any documentCan be indexed using function based index or Oracle textLimited intelligent processingXPath operations require creation of DOM from documentNo piecewise updateMore spaceNon schema based

Contents decomposed into set of objectsIncreased processing in storage and retrievalLoses whitespace / data format, maintains DOM fidelityLimited changes to schemaXQuery and XPath converted to native database queriesB*Tree, function based and Oracle text indexesXML schema annotation determines storage typeLess space

Unstructured - CLOB Structured

www.sagecomputing.com.auwww.sagecomputing.com.au

A Closer Look at Structured A Closer Look at Structured StorageStorage

Register Schema

Oracle defines an objectType for each complexType

Collections mapped toVARRAYS

Schema annotationsdetermine storage structures

Creates default tables

www.sagecomputing.com.auwww.sagecomputing.com.au

RepositoryRepository

Hierarchical folder/file metaphorStores metadata and contentAny content , but particularly XMLAccess using

SQL or PL/SQLstandard protocolsOracle Enterprise Manager

www.sagecomputing.com.auwww.sagecomputing.com.au

www.sagecomputing.com.auwww.sagecomputing.com.au www.sagecomputing.com.auwww.sagecomputing.com.au

XML Schema

Page 4: Oracle XML DB - What's in it for me?

www.sagecomputing.com.auwww.sagecomputing.com.au

XML SchemaXML Schema

Defines validation rulesDefines physical storage types using annotationDefines physical storage names using annotationDefined as .xsd documentRegistered using DBMS_XMLSCHEMA.registerschema

www.sagecomputing.com.auwww.sagecomputing.com.au

www.sagecomputing.com.auwww.sagecomputing.com.au

Creating Schema Based Creating Schema Based XMLType InstancesXMLType Instances

Pass the schema in to XMLType constructoror SchemaLocation defined in XML documentDocument must be well formed and conform to SQL Type definitions created by schemaFor full validation use schemaValidate() methodCan use check constraint or triggerAdd uniqueness and foreign key constraints

www.sagecomputing.com.auwww.sagecomputing.com.au

Changing a SchemaChanging a Schema

DBMS_XMLSCHEMA.copyEvolveCopies instances to temporary tablesDrops old schemaCreates new schemaRegisters new schemaCopy instances back

RestrictionsIndexes, triggers, constraints lostDoes not support XMLType columns

www.sagecomputing.com.auwww.sagecomputing.com.au

DEMODEMO

Create SchemaCreate document using PL/SQL

Create document using the repository

Validate the document

www.sagecomputing.com.auwww.sagecomputing.com.au

Accessing the XML data

Page 5: Oracle XML DB - What's in it for me?

www.sagecomputing.com.auwww.sagecomputing.com.au

Access MethodsAccess Methods

Query basedSQLJava APIPL/SQL API

Path based (repository)SQL (RESOURCE_VIEW or PATH_VIEW)PL/SQL (DBMS_XDB)Protocol based

www.sagecomputing.com.auwww.sagecomputing.com.au

Query BasedQuery Based

Identify whether a node existsexistsNode

Fetch a node extract

Fetch a valueextractValue

Update a nodeupdateXML

Transform a documentXMLtransform

www.sagecomputing.com.auwww.sagecomputing.com.au

ExampleExample

SELECT existsNode(value(R), '/Equipment[Manufacturer="ACME"]') Is_There,extractValue(value(R), '/Equipment/Manufacturer') Manufacturer

FROM res_docs R;

IS_THERE MANUFACTURER------------------- ------------------------------

1 ACME0 SMITH AND SONS0 SMITH AND SONS

www.sagecomputing.com.auwww.sagecomputing.com.au

ExampleExample

SELECT extract(value(R),'/Equipment/Manufacturer') Tree

FROM res_docs R;

TREE--------------------------------------------------------------------<Manufacturer>ACME</Manufacturer><Manufacturer>SMITH AND SONS</Manufacturer><Manufacturer>SMITH AND SONS</Manufacturer>

www.sagecomputing.com.auwww.sagecomputing.com.au

ExampleExample

UPDATE res_docs RSET value(R) =

updateXML(value(R),'/Equipment/Manufacturer/text()','ACME CORPORATION')

WHERE existsNode(value(R),'/Equipment[Manufacturer="ACME"]') =1;

SELECT extract(value(R),'/Equipment/Manufacturer') Tree FROM res_docs R;

TREE--------------------------------------------------------------------------<Manufacturer>ACME CORPORATION</Manufacturer><Manufacturer>SMITH AND SONS</Manufacturer><Manufacturer>SMITH AND SONS</Manufacturer>

www.sagecomputing.com.auwww.sagecomputing.com.au

ExampleExample

-- Create a table store the XSL stylesheetCREATE TABLE res_xsl OF XMLType;

-- Insert the stylesheet documentINSERT INTO res_xslvalues (XMLType('<html>

<head/><body text="#FFFF00">

<FONT FACE="Arial"> </FONT>……………………………….……………………………….

</body></html>'));

--Transform the documentsSELECT value(R).transform(value(S))FROM res_docs(R), res_xsl;

Page 6: Oracle XML DB - What's in it for me?

www.sagecomputing.com.auwww.sagecomputing.com.au

Index OptionsIndex Options

Use extractValue for single valueUsing extract for multiple values creates index on concatenationUse function based indexesUse bitmap indexes on existsNodeUse ctxxpath indexes for existsNode processing

www.sagecomputing.com.auwww.sagecomputing.com.au

Generate Relational data as Generate Relational data as XMLXML

SELECT SYS_XMLGEN(description) DESCR, SYS_XMLGEN(specification) SPEC

FROM resource_details;

DESCR SPEC--------------------------------------------- --------------------------------------------------<DESCRIPTION>Video recorder 6 <SPECIFICATION></DESCRIPTION> <Equipment serialNo="1000">

<Manufacturer>ACME CORPORATION</Manufacturer><Servicedate>01-JAN-2002</Servicedate><Type>Video Equipment</Type></Equipment></SPECIFICATION>

www.sagecomputing.com.auwww.sagecomputing.com.au

Aggregate RowsAggregate Rows

SELECT SYS_XMLAGG(SYS_XMLGEN(value(R)))FROM res_docs R;

SYS_XMLAGG(SYS_XMLGEN(VALUE(R)))---------------------------------------------------------------------------------<ROWSET><ROW><Equipment serialNo="1000"><Manufacturer>ACME CORPORATION</Manufacturer><Servicedate>01-JAN-2002</Servicedate><Type>Video Equipment</Type>

</Equipment></ROW><ROW><Equipment serialNo="2000"><Manufacturer>SMITH AND SONS</Manufacturer><Servicedate>10-DEC-2002</Servicedate><Type>Video Equipment</Type>

</Equipment></ROW>

…………………………. www.sagecomputing.com.auwww.sagecomputing.com.au

DEMODEMO

Xpath queriesUpdating data

Transformation

www.sagecomputing.com.auwww.sagecomputing.com.au

XML Repository

www.sagecomputing.com.auwww.sagecomputing.com.au

Repository AccessRepository Access

PATH_VIEWRESOURCE_VIEWDBMS_XDBStandard protocols

ftphttpWebDav

Oracle Enterprise Manager

Page 7: Oracle XML DB - What's in it for me?

www.sagecomputing.com.auwww.sagecomputing.com.au

DBMS_XDBDBMS_XDB

Create a resource in the XMLDB repositorycreateResource

Check whether a resource existsexistsResource

Create a folder in the repositorycreateFolder

Access documents in the repositoryXDBURIType.getBLOB()XDBURIType.getCLOB()XDBURIType.getXML()

www.sagecomputing.com.auwww.sagecomputing.com.au

VersionsVersions

DBMS_XDB_VERSION.MakeVersionedReturns resource id of first versionDBMS_XDB_VERSION.checkOutDBMS_XDB_VERSION.checkInDBMS_XDB_VERSION.UnCheckOutDBMS_XDB_VERSION.GetPredecessorsOnly for non schema based resources

www.sagecomputing.com.auwww.sagecomputing.com.au

SecuritySecurity

Managed in Access Contrl Lists (ACL)Stored in XDB.XDB$ACLResources stored in XDB$RESOURCESupports

Database usersDatabase rolesLDAP usersLDAP groups

DBMS_XDB.setACLDBMS_XDB.GETACLDOCUMENTDBMS_XDB.getPrivileges

www.sagecomputing.com.auwww.sagecomputing.com.au

PrivilegesPrivileges

Atomicread-propertiesread-contentsupdateread-acldav: lockdav: unlock

Aggregatealldav: readdav: write

www.sagecomputing.com.auwww.sagecomputing.com.au www.sagecomputing.com.auwww.sagecomputing.com.au

Page 8: Oracle XML DB - What's in it for me?

www.sagecomputing.com.auwww.sagecomputing.com.au

WebDAVWebDAV

www.sagecomputing.com.auwww.sagecomputing.com.au

httphttp

www.sagecomputing.com.auwww.sagecomputing.com.au

ftpftp

www.sagecomputing.com.auwww.sagecomputing.com.au

DEMODEMO

Using DBMS_XDBftp access

WebDav accesshttp access

www.sagecomputing.com.auwww.sagecomputing.com.au

Thank YouFor Your Attention

[email protected]

SAGE Computing ServicesSAGE Computing ServicesCustomised Oracle Training WorkshopsCustomised Oracle Training Workshops

and Consultingand Consultingwww.sagecomputing.com.auwww.sagecomputing.com.au