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 pgpcucCVfioa7.pgp Description: PGP signature
Getting Started With OJB
I found the object/relational bridge from a Struts book I was reading. The book suggested this type of technology, but did not give any information on configuring the OJB. So I downloaded the binaries for 1.0.1 and began reading the tutorial. Before I get too deep, I just want to be able to do some simple selects/joins for some data in a simple web app I am writing using struts. Upon following the docs, I clicked the link for ' http://db.apache.org/ojb/docu/tutorials/odmg-tutorial.html ODMG Tutorial ' and created the Product.java file. Then I moved to the 'Tutorial Mapping' link and created the table product in MYSQL. It then talks about a repository.xml doc and a user-repository.xml document. It shows some xml, but I do not know if it is the user- or the repository.xml. class-descriptor class=org.apache.ojb.tutorials.Product table=Product field-descriptor name=id column=id primarykey=true autoincrement=true / field-descriptor name=name column=name / field-descriptor name=price column=price / field-descriptor name=stock column=stock / /class-descriptor I do not know which one the above is and where it should live in my webapp? And then there is the question of the other xml document. Could someone help me just help me create the proper setup, tell me where things live, and get me underway with a select and an update of the simple product table? Thanks, Scott
Re: Crash while retrieving Results from a Reportquery and query.setEndAtIndex()
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 pgpOsS4vqFqk2.pgp Description: PGP signature
Re: Crash while retrieving Results from a Reportquery and query.setEndAtIndex()
Antonio Gallardo schrieb: Hello, 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: } Thanks. This is inside Cocoon Flow. Seems that OJB has nothing to do in this case. Please send more code of this Javascript. I would recommend to move this business code to a java code and call it from your Flow function. There are some small incompatibilities while manipulating Java object inside Javascript. I have interest in know how is declared it. Which kind of object it is. Same Thing happens when i use it in a java Class. Javascript is just easier to Debug for me, because i'm not using a java IDE. My workaround is to put a try/catch block into the while-loop. My Java-Code: import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.io.*; import java.text.*; import java.util.*; import org.apache.ojb.broker.query.*; ... Criteria crit = new Criteria(); crit.addEqualToField(logs.menuLinkId,id); crit.addEqualToField(stylesheet.id,stylesheetId); ReportQueryByCriteria q = new ReportQueryByCriteria(MenuLink.class,crit); String[] attributes = new String[4]; attributes[0] = logs.menuLinkId; attributes[1] = count(*); attributes[2] = name; attributes[3] = stylesheet.type; q.setAttributes(attributes); q.addGroupBy(logs.menuLinkId); q.addGroupBy(name); q.addGroupBy(stylesheet.type); q.addOrderByDescending(count(*)); // top 10 q.setEndAtIndex(10); ArrayList menulinks = new ArrayList(); dao.begin(); Iterator it = dao.getReport (q); while ( it != null it.hasNext() ) { // Catch Exception try { Object[] o = (Object[]) it.next(); menulinks.add(o); } catch (Exception e) { //nothing } } dao.commit(); Christoph pgp2U6j5MIt9Y.pgp Description: PGP signature