Skip Headers
Oracle® Database PL/SQL Packages and Types Reference
10g Release 2 (10.2)

Part Number B14258-01
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
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

144 OWA_OPT_LOCK

The OWA_OPT_LOCK package contains subprograms that impose optimistic locking strategies so as to prevent lost updates.

See Also:

For more information about implementation of this package:

This chapter contains the following topics:


Using OWA_OPT_LOCK


Overview

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.


Types

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.


Summary of OWA_OPT_LOCK Subprograms

Table 144-1 OWA_CACHE Package Subprograms

Subprogram Description
CHECKSUM Functions
Returns the checksum value
GET_ROWID Function
Returns the ROWID value
STORE_VALUES Procedure
Stores unmodified values in hidden fields for later verification
VERIFY_VALUES Function
Verifies the stored values against modified values


CHECKSUM Functions

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.

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

Table 144-2 CHECKSUM Procedure Parameters

Parameter Description
p_buff The nstring 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 GET_ROWID Function to convert VCARRAY values to proper rowids.


GET_ROWID Function

This function returns the ROWID data type from the specified OWA_OPT_LOCK.VCARRAY DATA TYPE.

Syntax

OWA_OPT_LOCK.GET_ROWID(
   p_old_values      IN      vcarray) 
 RETURN ROWID;

Parameters

Table 144-3 GET_ROWID Procedure Parameters

Parameter Description
p_old_values This parameter is usually passed in from an HTML form.


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.

Syntax

OWA_OPT_LOCK.STORE_VALUES(
   p_owner        IN       VARCHAR2,
   p_tname        IN       VARCHAR2,
   p_rowid        IN       ROWID);

Parameters

Table 144-4 STORE_VALUES Procedure Parameters

Parameter Description
p_owner The owner of the table.
p_tname The name of the table.
p_rowid The row where you want to store values.

Usage Notes

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.

The procedure generates series of hidden form elements:

See also the VERIFY_VALUES Function.


VERIFY_VALUES Function

This function verifies whether values in the specified row have been updated since the last query. Use this function with the STORE_VALUES Procedure.

Syntax

OWA_OPT_LOCK.VERIFY_VALUES(
   p_old_values IN vcarray) 
 RETURN BOOLEAN;

Parameters

Table 144-5 VERIFY_VALUES Procedure Parameters

Parameter Description
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 STORE_VALUES Procedure to store the row values on hidden form elements.


Return Values

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