Skip Headers

Oracle9i XML Database Developer's Guide - Oracle XML DB
Release 2 (9.2)

Part Number A96620-02
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback

Go to previous page Go to next page
View PDF

15
RESOURCE_VIEW and PATH_VIEW

This chapter describes the SQL-based mechanisms, RESOURCE_VIEW and PATH_VIEW, used to access Oracle XML DB Repository data. It discusses the SQL operators UNDER_PATH and EQUALS_PATH used to query resources based on their path names and the SQL operators PATH and DEPTH that return the resource path names and depth.

This chapter contains the following sections:

Oracle XML DB RESOURCE_VIEW and PATH_VIEW

Figure 15-1 shows how Oracle XML DB RESOURCE_VIEW and PATH_VIEW provide a mechanism for using SQL to access data stored in Oracle XML DB Repository. Data stored in Oracle XML DB Repository through protocols like FTP, WebDAV, or programming API, can be accessed in SQL using RESOURCE_VIEWs and PATH_VIEWs, and vice versa.

RESOURCE_VIEW and PATH_VIEW together, along with PL/SQL package, DBMS_XDB, provide all query-based access to Oracle XML DB and DML functionality that is available through the programming API.

The base table for RESOURCE_VIEW is XDB.XDB$RESOURCE and should only be accessed through RESOURCE_VIEW or the DBMS_XDB API.

See Also:

Chapter 26, "Oracle XML DB Basic Demo", "6.0 XML DB Demo: Querying RESOURCE_VIEWS Using SQL".

Figure 15-1 Accessing Repository Resources Using RESOURCE_VIEW and PATH_VIEW

Text description of adxdb034.gif follows
Text description of the illustration adxdb034.gif


RESOURCE_VIEW Definition and Structure

The RESOURCE_VIEW contains one row for each resource in the Repository. The following describes its structure:

Column      Datatype     Description 
------      --------     -------------------------------------------------------
RES         XMLTYPE      A resource in Oracle XML Repository 
ANY_PATH    VARCHAR2     A path that can be used to access the resource in the
                         Repository 
See Also:

Appendix G, "Example Setup scripts. Oracle XML DB - Supplied XML Schemas"

PATH_VIEW Definition and Structure

The PATH_VIEW contains one row for each unique path to access a resource in the Repository. The following describes its structure:

Column      Datatype     Description 
------      --------     -----------------------------
PATH        VARCHAR2     Path name of a resource 
RES         XMLTYPE      The resource referred by PATH 
LINK        XMLTYPE      Link property 

See Also:

Appendix G, "Example Setup scripts. Oracle XML DB - Supplied XML Schemas"

Figure 15-2 illustrates the structure of Resource and PATH_VIEWs.


Note:

Each resource may have multiple paths called links.


The path in the RESOURCE_VIEW is an arbitrary one and one of the accessible paths that can be used to access that resource. Oracle XML DB provides operator UNDER_PATH that enables applications to search for resources contained (recursively) within a particular folder, get the resource depth, and so on. Each row in the PATH_VIEW and RESOURCE_VIEW columns is of XMLType. DML on Oracle XML DB Repository views can be used to insert, rename, delete, and update resource properties and contents. Programmatic APIs must be used for some operations, such as creating links to existing resources.

Figure 15-2 RESOURCE_VIEW and PATH_VIEW Structure

Text description of adxdb032.gif follows
Text description of the illustration adxdb032.gif


Understanding the Difference Between RESOURCE_VIEW and PATH_VIEW

The major difference between the RESOURCE_VIEW and PATH_VIEW is:

Figure 15-3 illustrates the difference between Resource and PATH_VIEW.

Since many internet applications only need one URL to access a resource, RESOURCE_VIEW is widely applicable.

PATH_VIEW contains the link properties as well as resource properties, whereas the RESOURCE_VIEW only contains resource properties.

The RESOURCE_VIEW benefit is generally optimization, if the database knows that only one path is needed, the index does not have to do as much work to determine all the possible paths.


Note:

When using the RESOURCE_VIEW, if you are specifying a path with the UNDER_PATH or EQUALS_PATH operators, they will find the resource regardless of whether or not that path is the arbitrary one chosen to normally display with that resource using RESOURCE_VIEW.


