12.11.2014 Views

web server - Borland Technical Publications

web server - Borland Technical Publications

web server - Borland Technical Publications

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Container-Managed Persistence in <strong>Borland</strong> Enterprise Server<br />

■<br />

■<br />

VerifyModifiedFields<br />

VerifyAllFields<br />

The behavior exhibited by the container corresponds to the value of the<br />

optimisticConcurrencyBehavior table properties. See Chapter 16, “Using BES<br />

Properties for CMP 2.x.”<br />

Pessimistic Behavior<br />

In this mode, the container will allow only one transaction at a time to access the data<br />

held by the entity bean. Other transactions seeking the same data will block until the<br />

first transaction has committed or rolled back. This is achieved by setting the<br />

SelectForUpdate table property and issuing a tuned SQL statement with the FOR UPDATE<br />

statement included. You can issue this SQL by overriding the SQL generated by the<br />

CMP engine. See Chapter 17, “EJB-QL and Data Access Support.” Other selects on<br />

the row are blocked until then. The tuned SQL generated looks like this:<br />

SELECT ID, NAME FROM EMP_TABLE WHERE ID=? FOR UPDATE<br />

You can also specify the SelectForUpdateNoWAIT table property. Doing so instructs the<br />

database again to lock the row until the current transaction is committed or rolled back.<br />

However, other selects on the row will fail (rather than blocking). The following SQL<br />

illustrates a SELECT statement for the above:<br />

SELECT ID, NAME FROM EMP_TABLE WHERE ID=? FOR UPDATE NOWAIT<br />

These options should be used with caution. Although it does ensure the integrity of the<br />

data, your application's performance could suffer considerably. This option will also not<br />

function if you are using the Option A cache, since the entity bean remains in memory<br />

in this mode and calls to ejbLoad() are not made between transactions.<br />

SelectForUpdate<br />

SelectForUpdateNoWA<br />

IT<br />

UpdateAllFields<br />

Optimistic Concurrency<br />

This mode permits the container to allow multiple transactions to operate on the same<br />

data at the same time. While this mode is superior in performance, there is the<br />

possibility that data integrity could be compromised.<br />

The <strong>Borland</strong> Enterprise Server has four optimistic concurrency behaviors which are<br />

specified as Table Properties. These behaviors are:<br />

■<br />

SelectForUpdate<br />

■<br />

SelectForUpdateNoWAIT<br />

■<br />

UpdateAllFields<br />

■<br />

UpdateModifiedFields<br />

■<br />

VerifyModifiedFields<br />

■<br />

VerifyAllFields<br />

Use this option for pessimistic concurrency. With this option specified, the database<br />

locks the row until the current transaction is committed or rolled back. Other selects on<br />

the row are blocked until then.<br />

Use this option for pessimistic concurrency. With this option specified, the database<br />

locks the row until the current transaction is committed or rolled back. Other selects on<br />

the row will fail.<br />

With this option specified, the container issues an update on all fields, regardless of<br />

whether or not they were modified. For example, consider a CMP entity bean with three<br />

fields, KEY, VALUE1, and VALUE2. The following update will be issued at the terminus<br />

of every transaction, regardless of whether or not the bean was modified:<br />

UPDATE MyTable SET (VALUE1 = value1, VALUE2 = value2) WHERE KEY = key<br />

Chapter 15: Entity Beans and Table Mapping for CMP 2.0 131

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!