user manual

154 BES Developers Guide
Container-Managed Persistence in Borland Enterprise Server
SelectForUpdate
SelectForUpdateNoWAIT
UpdateAllFields
UpdateModifiedFields
VerifyModifiedFields
VerifyAllFields
The behavior exhibited by the container corresponds to the value of the
optimisticConcurrencyBehavior, found in the Table Properties section of
Chapter 16, Using BES Properties for CMP 2.x.
Pessimistic Behavior
In this mode, the container will allow only one transaction at a time to access
the data held by the entity bean. Other transactions seeking the same data will
block until the first transaction has committed or rolled back. This is achieved
by setting the SelectForUpdate table property and issuing a tuned SQL
statement with the FOR UPDATE statement included. You can issue this SQL by
overriding SQL generated from EJB-QL by the CMP engine. For more
information, go to Chapter 17, EJB-QL and Data Access Support. Other
selects on the row are blocked until then. The tuned SQL generated looks like
this:
SELECT ID, NAME FROM EMP_TABLE WHERE ID=? FOR UPDATE
You can also specify the SelectForUpdateNoWAIT table property. Doing so
instructs the database again to lock the row until the current transaction is
committed or rolled back. However, other selects on the row will fail (rather
than blocking). The following SQL illustrates a SELECT statement for the
above:
SELECT ID, NAME FROM EMP_TABLE WHERE ID=? FOR UPDATE NOWAIT
These options should be used with caution. Although it does ensure the
integrity of the data, your application's performance could suffer considerably.
This option will also not function if you are using the Option A cache, since the
entity bean remains in memory in this mode and calls to ejbLoad() are not
made between transactions.
Optimistic Concurrency
This mode permits the container to allow multiple transactions to operate on
the same data at the same time. While this mode is superior in performance,
there is the possibilty that data integrity could be compromised.
The Borland Enterprise Server has four optimistic concurrency behaviors
which are specified as Table Properties. These behaviors are:
SelectForUpdate
SelectForUpdateNoWAIT
UpdateAllFields