Exforsys.com
 

Sponsored Links

 

SCBCD Tutorials

 
Home Certification SCBCD
 

SCBCD Study Notes : Chapter 9 : EJB-QL (Part-1)

 

SCBCD Study Notes : Chapter 9 : EJB-QL (Part-1)

Page 1 of 2

SCBCD Study Notes : Chapter 9 : EJB-QL (Part-1)

Please find the Study Notes and resources which covers 1st Part of Chapter 9 : EJB-QL, as part of the Sun Certified Business Component Developer exam CX-310-090.


1. Identify correct and incorrect syntax for an EJB QL query including the SELECT, FROM, and WHERE clauses.


Chapter 9 : EJB-QL

Identify correct and incorrect syntax for an EJB QL query including the SELECT, FROM, and WHERE clauses.

EJB QL is a query specification language for the FINDER and SELECT methods of entity beans with container-managed persistence (CMP). EJB QL can be compiled to a target language, such as SQL, of a database or other persistent store. This allows the execution of queries to be shifted to the native language facilities provided by the persistent store, instead of requiring queries to be executed on the runtime representation of the entity beans' state. As a result, query methods can be optimizable as well as portable.


The Enterprise JavaBeans query language uses the abstract persistence schemas of entity beans, including their relationships, for its data model. It defines operators and expressions based on this data model. The Bean Provider uses EJB QL to write queries based on the abstract persistence schemas and the relationships defined in the deployment descriptor. EJB QL depends on navigation and selection based on the cmp-fields and cmr-fields of the related entity beans. The Bean Provider can navigate from an entity bean to other entity beans by using the names of cmr-fields in EJB QL queries.


When defining EJB QL, we are limited to referring only to elements described below:


  • Names of the entity beans defined in the abstract schema. Each bean by default is given the schema name of the bean (such as Customer, which is defined in the abstract-schema-name xml tag in DD).

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
< entity > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;< ejb-name >CustomerEJB< / ejb-name > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;... ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;< abstract-schema-name >Customer< / abstract-schema-name > ;;;;;;;;;;;;
;;;;;;;... ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
< / entity >
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


  • CMP field names within these beans (such as firstName, lastName, anything in a cmp-field tag in DD).

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
< entity >;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;< ejb-name > CustomerEJB < / ejb-name > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;...;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;< abstract-schema-name > Customer < / abstract-schema-name >;;;;;;;;;;;;;;
;;;;< cmp-field > < field-name > id < / field-name > < /cmp-field >;;;;;;;;;;;
;;;;< cmp-field > < field-name > lastName < / field-name > < /cmp-field >;;;;;
;;;;< cmp-field > < field-name > firstName < / field-name > < /cmp-field >;;;;
;;;;< cmp-field > < field-name > hasGoodCredit < / field-name > < /cmp-field >
;;;;...;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
< / entity >;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


  • CMR field names within these beans to navigate along relationships (such as anything defined in a cmr-field).

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
< ejb-relation >;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;< ejb-relation-name > Customer-HomeAddress < / ejb-relation-name >;;;;;;;
;;;;;< ejb-relationship-role >;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;< ejb-relationship-role-name >;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;Customer-has-a-Address;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;< / ejb-relationship-role-name >;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;; One < / multiplicity >;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;< relationship-role-source >;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;< ejb-name > CustomerEJB < / ejb-name >;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;< / relationship-role-source >;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;< cmr-field >;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;< cmr-field-name > homeAddress < / cmr-field-name >;;;;;;;;;;;;
;;;;;;;;;;< / cmr-field >;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;< / ejb-relationship-role >;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;< ejb-relationship-role >;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;...;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;< / ejb-relationship-role >;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
< / ejb-relation >;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


An EJB QL query is a string which consists of the following three clauses:


  • a SELECT clause, which determines the TYPE of the objects or values to be selected.
    .
  • a FROM clause, which provides declarations that designate the DOMAIN to which the expressions specified in the SELECT clause and WHERE clause of the query apply.
    .
  • an optional WHERE clause, which may be used to RESTRICT the results that are returned by the query.

