BTW, you may also look at the new EJBQLQuery in Cayenne 3.0. M1 supports only the simplest SELECT queries, while the upcoming M2 supports 99% of the JPA mandated syntax. While this is somewhat of a bleeding edge, it should simplify custom aggregate queries significantly.

http://cayenne.apache.org/doc/ejbqlquery.html

Andrus


On Oct 9, 2007, at 5:21 PM, David Marko wrote:

Thanks, its really what I needed.

The reason why I asked is as follow. The EntityManager for Cayenne (my previous post) offers aggregate functions (count, sum, average, max). To accomblish this I created SelecteQuery e.g. q="SELECT COUNT(*) as count, $name as name FROM ROLE GROUP BY $name"; for queries with 'where' constrains I use special Query syntax(wrapper for cayenne expression) and I need the 'where' clause to be put into manualy created 'select count(*) .... ' query. Not easy to explain without
detailed code though.

// and this is how I call it: em is EntityManager
List<DataRow> li= em.count(Item.class, Item.NAME_PROPERTY, Query.where("year >
$year").addParam("year", 2003));

// or sum
List<DataRow> li= em.sum(Item.class, Item.PROFIT_PROPERTY,
Item.PRODUCT_NAME_PROPERTY, Query.where("year > $year").addParam ("year", 2003));


David

Michael Gentry wrote:
Will:

Expression exp = sq.getQualifier();
String clause = exp.toString();

do what you are wanting?


On 10/9/07, David Marko <[EMAIL PROTECTED]> wrote:
Hello, I need to create a select query that have some parameters and I need to get SQL where statement from it containing replaced parameters. (see snippet
below) . Is there any way how to accomplish this?


[Code snippet]
SelectQuery sq = new
SelectQuery(Role.class,Expression.fromString(this.whereClause));
return sq.queryWithParameters(params);





Reply via email to