Figure 15-3 RESOURCE_VIEW and PATH_VIEW Explained

Text description of adxdb018.gif follows
Text description of the illustration adxdb018.gif


Operations You Can Perform Using UNDER_PATH and EQUALS_PATH

You can perform the following operations using UNDER_PATH and EQUALS_PATH:

See the "Using the Resource View and Path View API" and EQUALS_PATH.

Resource_View, Path_View API

This section describes the RESOURCE_VIEW and PATH_VIEW operators:

UNDER_PATH

The UNDER_PATH operator uses the Oracle XML DB Repository hierarchical index to return the paths under a particular path. The hierarchical index is designed to speed access walking down a path name (the normal usage).

If the other parts of the query predicate are very selective, however, a functional implementation of UNDER_PATH can be chosen that walks back up the Repository. This can be more efficient, since a much smaller number of links may need to be traversed. Figure 15-4 shows the UNDER_PATH syntax.

Figure 15-4 UNDER_PATH Syntax

Text description of under_path.gif follows
Text description of the illustration under_path.gif


Table 15-1 describes the UNDER_PATH syntax.

Table 15-1 RESOURCE_VIEW and PATH_VIEW API Syntax: UNDER_PATH  
Syntax Description

INTEGER UNDER_PATH(resource_column,

pathname);

Determines if a resource is under a specified path.

Parameters:

  • resource_column - The column name or column alias of the 'resource' column in the path_view or resource_view.
  • pathname - The path name to resolve.

INTEGER UNDER_PATH(resource_column,

depth,

pathname);

Determines if a resource is under a specified path, with a depth argument to restrict the number of levels to search.

Parameters:

  • resource_column - The column name or column alias of the 'resource' column in the path_view or resource_view.
  • depth - The maximum depth to search; a depth of less than 0 is treated as 0.
  • pathname - The path name to resolve.

INTEGER UNDER_PATH(resource_column,

pathname,

correlation)

Determines if a resource is under a specified path, with a correlation argument for ancillary operators.

Parameters:

  • resource_column - The column name or column alias of the 'resource' column in the path_view or resource_view.
  • pathname - The path name to resolve.
  • correlation - An integer that can be used to correlate the UNDER_PATH operator (a primary operator) with ancillary operators (PATH and DEPTH).

INTEGER UNDER_PATH(resource_column,

depth,

pathname,

correlation)

Determines if a resource is under a specified path with a depth argument to restrict the number of levels to search, and with a correlation argument for ancillary operators.

Parameters:

  • resource_column - The column name or column alias of the 'resource' column in the path_view or resource_view.
  • depth - The maximum depth to search; a depth of less than 0 is treated as 0.
  • pathname - The path name to resolve.
  • correlation - An integer that can be used to correlate the UNDER_PATH operator (a primary operator) with ancillary operators (PATH and DEPTH).

Note that only one of the accessible paths to the resource needs to be under the path argument for a resource to be returned.

EQUALS_PATH

The EQUALS_PATH operator is used to find the resource with the specified path name. It is functionally equivalent to UNDER_PATH with a depth restriction of zero. The EQUALS_PATH syntax is describe here and in Figure 15-5.

EQUALS_PATH INTEGER EQUALS_PATH( resource_column,pathname);

Figure 15-5 EQUALS_PATH Syntax

Text description of equals_path.gif follows
Text description of the illustration equals_path.gif


where:

PATH

PATH is an ancillary operator that returns the relative path name of the resource under the specified pathname argument. Note that the path column in the RESOURCE_VIEW always contains the absolute path of the resource. The PATH syntax is:

PATH VARCHAR2 PATH( correlation);

where:

Here are some examples of a RESOURCE_VIEW that include resources specified by paths:

'/a/b/c'
'/a/b/c/d'
'/a/e/c'
'/a/e/c/d' 

Example 15-1 Determining Paths Under the Specified Pathname Argument

SELECT path(1) FROM resource_view 
   WHERE UNDER_PATH(res, '/a/b', 1) = 1;

Returns the following:

PATH(1)
-------
c
c/d
2 rows returned

Example 15-2 Determining Paths Not Under the Specified Pathname Argument

SELECT path(1) FROM resource_view 
   WHERE UNDER_PATH(res, '/a/b', 1)!=1

