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 />

This section illustrates some of the information that needs to be provided for containermanaged<br />

finder methods, particularly if you are constructing container-managed finder<br />

methods at the command line level. Because it is not an exhaustive reference, you<br />

should refer to the DTD of the deployment descriptor for the detailed syntax. Look for<br />

the syntax for the finder methods and Object-Relation (OR) mapping metadata.<br />

Constructing finder methods<br />

When you construct a finder method, you are actually constructing an SQL select<br />

statement with a where clause. The select statement includes a clause that states what<br />

records or data are to be found and returned. For example, you might want to find and<br />

return checking accounts in a bank. The where clause of the select statement sets<br />

limits on the selection process; that is, you might want to find only those checking<br />

accounts with a balance greater than some specified amount, or accounts with a<br />

certain level of activity per month. When the Container uses container-managed<br />

persistence, you must specify the terms of the where clause in the deployment<br />

descriptor.<br />

For example, suppose you have a finder method called findAccountsLargerThan(int<br />

balance) and you are using container-managed persistence. This finder method<br />

attempts to find all bank accounts with a balance greater than the specified value.<br />

When the Container executes this finder method, it actually executes a select<br />

statement whose where clause tests the account balances against the int value<br />

passed as a parameter to the method. Because we're using container-managed<br />

persistence, the deployment descriptor needs to specify the conditions of the where<br />

clause; otherwise, the Container does not know how to construct the complete select<br />

statement.<br />

The value of the where clause for the findAccountsLargerThan(int balance)method is<br />

“balance > :balance“. In English, this translates to: “the value of the balance column is<br />

greater than the value of the parameter named balance.” (Note that there is only one<br />

argument to the finder method, an int value.)<br />

The default container-managed persistence implementation supports this finder<br />

method by constructing the complete SQL select statement, as follows:<br />

select * from Accounts where ? > balance<br />

The CMP engine then substitutes “?” with the int parameter. Lastly, the engine<br />

converts the result set into either an Enumeration or Collection of primary keys, as<br />

required by the EJB Specification.<br />

It is possible to inspect the various SQL statements that the CMP implementation<br />

constructs. To do this, enable the EJBDebug flag on the container. When that flag is<br />

enabled, it prints the exact statements constructed by the Container.<br />

While other EJB Container products use code generation to support CMP, the <strong>Borland</strong><br />

Container does not use code generation because it has serious limitations. For<br />

example, code generation makes it difficult to support a “tuned update” feature,<br />

because of the great number of different update statements to container-managed<br />

fields that are required.<br />

Constructing the where clause<br />

The where clause is a necessary part of select statements when you want to delimit the<br />

extent of the returned records. Because the where clause syntax can be fairly complex,<br />

you must follow certain rules in the XML deployment descriptor file so that the EJB<br />

Container can correctly construct this clause.<br />

To begin with, you are not obligated to use the literal “where” in your .<br />

You can construct a where clause without this literal and rely on the Container to<br />

supply it. However, the Container only does this if the is not an empty<br />

string; it leaves empty strings empty. For example, you could define a where clause as<br />

either:<br />

116 BES Developer’s Guide

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

Saved successfully!

Ooh no, something went wrong!