Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Enterprise JavaBeans™ Specification, Version 2.0 - Sun Microsystems.pdf
Скачиваний:
14
Добавлен:
24.05.2014
Размер:
2.71 Mб
Скачать

Sun Microsystems Inc

EJB QL Definition

Enterprise JavaBeans 2.0, Public Draft EJB QL: EJB Query Language for Container

The comparison operator IS NOT NULL is used in the conditional expression:

(Single_valued_path_expression| Correlation_variable) IS NOT NULL

This expression tests for the existence of a value designated by the Single_valued_path_expression or

Correlation_variable.

Path expressions containing NULL values during evaluation return NULL values.

10.2.4.14 Finder Expression

A finder expression is used to evaluate an entity bean’s finder method. A finder expressions is a special selection expression utilizing the ejb-name or remote-ejb-name of a bean. Finder expressions allow queries to contain method invocations on the finder methods of an entity bean’s home interface. A finder expression, however, cannot be used to evaluate an entity bean’s select method.

A finder expression has the following syntax:

EjbName>>finder_method_name(Arg1, ..., Argn).

EjbName designates an entity bean. It is either an ejb-name specifying an entity bean in the deployment descriptor or a remote-ejb-name specifying an entity bean in an ejb-entity-ref element. The operator >> locates the home interface of the bean and calls a finder method on the designated entity bean.

The finder method of the entity bean is designated by finder_method_name. The arguments must match those of the signatures of the finder method of the entity bean designated by EjbName. A finder variable, such as ?1, can be used as an argument. Otherwise, the arguments must be literals representing numeric values, string values, or the boolean values TRUE and FALSE.

The Bean Provider must not write a finder query that includes a finder expression using the bean’s own finder methods, because finder queries do not depend on a particular entity object. Therefore, the semantics of such a query cannot be determined.

10.2.5 SELECT Clause

An EJB QL query string may have a SELECT clause which defines the types of values to be selected by the select method. EJB QL query strings for finder methods which are defined in the entity bean’s home interface must not contain a SELECT clause. Select methods, which are defined only within an entity bean’s implementation class, require a SELECT clause to designate the type of values returned by the query. The valid return type for a SELECT clause is determined by the ejbSelect<METHOD> method, as described in Section 9.6.7.

The SELECT clause has the following syntax:

Select_clause ::= SELECT {single_valued_path_expression | correlation_variable}

209

5/31/00

Sun Microsystems Inc.

EJB QL: EJB Query Language for Container Managed Persistence Finder MethodsEnterprise JavaBeans 2.0, Public Draft

EJB QL

The type of the single_valued_path_expression or correlation variable specified in the body of a SELECT clause cannot be the type of an entity bean’s abstract schema. It is illegal to return an abstract schema type in EJB QL. For example, the following query is illegal:

SELECT p FROM l in lineitems, p FOR l.product

The Bean Provider, however, can return remote objects, as in the following query:

SELECT p FROM l in lineitems, p FOR l => product

The ejbSelect<METHOD> method for which this query is specified returns a collection of remote objects of type Product.

The type of the values returned by a query is determined by the type of the SELECT clause. Depending on the type of ejbSelect<METHOD>, different return values are allowed. EJB QL queries that are defined for ejbSelect<name>InEntity methods can return arbitrary types of values permissible by the single_valued_path_expression or the correlation_variable because the values are scoped for an entity bean’s instance. However, the EJB QL queries which are defined for ejbSelect<name> methods must not return values of dependent object classes because such queries are executed in a global context for all entity beans of the same type. Select methods are discussed in detail in Chapter 9.

10.2.6 Null Values

If the target of a reference does not exist in the persistent store, its value is regarded as NULL. SQL 92 NULL semantics define the evaluation of conditional expressions containing NULL values. Here is a brief description of these semantics:

SQL treats a NULL value as unknown. Comparison or arithmetic operations with an unknown value always yield an unknown value.

Path expressions that contain NULL values during evaluation return NULL values.

The IS NULL and IS NOT NULL operators convert a NULL cmp-field or cmr-field value into the respective TRUE or FALSE value.

Boolean operators use three valued logic, defined by the following tables:

Table 0-1 The Definition of the AND Operator

AND

T

F

U

 

 

 

 

T

T

F

U

 

 

 

 

F

F

F

F

 

 

 

 

U

U

F

U

 

 

 

 

5/31/00

210

Sun Microsystems Inc

EJB QL Definition

Enterprise JavaBeans 2.0, Public Draft EJB QL: EJB Query Language for Container

:

Table 0-2 The Definition of the OR Operator

OR

T

F

U

T

T

T

T

 

 

 

 

F

T

F

U

 

 

 

 

U

T

U

U

 

 

 

 

:

Table 0-3 The Definition of the NOT Operator

NOT

 

 

 

T

F

 

 

F

T

 

 

U

U

 

 

10.2.7 Equality

In EJB QL, only like type values can be compared. There is one exception to this rule. It is valid to compare exact numeric values and approximate numeric values (the type conversion required is defined by the rules of Java numeric promotion). The conditional expression is always false when the comparison of non-like type values is attempted.

String and Boolean comparison is restricted to = and <>. Two strings are equal if and only if they contain the same sequence of characters.

Currently, the container managed persistence data model does not support inheritance. Thus, entity beans, dependent objects or value classes of different types cannot be compared. Such comparisons always return false.

Two entity beans of the same abstract schema type are equal if and only if they have the same primary key value.

References to two remote objects are considered equal if and only if the entity objects have the same primary key value.

Two dependent objects are equal if and only if they both have the same type and all their cmp-fields and cmr-fields have the same values. Since dependent objects do not have primary keys or explicit identity, their comparison is based on all persistent data for these beans. Because this comparison might be very expensive, the Bean Provider is discouraged from writing such queries for dependent objects with cmr-fields. Instead, the Bean Provider should compare relevant cmp-fields of dependent objects, according to the requirements of the application, to appropriately determine equality.

211

5/31/00