user manual

Chapter 14: Entity Beans and CMP 1.1 in Borland Enterprise Server 137
Container-Managed Persistence in Borland Enterprise Server
Providing CMP metadata to the Container
According to the EJB Specification, the deployer must provide CMP metadata
to the EJB container. The Borland Container captures the CMP-relevant
metadata in the XML deployment descriptor. Specifically, the Borland
Container uses the vendor-specific portion of the deployment descriptor for
the CMP metadata.
This section illustrates some of the information that needs to be provided for
container-managed finder methods, particularly if you are constructing
container-managed finder methods at the command line level. Because it is
not an exhaustive reference, you should refer to the DTD of the deployment
descriptor for the detailed syntax. Look for the syntax for the finder methods
and Object-Relation (OR) mapping metadata.
Constructing finder methods
When you construct a finder method, you are actually constructing an SQL
select statement with a where clause. The select statement includes a clause
that states what records or data are to be found and returned. For example,
you might want to find and return checking accounts in a bank. The where
clause of the select statement sets limits on the selection process; that is, you
might want to find only those checking accounts with a balance greater than
some specified amount, or accounts with a certain level of activity per month.
When the Container uses container-managed persistence, you must specify
the terms of the where clause in the deployment descriptor.
For example, suppose you have a finder method called
findAccountsLargerThan(int balance) and you are using container-managed
persistence. This finder method attempts to find all bank accounts with a
balance greater than the specified value. When the Container executes this
finder method, it actually executes a select statement whose where clause
tests the account balances against the int value passed as a parameter to the
method. Because we're using container-managed persistence, the
deployment descriptor needs to specify the conditions of the where clause;
otherwise, the Container does not know how to construct the complete select
statement.
The value of the where clause for the findAccountsLargerThan(int
balance)method is "balance > :balance". In English, this translates to: "the value
of the balance column is greater than the value of the parameter named
balance." (Note that there is only one argument to the finder method, an int
value.)
The default container-managed persistence implementation supports this
finder method by constructing the complete SQL select statement, as follows:
select * from Accounts where ? > balance
The CMP engine then substitutes "?" with the int parameter. Lastly, the
engine converts the result set into either an Enumeration or Collection of primary
keys, as required by the EJB Specification.
It is possible to inspect the various SQL statements that the CMP
implementation constructs. To do this, enable the EJBDebug flag on the