Returns the following:

PATH(1)
-------


2 rows returned


Note:

For absolute paths use ANY_PATH as follows:

SELECT ANY_PATH
FROM resource_view 
WHERE UNDER_PATH(res, '/a/b')=1;

This returns the following:

ANY_PATH
--------
/a/e/c
/a/e/c/d
2 rows returned

Example 15-3 Determining Paths Using Multiple Correlations

SELECT ANY_PATH, path(1), path(2) 
FROM resource_view
WHERE UNDER_PATH(res, '/a/b', 1) = 1 or UNDER_PATH(res, '/a/e', 2) = 1;

This returns the following:

ANY_PATH           PATH(1)                  PATH(2)
----------------------------------------------------
/a/b/c             c
/a/b/c/d           c/d
/a/e/c                                      c
/a/e/c/d                                    c/d
4 rows returned

DEPTH

DEPTH is an ancillary operator that returns the folder depth of the resource under the specified starting path.

DEPTH  INTEGER DEPTH( correlation);

where:

correlation is an integer that can be used to correlate the UNDER_PATH operator (a primary operator) with ancillary operators (PATH and DEPTH).

Using the Resource View and Path View API

The following RESOURCE_VIEW and PATH_VIEW examples use operators UNDER_PATH, EQUALS_PATH, PATH, and DEPTH.

Accessing Paths and Repository Resources: Examples

The following examples illustrate how you can access paths, resources, and link properties in the Repository:

Example 15-4 Using UNDER_PATH: Given a Path Name, List the Directory Given by the Path Name from the RESOURCE_VIEW

select any_path from resource_view where any_path like '/sys%';

Example 15-5 Using UNDER_PATH: Given a Path Name, Get a Resource From the RESOURCE_VIEW

select any_path, extract(res, '/display_name') from resource_view
   where under_path(res, '/sys') = 1; 

Example 15-6 Using RESOURCE_VIEW: Given a Path, Get all Relative Path Names for Resources up to Three Levels

select path(1) from resource_view
   where under_path (res, 3, '/sys',1)=1;

Example 15-7 Using UNDER_PATH: Given a Path Name, Get Path and Depth Under a Specified Path from the PATH_VIEW

select path(1) PATH,depth(1) depth 
  from path_view 
  where under_path(RES, 3,'/sys',1)=1 

Example 15-8 Given a Path Name, Get Paths and Link Properties from PATH_VIEW

select path, extract(link, '/LINK/Name/text()').getstringval(), 
               extract(link, '/LINK/ParentName/text()').getstringval(), 
               extract(link, '/LINK/ChildName/text()').getstringval(), 
               extract(res, '/Resource/DisplayName/text()').getstringval() 
   from path_view
   where path LIKE '/sys%';

Example 15-9 Using UNDER_PATH: Given a Path Name, Find all the Paths up to a Certain Number of Levels, Including Links Under a Specified Path from the PATH_VIEW

select path(1) from path_view 
   where under_path(res, 3,'/sys', 1) > 0 ;

Example 15-10 Using EQUALS_PATH to Locate a Path

select any_path from resource_view
   where equals_path(res, '/sys') > 0;

Inserting Data into a Repository Resource: Examples

The following example illustrates how you can insert data into a resource:

Example 15-11 Creating Resources: Inserting Data Into a Resource

