persistence@glassfish.java.net

RE: Multiple Return types EJBQL

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Tue, 1 Nov 2005 16:14:28 -0500

Hello Michael,
        There are two reasons for our use of ReadAllQuery. The first and most important is caching. By using the ReadAllQuery we can cache results, even avoid certain queries for selectSingleResult. The second is that until the code I checked in was finished the ReportQuery could not return entities. It would be preferable if the ReadAllQuery could continue to be built except in cases where a ReportQuery is required.

        You can use the class of the first entity class in the FROM clause. The reference class is used as the base for the expressions used by the query. The query's ExpressionBuilder will have the class type set in the query.
I am not being the clearest here so if you have any more questions please feel free to ask. I will try to expand my answers.
--Gordon

-----Original Message-----
From: Michael Bouschen [mailto:Michael.Bouschen_at_Sun.COM]
Sent: Tuesday, November 01, 2005 11:34 AM
To: Gordon Yorke
Cc: tlcore_ca; persistence_at_glassfish.dev.java.net
Subject: Re: Multiple Return types EJBQL


Hi Gordon,

thanks for the info.

Yes, I saw your checkin and started looking into adding support for
EJBQL queries with multiple expressions in the SELECT clause. The
example setup code helps (e.g. I was not aware of method
returnWithoutReportQueryResult).

However, I still have some questions and hope you can help:

(1) Both examples use a ReportQuery. The current EJBQL code creates an
ReadAllQuery if the SELECT clause uses an identification variable
"SELECT c FROM Customer c". In all other cases it creates a ReportQuery.
Is there any specific reason to create a ReadAllQuery (and not a
ReportQuery) for the above EJBQL? It would be easier if we could always
create a ReportQuery for an EJBQL SELECT query.

(2) What is the reference class in case of multiple expressions
selecting values from different classes? E.g.
   SELECT c.name, o.totalPrice FROM Order o JOIN o.customer c
And what is it if one of the expression selects an association field?
   SELECT o.customer, o.orderId, o.totalPrice FROM Order o

Regards Michael


> Hello Michael,
> I'm not sure how Tom generally organises these feature notifications but i have compeleted (and checked into CVS) the work required to return multiple return types in a single EJBQL query (ie Select o.customer, o.id, FROM Order o where o.customer.name='Somename')
>
> To support this type of selection a TopLink ReportQuery should be used. Each of the selection items (ie o.customer) can be added as an attribute. So as an example the setup code for the above EJBQL would be:
>
> ReportQuery reportQuery = new ReportQuery();
> reportQuery.returnWithoutReportQueryResult();
> reportQuery.setReferenceClass(Order.class);
> ExpressionBuilder orderBuilder = reportQuery.getExpressionBuilder();
> reportQuery.addAttribute("someString-a",empbuilder.get("customer"));
> reportQuery.addAttribute("someString-b",empbuilder.get("id"));
> reportQuery.setSelectionCriteria(empbuilder.get("customer").get("name").equal("Somename");
>
>
>
> Selecting a base object for a query like SELECT c FROM Customer c can be completed as follows:
>
> ReportQuery reportQuery = new ReportQuery();
> reportQuery.returnWithoutReportQueryResult();
> reportQuery.setReferenceClass(Customer.class);
> ExpressionBuilder customerBuilder = reportQuery.getExpressionBuilder();
> reportQuery.addAttribute("someString-a", empbuilder);
>
> This is not quite straight forward so if you have any questions please feel free to ask.
> --Gordon
> __
> Gordon Yorke
> Senior Software Engineer
> TopLink
> Oracle Canada
> <http://www.oracle.com/>
> Main: (613) 783-4585
> Email: gordon.yorke_at_oracle.com
>
>