|
Page 2 of 2
Handling Transactions
As you can see from the preceding example, changes made through internet protocols to repository resources become permanent once a single operation on a resource has been completed.
In contrast, all SQL and PL/SQL operations that you perform on the XML data stored in Oracle XML DB are transactional, irrespective of whether you're using XMLType storage or the XML repository. This allows you to combine SQL and PL/SQL statements operating on XML data within a logical unit of work and explicitly commit the transaction or roll it back if necessary.
Suppose you want to create a folder in the XML repository and then upload an XML document in it. The following code fragment shows how this can be done in PL/SQL:
rslt:=DBMS_XDB.createFolder('/public/xmlusr/emps/303'); rslt:=DBMS_XDB.createResource('/public/xmlusr/emps/303/emp303.xml', xmldoc); COMMIT; -
rslt%3A%3DDBMS_XDB.createFolder%28%27%2Fpublic%2Fxmlusr%2Femps%2F303%27%29%3B%0D%0Arslt%3A%3DDBMS_XDB.createResource%28%27%2Fpublic%2Fxmlusr%2Femps%2F303%2Femp303.xml%27%2C%0D%0Axmldoc%29%3B%0D%0ACOMMIT%3B%0D%0A
The above PL/SQL code is transactional. If an error occurs during the execution of the createFolder function, then the results of execution of createFolder are discarded automatically.
On the other hand, when performing the same operations through FTP protocol, failure to create the resource doesn't affect the results of preceding operation. So, the following fragment of PHP code is not transactional:
$login = ftp_login($ftpcon, $db_user, $db_pswd); ftp_chdir($ftpcon, '/public/xmlusr/emps/303'); ftp_fput($ftpcon, 'emp303.xml', $xmldoc, FTP_ASCII );
%24login%20%3D%20ftp_login%28%24ftpcon%2C%20%24db_user%2C%20%24db_pswd%29%3B%0D%0Aftp_chdir%28%24ftpcon%2C%20%27%2Fpublic%2Fxmlusr%2Femps%27%29%3B%0D%0Aftp_mkdir%28%24ftpcon%2C%20%27303%27%29%3B%0D%0Aftp_chdir%28%24ftpcon%2C%20%27%2Fpublic%2Fxmlusr%2Femps%2F303%27%29%3B%0D%0Aftp_fput%28%24ftpcon%2C%20%27emp303.xml%27%2C%20%24xmldoc%2C%20FTP_ASCII%29%3B%0D%0Aftp_close%28%24ftpcon%29%3B
NOTE: Chapter 4 Transactions, presented earlier in this book, explains in detail how to use transactions in PHP/Oracle applications.
Trackback(0)

|