On 10/06/2008, at 5:37 PM, Andrus Adamchik wrote:
> On Jun 10, 2008, at 10:31 AM, Lachlan Deck wrote:
>
>> Perhaps I should describe what I'm actually doing. All I need is a
>> way to get a count of a select query (without having to fault in
>> all the related objects). So is there a way to trigger that, in
>> order to just get a count back, with a SelectQuery without going
>> the sqltemplate or namedquery route?
>
> I think EJBQL route is the way to go for aggregate object queries.
> In fact Expression has 'toEJBQLString' method, but you may not even
> care about it. Anyways here is an example:
>
> EJBQLQuery countQuery = new EJBQLQuery("SELECT count(a) FROM Artist
> a WHERE a.artistName like 'A%'");
> Number count = (Number) DataObjectUtils.objectForQuery(countQuery);
Okay, so I've got this...
public int allRecordsCount(Expression e) {
ObjEntity entity =
getContext().getEntityResolver().lookupObjEntity(getObjectClass());
Expression qualifier = null;
<...>
String ejbqlWhereString = qualifier == null ? "" : " WHERE " +
qualifier.toEJBQL("a");
String ejbqlQueryString = "SELECT count(a) FROM " + entity.getName()
+ " a" + ejbqlWhereString;
EJBQLQuery ejbqlQuery = new EJBQLQuery(ejbqlQueryString);
Number count = (Number) DataObjectUtils.objectForQuery(getContext(),
ejbqlQuery);
return count.intValue();
}
But I'm getting this exception. Any ideas?
org.apache.cayenne.CayenneRuntimeException: [v.3.0-SNAPSHOT May 14
2008 22:35:23] Remote error. URL - http://delish.ish.com.au:8181/angel-server-cayenne
; CAUSE - Serialized class
org.apache.cayenne.query.SQLResultSetMapping must implement
java.io.Serializable
[java] at
org
.apache
.cayenne
.remote.hessian.HessianConnection.doSendMessage(HessianConnection.java:
147)
[java] at
org
.apache.cayenne.remote.BaseConnection.sendMessage(BaseConnection.java:
73)
[java] at
org.apache.cayenne.remote.ClientChannel.send(ClientChannel.java:281)
[java] at
org.apache.cayenne.remote.ClientChannel.onQuery(ClientChannel.java:113)
[java] at
org
.apache
.cayenne
.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:
317)
[java] at
org
.apache
.cayenne
.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:96)
[java] at
org.apache.cayenne.CayenneContext.onQuery(CayenneContext.java:340)
[java] at
org.apache.cayenne.CayenneContext.performQuery(CayenneContext.java:328)
[java] at
ish.oncourse.cayenne.CayenneContext.performQuery(CayenneContext.java:
292)
[java] at
org.apache.cayenne.DataObjectUtils.objectForQuery(DataObjectUtils.java:
274)
[java] at
ish
.oncourse
.controller.ListController.allRecordsCount(ListController.java:482)
with regards,
--Lachlan Deck
This archive was generated by hypermail 2.0.0 : Tue Jun 10 2008 - 04:17:44 EDT