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

Note<br />

or:<br />

where a = b <br />

a = b <br />

The Container converts a = b to the same where clause, where a = b. However, it leaves<br />

unmodified an empty string defined as “” .<br />

The empty string makes it easy to specify the findAll() method. When you specify just<br />

an empty string, the Container construes that to mean the following:<br />

select [values] from [table];<br />

Such a select statement would return all values from a particular table.<br />

Parameter substitution<br />

Parameter substitution is an important part of the where clause. The <strong>Borland</strong> EJB<br />

Container does parameter substitution wherever it finds the standard SQL substitution<br />

prefix colon (:). Each parameter for substitution corresponds to a name of a parameter<br />

in the finder specification found in the XML descriptor.<br />

For example, in the XML deployment descriptor, you might define the following finder<br />

method which takes a parameter balance (note that balance is preceded by a colon):<br />

<br />

findAccountsLargerThan(float balance)<br />

balance > :balance<br />

<br />

The Container composes a SQL select statement whose where clause is:<br />

balance > ?<br />

Note that the :balance parameter in the deployment descriptor becomes a question<br />

mark (?) in the equivalent SQL statement. When invoked, the Container substitutes the<br />

value of the parameter :balance for the ? in the where clause.<br />

Compound parameters<br />

The Container also supports compound parameters; that is, the name of a table<br />

followed by a column within the table. For this, it uses the standard dot (.) syntax,<br />

where the table name is separated from the column name by a dot. These parameters<br />

are also preceded by a colon.<br />

For example, the following finder method has the compound parameters :address.city<br />

and :address.state:<br />

<br />

findByCity(Address address)<br />

city = :address.city AND state = :address.state<br />

<br />

The where clause uses the city and state fields of the address compound object to<br />

select particular records. The underlying Address object could have Java Beans-style<br />

getter methods that correspond to the attributes city and state. Or, alternatively, it<br />

could have public fields that correspond to the attributes.<br />

Entity beans as parameters<br />

An entity bean can also serve as a parameter in a finder method. You can use an entity<br />

bean as a compound type. To do so, you must tell the CMP engine which field to use<br />

from the entity bean's passed reference to the SQL query. If you do not use the entity<br />

bean as a compound type, then the Container substitutes the bean's primary key in the<br />

where clause.<br />

For example, suppose you have a set of OrderItems entity beans associated with an<br />

Order entity object. You might have the following finder method:<br />

Chapter 14: Entity Beans and CMP 1.1 in <strong>Borland</strong> Enterprise Server 117

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

Saved successfully!

Ooh no, something went wrong!