Unformatted text preview:

Enterprise JavaBeans 2 0 Cont d Wu Lu EJB2 0 Query Language EJB QL is a declarative language similar in many respects to SQL Is intended to be portable to all EJB2 0 compliant containers and persistence managers The Usage of Find Method in EJB1 1 Declare find method in home interface Modify the xml file C orion application deployments factory ejbs orion ejb jar xml finder method query finder method query status LIKE o Advange of Query Language QL Developed and tested once Use anywhere Methods which use QL Finder Methods Select Methods 1 They are not exposed to clients They are used in the implementation class alone They allow the programmer to retrieve dependent objects values or related EJBs based on relevant search criteria 2 Advantages of using a select method A select method written in QL can be more efficient than java programming Declarative SQL language is more maintainable and less error prone Types of Select Method ejbSelect METHOD Operate on all instances of that entity Can return individual instances or collections of any type represented by a cmp field as well as remote interfaces represented by a cmr field ejbSelect METHOD InEntity Associated with a particular entity identity Can not be used from the implementations of a home interface business method Introduced as a way of efficiently navigating the EJBs relationships with other entity beans and with its dependent objects METHOD represents a descriptive name for the activity of the method Where to specify a Query A query is specified in two parts Method declaration Specify the QL in XML deployment descriptor Method declaration 1 Find Method Declared in the home interface just as it is for EJB1 1 cmp Returning the remote interface type Must have a name of the form findByXXX Throw RemoteException and FinderException Method declaration 2 Select Method 1 Declared as abstract in the bean s main implementation class 2 Must have a name of the form ejbSelect METHOD or ejbSelect METHOD InEntity 3 Throw javax ejb FinderException 4 Return type can be individual instances or collections of any type of cmp field and cmr field 5 The collection class must be either java util Collection or java util Set Public abstract class SportTeamEJB implements EntityBean abstract public String ejbSelectShipToCityInEntity throws FinderExecption Specify query language 1 Specify in the XML deployment descriptor 2 A query is defined as a query element as a child of the relevant entity element 3 A query has 3 parts an optional description a method it applied the query language string query query method method name ejbSelectOverdueLibraryBooksInEntity method name method params query method ejb ql SELECT b FROM b in books WHERE overdue is TRUE ejb ql query How to specify a query An EJB QL string may have up to 3 clauses 1 Select indicate the return type of the query or of the instances in a returned collection 2 From declare variables that represent navigation paths in your schema correlation variables These variables are used in SELECT or WHERE clauses 3 Where a conditional expression that limits the results of your query It can include parameters from the finder or select method The concept of schema Is the definition of its cmp fields and cmr fields A schema type has a name Entity bean the name is specified in the deployment descriptor with the element abstract schema name Dependent object same as the dependent object name The concept of schema Every query in an entity bean must use that bean s schema or the schema of a related objects in the same ejb jar for navigation A bean s schema is different from its remote interface Can not refer to a schema of an entity or dependent object that is defined outside your ejb jar You may call finder methods on entities outside your JAR but you may not navigate to their dependent objects or refer to their state OrderBean Number custname lineitems Address dependent object street city Order date state Shippine address Postal code Billing address Lineitem dependent object ProductBean product name quantity description shipped type Navigation Operator Use navigation operator to traverse cmp and cmrfields SELECT shipping address city String ejbSelectShipToCityInEntity throws FinderException Java util Collection ejbSelectShipToCity throws FinderException Java util Set ejbSelectShipToCity throws FinderException SELECT shipping address WHERE shipping address state NY WHERE billing address state MA Navigating Over Collections Can not use navigation operator to navigate into a many valued relationship SELECT lineitems product name WHERE lineitems shipped TRUE Declare a correlation variable in the From clause SELECT 1 product name FROM 1 in lineitems WHERE 1 shipped TRUE Input Parameters To parameterize a query 1 Add the appropriate parameters to the method declaration 2 Refer to those parameters in the WHERE clause with a question mark followed by a index of the parameter in the method declaration 3 Date literals need to be expressed as a standard Java long milliseconds value OrderEJB findByCustomerName String custname throws FinderException WHERE custname 1 Other Entity Beans Query references to entity beans that are within the same ejb jar and use the EJB2 0 persistence model represent a schema SELECT 1 product name FROM 1in lineitems WHERE 1 shipped TRUE Query references to entity beans that are outside the eib jar or use the EJB1 1 persistence model represent the remote interface of the entity bean SELECT 1 product FROM 1in lineitems WHERE 1 shipped TRUE The remote interface navigation operation SELECT 1 product FROM 1 in lineitems WHERE 1 shipped true Where Clause Options Logical operator NOT AND OR Comparison operator Types number string boolean object Comparison for entity bean remote references or schemas are done by compare their primary key values Comparison for dependent objects are also probably done by compare their primary key values Arithmetic operators BETWEEN expression NOT BETWEEN x AND y IN expression NOT IN string Entity reference NOT IN finder expression LIKE expression NOT LIKE pattern ESCAPE character representing any single character representing any sequence of zero or more characters NULL test IS NOT NULL Queries from the Manufacturing Application 1 Location application server specific file 2 Format application server specific format finder method query status LIKE o method ejb name Orders ejb name method name findOpenOrders method name method params method params method finder method finder


View Full Document

WVU CS 486 - Enterprise JavaBeans 2.0

Course: Cs 486-
Pages: 31
Loading Unlocking...
Login

Join to view Enterprise JavaBeans 2.0 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Enterprise JavaBeans 2.0 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?