You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Christoph Hermann <ch...@tu-clausthal.de> on 2005/02/14 14:21:58 UTC

Crash while retrieving Results from a Reportquery and query.setEndAtIndex()

Hello,

i'm having Problems when retrieving Results with a Reportquery.
I set the max number of results to 10 and on the 9th row my loop crashes 
(because in the database there are only 8 rows).
I would expect ojb to only return 8 Rows.

Code snippet:

var crit = new Packages.org.apache.ojb.broker.query.Criteria();
 crit.addEqualToField("logs.menuLinkId","id");
 var q = new 
Packages.org.apache.ojb.broker.query.ReportQueryByCriteria(Packages.nymphoon.MenuLink, 
crit);
  
 var attributes = new Array(3);
 attributes[0] = "logs.menuLinkId";
     attributes[1] = "count(*)";
 attributes[2] = "name";
     q.setAttributes(attributes);
 
 q.addGroupBy("logs.menuLinkId");
 q.addGroupBy("name");
 q.addOrderByDescending("count(*)");
 q.setEndAtIndex(10);
 
 dao.begin();
     var it = dao.getReport (q);
     while ( it.hasNext() ) {
  var o = it.next(); // crash
  suggestions.add(o);
     }
     dao.commit();


The while loop crashes after the 8th Element.
An Iterator of Type broker.accesslayer.PagingIterator (it) is 
instanciated correctly.
I thought that if there are only 8 Rows it.hasNext() would return false?

I could add a try/catch in the inner loop, but i don't think this is a 
good solution.
Can anyone help me with this?

The loop works fine when i set "q.setEndAtIndex(5);" i.e.

Christoph

Re: Crash while retrieving Results from a Reportquery and query.setEndAtIndex()

Posted by Christoph Hermann <ch...@tu-clausthal.de>.
Jakob Braeuchi schrieb:

Hello,

> what do you mean by 'crash' ? could you please post the exception.

hmm of course, sorry that i forgot this :/

The Exception is:

org.apache.cocoon.ProcessingException: Failed to execute pipeline.: 
java.lang.RuntimeException: java.lang.RuntimeException: 
org.apache.avalon.framework.CascadingRuntimeException: 
"file:/usr/local/jakarta-tomcat-4.1.31/webapps/cocoon_2.1.6/samples/guschtel/nymphoon/flow/authentication.js", 
line 318: uncaught JavaScript exception: at displayMenu 
(file:/usr/local/jakarta-tomcat-4.1.31/webapps/cocoon_2.1.6/samples/guschtel/nymphoon/flow/authentication.js, 
Line 318): 

java.util.NoSuchElementException: Could not obtain next object: inner 
hasNext was false

317: while ( it.hasNext() ) {
318:   var o = it.next(); // crashes here
319:   suggestions.add(o);
320: }

Christoph

Re: Crash while retrieving Results from a Reportquery and query.setEndAtIndex()

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi christoph,

what do you mean by 'crash' ? could you please post the exception.

jakob

Christoph Hermann schrieb:
> Hello,
> 
> i'm having Problems when retrieving Results with a Reportquery.
> I set the max number of results to 10 and on the 9th row my loop crashes 
> (because in the database there are only 8 rows).
> I would expect ojb to only return 8 Rows.
> 
> Code snippet:
> 
> var crit = new Packages.org.apache.ojb.broker.query.Criteria();
>  crit.addEqualToField("logs.menuLinkId","id");
>  var q = new 
> Packages.org.apache.ojb.broker.query.ReportQueryByCriteria(Packages.nymphoon.MenuLink, 
> crit);
>   
>  var attributes = new Array(3);
>  attributes[0] = "logs.menuLinkId";
>      attributes[1] = "count(*)";
>  attributes[2] = "name";
>      q.setAttributes(attributes);
>  
>  q.addGroupBy("logs.menuLinkId");
>  q.addGroupBy("name");
>  q.addOrderByDescending("count(*)");
>  q.setEndAtIndex(10);
>  
>  dao.begin();
>      var it = dao.getReport (q);
>      while ( it.hasNext() ) {
>   var o = it.next(); // crash
>   suggestions.add(o);
>      }
>      dao.commit();
> 
> 
> The while loop crashes after the 8th Element.
> An Iterator of Type broker.accesslayer.PagingIterator (it) is 
> instanciated correctly.
> I thought that if there are only 8 Rows it.hasNext() would return false?
> 
> I could add a try/catch in the inner loop, but i don't think this is a 
> good solution.
> Can anyone help me with this?
> 
> The loop works fine when i set "q.setEndAtIndex(5);" i.e.
> 
> Christoph

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org