12.11.2014 Views

web server - Borland Technical Publications

web server - Borland Technical Publications

web server - Borland Technical Publications

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter<br />

17<br />

17EJB-QL and Data Access Support<br />

Chapter<br />

Important<br />

EJB-QL allows you to specify queries in an object oriented query language, EJB-QL.<br />

The <strong>Borland</strong> CMP engine translates these queries into SQL queries. The <strong>Borland</strong><br />

Enterprise Server provides some extensions to the EJB-QL functionality described in<br />

the Sun Microsystems EJB 2.x Specification.<br />

For documentation updates, go to www.borland.com/techpubs/bes.<br />

Selecting a CMP Field or Collection of CMP Fields<br />

When only one cmp-field of an otherwise large EJB is required, you can use EJB-QL to<br />

select a single instance of collection of that cmp-field. Using EJB-QL in this way<br />

improves application performance by eliminating the need to load an entire EJB. For<br />

example, this query method selects only the balance field from the Account table:<br />

<br />

<br />

ejbSelectBalanceOfAccountLineItem<br />

<br />

java.lang.Long<br />

<br />

<br />

Local<br />

SELECT l.balance FROM Account a, IN (a.accountLineItem) l WHERE<br />

l.lineItemId=?1<br />

<br />

The return types of the EJB-QL query method are:<br />

■<br />

■<br />

■<br />

■<br />

If the Java type of the cmp-field is an object type, and the query method is a singleobject<br />

query method, the return type is an instance of that object type.<br />

If the Java type of the cmp-field is an object type and the query method returns<br />

multiple objects, a collection of instances of the object type is returned.<br />

If the Java type of the cmp-field is a primitive Java type, and the SELECT method is<br />

a single-object method, the return type is that primitive type.<br />

If the Java type of the cmp-field is a primitive Java type, and the SELECT method is<br />

for multiple objects, a collection of the wrappered Java type is returned.<br />

Chapter 17: EJB-QL and Data Access Support 153

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

Saved successfully!

Ooh no, something went wrong!