insert into resource_view values(sys.xmltype.createxml(' 
  <Resource xmlns="http://xmlns.oracle.com/xdb/XDBResource.xsd" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.oracle.com/xdb/XDBResource.xsd 
http://xmlns.oracle.com/xdb/XDBResource.xsd"> 
  <Author>John Doe</Author> 
  <DisplayName>example</DisplayName> 
  <Comment>This resource was contrived for resource view demo</Comment> 
  <Language>en</Language> 
  <CharacterSet>ASCII</CharacterSet> 
  <ContentType>text/plain</ContentType> 
  </Resource>'), '/home/SCOTT'); 

Deleting Repository Resources: Examples

The following examples illustrate how you can delete resources or paths:

Example 15-12 Deleting Resources

delete from resource_view where any_path = '/home/SCOTT/example 

If only leaf resources are deleted, you can perform a delete using delete from resource_view where....

Deleting Non-Empty Containers Recursively

If only leaf resources are deleted, you can delete them using "delete from 
resource_view where...". For example, one way to delete leaf node 
'/public/test/doc.xml' is as follows:

delete from resource_view where under_path(res, '/public/test/doc.xml') = 1;

However, if you attempt to delete a non-empty container recursively, the following rules apply:

Therefore you should guarantee that a container is deleted only after its children have been deleted.

Example 15-13 Recursively Deleting Paths

For example, to recursively delete paths under '/public'), you may want to try the following:

delete from
(select 1 from resource_view
 where UNDER_PATH(res, '/public', 1) = 1
 order by depth(1) desc);

Updating Repository Resources: Examples

The following examples illustrate how to update resources and paths:

Example 15-14 Updating Resources

update resource_view set res = sys.xmltype.createxml(' 
  <Resource xmlns="http://xmlns.oracle.com/xdb/XDBResource.xsd" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://xmlns.oracle.com/xdb/XDBResource.xsd 
http://xmlns.oracle.com/xdb/XDBResource.xsd"> 
  <Author>John Doe</Author> 
  <DisplayName>example</DisplayName> 
  <Comment>Has this got updated or not ? </Comment> 
  <Language>en</Language> 
  <CharacterSet>ASCII</CharacterSet> 
  <ContentType>text/plain</ContentType> 
  </Resource>') 
    where any_path = '/home/SCOTT/example'; 

Example 15-15 Updating a Path in the PATH_VIEW

update path_view set path = '/home/XDB' 
  where path = '/home/SCOTT/example' 

Note:

If you need to get all the resources under a directory, you can use the LIKE operator, as shown in Example 15-4.

If you need to get the resources up to a certain number of levels, or get the relative path, then use the UNDER_PATH operator, as shown in Example 15-5.

The query plan for Example 15-4 will be more optimal than that of Example 15-5.


See Also:

Chapter 13, "Oracle XML DB Foldering",Table 13-3, "Accessing Oracle XML DB Repository: API Options" for additional examples that use the RESOURCE_VIEW and PATH_VIEW operators.

Working with Multiple Oracle XML DB Resources Simultaneously

Operations listed in Table 13-3, Chapter 13, "Oracle XML DB Foldering", typically apply to only one resource at a time. To perform the same operation on multiple Oracle XML DB resources, or to find one or more Oracle XML DB resources that meet a certain set of criteria, use RESOURCE_VIEW and PATH_VIEW in SQL.

For example, you can perform the following operations with these resource_view and PATH_VIEW SQL clauses:

Tuning XML DB to Obtain Faster Queries

XML DB uses the xdbconfig file for configuring the system and protocol environment. In Release 2 (9.2.0.2) it includes an element resource-view-cache-size parameter that defines the in-memory size of the RESOURCE_VIEW cache. The default value is 1048576.

Some queries on RESOURCE_VIEW and PATH_VIEW can be sped up by tuning resource-view-cache-size. In general, the bigger the cache size, the faster the query. The default resource-view-cache-size is appropriate for most cases. However you may want to enlarge your resource-view-cache-size element when querying sizable RESOURCE_VIEWs.

See Also:

Appendix A, "Installing and Configuring Oracle XML DB"

Searching for Resources Using Oracle Text

The XDB$RESOURCE table in Oracle XML DB user schema stores in Oracle XML DB the metadata and data corresponding to resources, such as files and folders. You can search for resources containing a specific keyword by using the CONTAINS operator in RESOURCE_VIEW or PATH_VIEW.

Example 15-16 Find All Resources Containing Keywords "Oracle" and "Unix"

select path
   from path_view
   where contains(res, 'Oracle AND Unix') > 0;

Example 15-17 Find All Resources Containing Keyword "Oracle" that are Also Under a Specified Path.

select any_path
   from resource_view
   where contains(res, 'Oracle') > 0
   and under_path(res, '/myDocuments') > 0;

To evaluate such queries, you must create a Context Index on the XDB$RESOURCE table. Depending on the type of documents stored in Oracle XML DB, choose one of the following options for creating your Context Index:

DBMS_XDBT package also includes procedures to sync and optimize the index. You can use the configureAutoSync() procedure to configure automatic sync of the index by using job queues.