Oracle9i XML Database Developer's Guide - Oracle XML DB Release 2 (9.2) Part Number A96620-02 |
|
|
View PDF |
This chapter describes how to create and manage versions of Oracle XML DB resources. It contains the following sections:
Oracle XML DB versioning provides a way to create and manage different versions of a resource in Oracle XML DB. In previous releases of Oracle9i database, after a resource (table, column,...) is updated, its previous contents and properties are lost. Oracle XML DB versioning prevents this loss by storing a version of the resource in the database to keep the old resource contents and properties when an update is issued.
Oracle XML DB provides a PLSQL package, DBMS_XDB_VERSION
to put a resource under version-control and retrieve different versions of the resource.
Oracle XML DB versioning helps keep track of all changes on version-controlled Oracle XML DB resources (VCR). The following sections discuss these features in detail. Oracle XML DB versioning features include the following:
Note: In this release, Oracle XML DB versioning supports version control for Oracle XML DB resources. It does not support version control for user-defined tables or data in an Oracle9i database. |
Table 14-1 lists the Oracle XML DB versioning terms used in this chapter.
Oracle XML DB resource ID is a unique system-generated ID for an Oracle XML DB resource. Here Resource ID helps identify resources that do not have path names. For example, version resource is a system-generated resources and does not have a path name. The function GetResourceByResId()
can be used to retrieve resources given the resource object ID.
declare resid DBMS_XDB_VERSION.RESID_TYPE; res XMLType; begin resid := DBMS_XDB_VERSION.MakeVersioned('/home/SCOTT/versample.html'); -- Obtain the resource res := DBMS_XDB_VERSION.GetResoureceByResId(resid);
Oracle XML DB does not automatically keep a history of updates since not all Oracle XML DB resources need this. You must send a request to Oracle XML DB to put an Oracle XML DB resource under version control. In this release, all Oracle XML DB resources are versionable resources except for the following:
When a Version-Controlled Resource (VCR) is created the first version resource of the VCR is created, and the VCR is a reference to the newly-created version.
See "Version Resource or VCR Version".
Resource 'home/SCOTT/versample.html
' is turned into a version-controlled resource.
declare resid DBMS_XDB_VERSION.RESID_TYPE; begin resid := DBMS_XDB_VERSION.MakeVersioned('/home/SCOTT/versample.html'); end; /
MakeVersioned()
returns the resource ID of the very first version of the version-controlled resource. This version is represented by a resource ID, which is discussed in "Resource ID of a New Version" .
MakeVersioned()
is not an auto-commit SQL operation. You have to commit the operation.
Oracle XML DB does not provide path names for version resources. However, it does provide a version resource ID. Version resources are read-only resources.
The version ID is returned by a couple of methods in package DBMS_XDB_VERSION
, that are described in the following sections.
When a VCR is checked in, a new version resource is created, and its resource ID is returned to the you. Because the VCR is just a reference to this new version resource, the resource ID of the version can also be found by calling method DBMS_XDB.getResourceID()
whose input is the VCR path name.
The following example shows how to get the resource ID of the new version after checking in '/home/index.html
':
-- Declare a variable for resource id declare resid DBMS_XDB_VERSION.RESID_TYPE; res XMLType; begin -- Get the id as user checks in. resid := DBMS_XDB_VERSION.checkin('/home/SCOTT/versample.html'); -- Obtain the resource res := DBMS_XDB_VERSION.GetResourceByResId(resid); end; /
-- Variable definitions. declare resid1 DBMS_XDB_VERSION.RESID_TYPE; resid2 DBMS_XDB_VERSION.RESID_TYPE; begin -- Put a resource under version control. resid1 := DBMS_XDB_VERSION.MakeVersioned('/home/SCOTT/versample.html'); -- Checkout to update contents of the VCR DBMS_XDB_VERSION.Checkout('/home/SCOTT/versample.html'); -- Use resource_view to update versample.html 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>Jane Doe</Author> <DisplayName>versample</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/versample.html'; -- Checkin the change resid2 := DBMS_XDB_VERSION.Checkin('/home/SCOTT/versample.html'); end; / -- At this point, you can download the first version with the resource object ID, -- resid1 and download the second version with resid2. -- Checkout to delete the VCR DBMS_XDB_VERSION.Checkout('/home/SCOTT/versample.html'); -- Delete the VCR delete from resource_view where any_path = '/home/SCOTT/versample.html'; -- Once the delete above is done, any reference -- to the resource (that is, checkin, checkout,and so on, results in -- ORA-31001: Invalid resource handle or path name "/home/SCOTT/versample.html"
VCR also has a path name as any regular resource. Accessing a VCR is the same as accessing any other resources in Oracle XML DB.
The operations on regular Oracle XML DB resources do not require the VCR to be checked-out. Updating a VCR requires more steps than for a regular Oracle XML DB resource:
Before updating the contents and properties of a VCR, check out the resource. The resource must be checked in to make the update permanent. All of these operations are not auto-commit SQL operations. You must explicitly commit the SQL transaction. Here are the steps to update a VCR:
In Oracle9i Release 2 (9.2), the VCR checkout operation is executed by calling DBMS_XDB_VERSION.CheckOut()
. If you want to commit an update of a resource, it is a good idea to commit after checkout. If you do not commit right after checking out, you may have to rollback your transaction at a later point, and the update is lost.
For example:
-- Resource '/home/SCOTT/versample.html' is checked out. DBMS_XDB_VERSION.CheckOut('/home/SCOTT/versample.html');
InOracle9i Release 2 (9.2), the VCR checkin operation is executed by calling DBMS_XDB_VERSION.CheckIn()
. Checkin takes the path name of a resource. This path name does not have to be the same as the path name that was passed to checkout, but the checkin and checkout path names must be of the same resource.
For example:
-- Resource '/home/SCOTT/versample.html' is checked in. declare resid DBMS_XDB_VERSION.RESID_TYPE; begin resid := DBMS_XDB_VERSION.CheckIn('/home/SCOTT/versample.html'); end; /
InOracle9i Release 2 (9.2), uncheckout is executed by calling DBMS_XDB_VERSION.UncheckOut()
. This path name does not have to be the same as the path name that was passed to checkout, but the checkin and checkout path names must be of the same resource.
For example:
-- Resource '/home/SCOTT/versample.html' is unchecked out. declare resid DBMS_XDB_VERSION.RESID_TYPE; begin resid := DBMS_XDB_VERSION.UncheckOut('/home/SCOTT/versample.html'); end; /
After checking out a VCR, all Oracle XML DB user interfaces for updating contents and properties of a regular resource can be applied to a VCR.
See Also:
Chapter 15, "RESOURCE_VIEW and PATH_VIEW" for details on updating an Oracle XML DB resource. |
Access control on VCR and version resource is the same as for a regular resource. Whenever you request access to these resources, ACL is checked.
When a regular resource is makeversioned
, the first version resource is created, and the ACL of this first version is the same as the ACL of the original resource. When a checked-out resource is checked in, a new version is created, and the ACL of this new version is exactly the same as the ACL of the checked-out resource. After version resource is created, its ACL cannot be changed and is used the same way as the ACL of a regular resource.
When a VCR is created by makeversioned
, the ACL of the VCR is the same as the ACL of the first version of the resource. When a resource is checked in, a new version is created, and the VCR will have the same contents and properties including ACL property with this new version.
Table 14-2 describes the subprograms in DBMS_XDB_VERSION
.
Answer: No.
Answer: The old copy is the version resource of the last checked-in:
Answer: Only Oracle XML DB resources can be put under version control in this release.