EJB QL :: = SELECT_clause FROM_clause [WHERE_clause]


An EJB QL query MUST always have a SELECT and a FROM clause. The WHERE clause is OPTIONAL.


An EJB QL query MAY have parameters that correspond to the parameters of the finder or select method for which it is defined.


An EJB QL query is statically defined in the ejb-ql deployment descriptor element. There must be ONE ejb-ql tag per query definition for each finder and select method.


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
< entity > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;< ejb-name > CustomerEJB < / ejb-name > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;... ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;< abstract-schema-name > Customer ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;< cmp-field > < field-name > id ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;< cmp-field > < field-name > lastName ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;< cmp-field > < field-name > firstName ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;< cmp-field > < field-name > hasGoodCredit ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;... ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;< query > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;< query-method > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;< method-name > findByName < / method-name > ;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;< method-params > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;< method-param > java.lang.String < / method-param > ;;;;;
;;;;;;;;;;;;;;;;;;;;< method-param > java.lang.String < / method-param > ;;;;;
;;;;;;;;;;;;;;;< / method-params > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;< / query-method > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;< ejb-ql > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;SELECT OBJECT(c) FROM Customer c ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;WHERE c.lastName = ?1 AND c.firstName = ?2 ;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;< / ejb-ql > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;< / query > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;< query > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;< query-method > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;< method-name > findByGoodCredit < / method-name > ;;;;;;;;;;;;
;;;;;;;;;;;;;;;< method-params / > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;< / query-method > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;< ejb-ql > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;SELECT OBJECT(c) FROM Customer c ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;WHERE c.hasGoodCredit = TRUE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;< / ejb-ql > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;< / query > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;< query > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;< query-method > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;< method-name > ejbSelectLastNames < / method-name > ;;;;;;;;;;
;;;;;;;;;;;;;;;< method-params / > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;< / query-method > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;< ejb-ql > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;SELECT c.lastName FROM Customer AS c ;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;< / ejb-ql > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;< / query > ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;... ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
< / entity >;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



EJB QL is used for two types of query methods:


  • FINDER METHODS. Finder methods are defined in the HOME interface(s) of an entity bean and return entity objects or local entity objects (NOTE, they can return ONLY COMPONENT INTERFACES). A finder method that is defined on the remote home interface must return either an EJBObject or a collection of EJBObjects; a finder method that is defined on the local home interface must return either an EJBLocalObject or a collection of EJBLocalObjects. The result type of a finder method defined on the remote home interface of an entity bean is the entity bean's remote interface (or a collection of objects implementing the entity bean's remote interface). The result type of a finder method defined on the local home interface of an entity bean is the entity bean's local interface (or a collection of objects implementing the entity bean's local interface).
    .
  • SELECT METHODS. Select methods are a special type of query method NOT DIRECTLY EXPOSED through the client view. The Bean Provider typically uses select methods to select the persistent state of an entity object or to select entities that are related to the entity bean for which the query is defined. The result type of a select method can be an EJBLocalObject (or a collection of EJBLocalObjects), an EJBObject (or a collection of EJBObjects), or a cmp-field value (or a collection of such). NOTE, the SELECT method can return not only component interfaces, but also java.lang.Object, or COLLECTION of java.lang.Object.

Next Page: SCBCD Study Notes : Chapter 9 : EJB-QL (Part-1) - Page 2


Read Next: SCBCD Study Notes : Chapter 9 : EJB-QL (Part-2)



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 

Subscribe via RSS


Get Daily Updates via Subscribe to Exforsys Free Training via email


Get Latest Free Training Updates delivered directly to your Inbox...

Enter your email address:


 

Subscribe to Exforsys Free Training via RSS
 

 
Partners -  Privacy and Legal Policy -  Site News -  Contact   Sitemap  

Copyright © 2000 - 2009 exforsys.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape