Skip Headers
Oracle® Application Server PL/SQL Web Toolkit Reference
10g Release 2 (10.1.2)
B15896-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

5 The owa_opt_lock Package

The owa_opt_lock package contains subprograms that impose optimistic locking strategies, so as to prevent lost updates. It checks if the row that the user is interested in updating has been changed by someone else in the meantime.

The PL/SQL Gateway cannot use conventional database locking schemes because HTTP is a stateless protocol. The owa_opt_lock package gives you two ways of dealing with the lost update problem:

These methods are optimistic. They do not prevent other users from performing updates, but they do reject the current update if an intervening update has occurred.

5.1 Summary

owa_opt_lock.vcArray data type - data type to contain ROWIDs.

owa_opt_lock.checksum function - returns the checksum value.

owa_opt_lock.get_rowid function - returns the ROWID value.

owa_opt_lock.store_values procedure - stores unmodified values in hidden fields for later verification.

owa_opt_lock.verify_values function - verifies the stored values against modified values.

5.2 owa_opt_lock.vcArray data type

This data type is a PL/SQL table intended to hold ROWIDs.

Type vcArray is table of varchar2(2000) index by binary_integer.

Note that this is different from the owa_text.vc_arr data type.

Table 5-1 owa_opt_lock.vcArray data type

Properties Definitions

Syntax:

owa_opt_lock.vcArray - data type

Returns:

Not applicable.


5.3 owa_opt_lock.checksum function

This function returns a checksum value for a specified string, or for a row in a table. For a row in a table, the function calculates the checksum value based on the values of the columns in the row. This function comes in two versions.

The first version returns a checksum based on the specified string. This is a "pure" 32-bit checksum executed by the database and based on the Internet 1 protocol.

The second version returns a checksum based on the values of a row in a table. This is a "impure" 32-bit checksum based on the Internet 1 protocol.

Table 5-2 owa_opt_lock.checksum function

Properties Definitions

Syntax:

owa_opt_lock.checksum(p_buff in varchar2) return number;
owa_opt_lock.checksum(
   p_owner        in       varchar2
   p_tname        in       varchar2
   p_rowid        in       rowid) return number;

Parameters:

p_buff - the string where you want to calculate the checksum.

p_owner - the owner of the table.

p_tname - the table name.

p_rowid - the row in p_tname where you want to calculate the checksum value. Use the owa_opt_lock.get_rowid function to convert vcArray values to proper rowids.

Returns:

A checksum value.


5.4 owa_opt_lock.get_rowid function

This function returns the ROWID data type from the specified owa_opt_lock.vcArray data type.

Table 5-3 owa_opt_lock.get_rowid function

Properties Definitions

Syntax:

owa_opt_lock.get_rowid(p_old_values in vcArray) return rowid;

Parameters:

p_old_values - this parameter is usually passed in from an HTML form.

Returns:

A ROWID.


5.5 owa_opt_lock.store_values procedure

This procedure stores the column values of the row that you want to update later. The values are stored in hidden HTML form elements. Before updating the row, compare these values with the current row values to ensure that the values in the row have not been changed. If the values have changed, you can warn the users and let them decide if the update should take place.

Table 5-4 owa_opt_lock.store_values procedure

Properties Definitions

Syntax:

owa_opt_lock.store_values(
   p_owner        in       varchar2
   p_tname        in       varchar2
   p_rowid        in       rowid);

Parameters:

p_owner - the owner of the table.

p_tname - the name of the table.

p_rowid - the row where you want to store values.

Generates:

A series of hidden form elements:

One hidden form element is created for the table owner. The name of the element is "old_p_tname", where p_tname is the name of the table. The value of the element is the owner name.

One hidden form element is created for the table name. The name of the element is "old_p_tname", where p_tname is the name of the table. The value of the element is the table name.

One element is created for each column in the row. The name of the element is "old_p_tname", where p_tname is the name of the table. The value of the element is the column value.

See also:

owa_opt_lock.verify_values function.


5.6 owa_opt_lock.verify_values function

This function verifies whether values in the specified row have been updated since the last query. Use this function with the owa_opt_lock.store_values procedure.

Table 5-5 owa_opt_lock.verify_values function

Properties Definitions

Syntax:

owa_opt_lock.verify_values(p_old_values in vcArray) return boolean;

Parameters:

p_old_values - a PL/SQL table containing the following information:

p_old_values(1) specifies the owner of the table.

p_old_values(2) specifies the table.

p_old_values(3) specifies the rowid of the row to verify.

The remaining indexes contain values for the columns in the table.

Typically, this parameter is passed in from the HTML form, where you have previously called the owa_opt_lock.store_values procedure to store the row values on hidden form elements.

Returns:

TRUE if no other update has been performed; otherwise, FALSE.

See also:

owa_opt_lock.store_values procedure.