Oracle® XML DB Developer's Guide 10g Release 1 (10.1) Part Number B10790-01 |
|
|
View PDF |
This chapter describes the Oracle XML DB resource application program interface (API) for PL/SQL (DBMS_XDB
) used for accessing and managing Oracle XML DB repository resources and data using PL/SQL. It includes methods for managing the resource security and Oracle XML DB configuration.
This chapter contains these topics:
This chapter describes the Oracle XML DB resource API for PL/SQL (PL/SQL package DBMS_XDB
). This is also known as the PL/SQL foldering API.
Oracle XML DB repository is modeled on XML and provides a database file system for any data. Oracle XML DB repository maps path names (or URLs) onto database objects of XMLType
and provides management facilities for these objects.
DBMS_XDB
package provides functions and procedures for accessing and managing Oracle XML DB repository using PL/SQL.
The DBMS_XDB
provides the PL/SQL application developer with an API that manages:
Oracle XML DB Resources
Oracle XML DB access control list (ACL) based Security. ACL is a list of access control entries that determines which principals have access to a given resource or resources.
Oracle XML DB Configuration
Oracle XML DB Hierarchical Index Rebuild
Table 21-1 lists the DBMS_XDB
Oracle XML DB resource management methods.
Table 21-1 DBMS_XDB Resource Management Methods
The input character set id, if specified, must be a valid Oracle id; otherwise, an error is returned. This value if nonzero overrides any encoding specified in the source data. Otherwise, the character encoding of the resource is based on the MIME type which is derived from the abspath argument. If the MIME type is "*/xml
" then the character encoding is determined by auto-detection as defined in Appendix F of the W3C XML Recommendation; otherwise, the character encoding of the input is defaulted to the database character set so that no conversion is applied. The character encoding of the data file is determined based on the following precedence:
The csid
value if nonzero.
The MIME type based on the file extension specified in the abspath
argument. If the MIME type is "*/xml
" then the character encoding is determined by auto-detection, as defined in Appendix F of the W3C XML Recommendation. Otherwise, the character set of the BFILE or BLOB data is defaulted to the database character set.
Note: the determination of the character set based on the MIME type is only done when creating a resource. Afterward, changing the MIME type of a resource, either through theRESOURCE_VIEW or XDBResource Java class, will not affect the character set property of the resource. |
Use IANA character name for XML documents if possible. The character set id can be derived from an IANA name using: UTL_GDK.CHARSET_MAP
and NLS_CHARSET_ID
functions. For example:
Example 21-1 Deriving the Character Set ID From an IANA Name Using UTL_GDK.CHARSET_MAP
DECLARE oracs VARCHAR2(255); csid NUMBER; BEGIN oracs := UTL_GDK.CHARSET_MAP('EUC-JP', utl_gdk.IANA_TO_ORACLE); csid := NLS_CHARSET_ID(oracs); END;
Figure 21-1 describes the calling sequence when using DBMS_XDB
to manage repository resources:
When managing repository resources the calling sequence diagram assumes that the resources and folders already exist. If not, then you must create the resources using createResource()
or create folders using createFolder()
createResource()
takes resource data and the resource path as parameters.
createFolder()
takes the resource path as a parameter.
If the resource or folder does not need additional processing or managing, then they are simply output.
If the resource or folder need additional processing or managing, then you can apply any or all of the following methods as listed in Table 21-1:
Link()
LockResource()
GetLockToken()
UnlockResource()
DeleteResource()
See Example 21-2 for an examples of using DBMS_XDB
to manage repository resources.
Figure 21-1 Using DBMS_XDB to Manage Resources: Calling Sequence
Example 21-2 Using DBMS_XDB to Manage Resources
DECLARE retb boolean; BEGIN retb := dbms_xdb.createfolder('/public/mydocs'); commit; END; / declare bret boolean; begin bret := dbms_xdb.createresource('/public/mydocs/emp_scott.xml','<emp_name>scott</emp_name>'); commit; end; / declare bret boolean; begin bret := dbms_xdb.createresource('/public/mydocs/emp_david.xml','<emp_name>david</emp_name>'); commit; end; / call dbms_xdb.link('/public/mydocs/emp_scott.xml','/public/mydocs', 'person_scott.xml'); call dbms_xdb.link('/public/mydocs/emp_david.xml','/public/mydocs', 'person_david.xml'); commit; call dbms_xdb.deleteresource('/public/mydocs/emp_scott.xml'); call dbms_xdb.deleteresource('/public/mydocs/person_scott.xml'); call dbms_xdb.deleteresource('/public/mydocs/emp_david.xml'); call dbms_xdb.deleteresource('/public/mydocs/person_david.xml'); call dbms_xdb.deleteresource('/public/mydocs'); commit;
Table 21-2 lists the DBMS_XDB
Oracle XML DB ACL- based security management methods. Because the arguments and return values for the methods are self-explanatory, only a brief description of the methods is provided here.
Table 21-2 DBMS_XDB: Security Management Methods
DBMS_XDB Method | Arguments, Return Values |
---|---|
getAclDocument |
Argument: (abspath VARCHAR2)
Return value: |
ACLCheckPrivileges |
Argument: (acl_path IN VARCHAR2, owner IN VARCHAR2, privs IN XMLType)
Return value: Positive integer if privileges are granted. |
checkPrivileges |
Argument: (res_path IN VARCHAR2, privs IN XMLType)
Return value: Positive integer if privileges are granted. |
getprivileges |
Argument: (res_path IN VARCHAR2)
Return value: |
changePrivileges |
Argument: (res_path IN VARCHAR2, ace IN XMLType)
Return value: Positive integer if ACL was successfully modified. |
setAcl |
Argument: (res_path IN VARCHAR2, acl_path IN VARCHAR2) . This sets the ACL of the resource at res_path to the ACL located at acl_path .
Return value: N/A |
Figure 21-2 describes the calling sequence when using DBMS_XDB
to manage security.
Each DBMS_XDB
security management method take in a path (resource_path, abspath, or acl_path).
You can then use any or all of the DBMS_XDB
methods listed in Table 21-2 to perform security management tasks:
getAclDocument()
ACLCheckPrivileges()
checkPrivileges()
getPrivileges()
changePrivileges()
setACL()
See Example 21-3 for an examples of using DBMS_XDB
to manage repository resource security.
Figure 21-2 Using DBMS_XDB to Manage Security: Calling Sequence
Example 21-3 Using DBMS_XDB to Manage ACL-Based Security
DECLARE retb boolean; BEGIN retb := dbms_xdb.createfolder('/public/mydocs'); commit; END; / declare bret boolean; begin bret := dbms_xdb.createresource('/public/mydocs/emp_scott.xml','<emp_name>scott</emp_name>'); commit; end; / call dbms_xdb.setacl('/public/mydocs/emp_scott.xml', '/sys/acls/all_owner_acl.xml'); commit; select dbms_xdb.getacldocument('/public/mydocs/emp_scott.xml') from dual; declare r pls_integer; ace XMLType; ace_data varchar2(2000); begin ace_data := '<ace xmlns="http://xmlns.oracle.com/xdb/acl.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/xdb/acl.xsd http://xmlns.oracle.com/xdb/acl.xsd DAV:http://xmlns.oracle.com/xdb/dav.xsd"> <principal>SCOTT</principal> <grant>true</grant> <privilege> <all/> </privilege> </ace>'; ace := xmltype.createxml(ace_data); r := dbms_xdb.changeprivileges('/public/mydocs/emp_scott.xml', ace); dbms_output.put_line('retval = ' || r); commit; end; / select dbms_xdb.getacldocument('/public/mydocs/emp_scott.xml') from dual; select dbms_xdb.getprivileges('/public/mydocs/emp_scott.xml') from dual; call dbms_xdb.deleteresource('/public/mydocs/emp_scott.xml'); call dbms_xdb.deleteresource('/public/mydocs'); commit;
Table 21-3 lists the DBMS_XDB
Oracle XML DB Configuration Management Methods. Because the arguments and return values for the methods are self-explanatory, only a brief description of the methods is provided here.
Table 21-3 DBMS_XDB: Configuration Management Methods
DBMS_XDB Method | Arguments, Return Value |
---|---|
CFG_get |
Argument: None
Return value: |
CFG_refresh |
Argument: None
Return value: N/A |
CFG_update |
Argument: (xdbconfig IN XMLType)
Return value: N/A |
Figure 21-3 shows the calling sequence when using DBMS_XDB
for configuration management.
The diagram shows the following sequence:
To manage the Oracle XML DB configuration, first retrieve the configuration instance using cfg_get
.
You can then optionally modify the Oracle XML DB configuration XMLType
instance to update it, or simply produce the Oracle XML DB configuration.
To update the Oracle XML DB configuration resource use cfg_update
. You must either input a new Oracle XML DB configuration XMLType instance or use a modified version of the current configuration.
To refresh the Oracle XML DB configuration resource use cfg_refresh
. You are not required to input a configuration XMLType instance.
See Example 21-4 for an example of using DBMS_XDB
for configuration management of repository resources.
Figure 21-3 Using DBMS_XDB for Configuration Management: Calling Sequence
Example 21-4 Using DBMS_XDB for Configuration Management of Oracle XML DB
connect system/manager select dbms_xdb.cfg_get() from dual; declare config XMLType; begin config := dbms_xdb.cfg_get(); -- Modify the xdb configuration using updatexml ... dbms_xdb.cfg_update(config); end; / -- To pick up the latest Oracle XML DB Configuration -- In this example it is not needed as cfg_update() -- automatically does a cfg_refresh(). call dbms_xdb.cfg_refresh();