Getting exception on IQueryResult.hasNext() method
I am making a query to the JTS for work items that were modified after a specific time. The query works fine if there are work items that meet that criteria. If there are no work items modified after the provided time then the following method call generates an exception
//
// This method was created to address the strange problem where the
// hasNext method is generating an exception when the query did
// not yield any results.
//
private boolean hasNextSafe(IQueryResult<IResolvedResult<IWorkItem>> queried)
{
//
// The queried.hasNext() method is generating an exception when the result is empty, EVEN though the
// total count above shows there there are results.
//
boolean fContinue = false;
try
{
fContinue = queried.hasNext(null);
}
catch(Exception e)
{
System.out.println("RTCActionPerformer::hasNextSafe - queried.hasNext generated an exception");
fContinue = false;
}
return fContinue;
} // end of the hasNextSafe method
In the case where there are no work items returned ... the following code seems to yield the results of the previous query ...
ResultSize rs = queried.getResultSize(null);
int iTotal = rs.getTotal();
System.out.println("RTCActionPerformer::processArtifact - " + iTotal + " work items returned");
//
// This method was created to address the strange problem where the
// hasNext method is generating an exception when the query did
// not yield any results.
//
private boolean hasNextSafe(IQueryResult<IResolvedResult<IWorkItem>> queried)
{
//
// The queried.hasNext() method is generating an exception when the result is empty, EVEN though the
// total count above shows there there are results.
//
boolean fContinue = false;
try
{
fContinue = queried.hasNext(null);
}
catch(Exception e)
{
System.out.println("RTCActionPerformer::hasNextSafe - queried.hasNext generated an exception");
fContinue = false;
}
return fContinue;
} // end of the hasNextSafe method
In the case where there are no work items returned ... the following code seems to yield the results of the previous query ...
ResultSize rs = queried.getResultSize(null);
int iTotal = rs.getTotal();
System.out.println("RTCActionPerformer::processArtifact - " + iTotal + " work items returned");
3 answers
Ralph - thanks for the quick response and pointer. Looks like a great article and just what I am looking for. I did not see a link to download the full source code? Is that available?
Comments
Hi Joe, I did not publish the code yet. but you should be able to just cut and paste from the blog. I am still in the process of publishing to https://hub.jazz.net/project/rschoon/Jazz%20In%20Flight but this code is not yet up. I have to do some clean up first.
Ralph - by the way, I have a hunch that maybe there is something that I need to do to close out the previous query that maybe I am not doing. In the case where I get the exception I am seeing somethings that were clearly from the previous query.
ResultSize rs = queried.getResultSize(null);
int iTotal = rs.getTotal();
System.out.println("RTCActionPerformer::processArtifact - " + iTotal + " work items returned");
Thanks again for your help.
Joe
ResultSize rs = queried.getResultSize(null);
int iTotal = rs.getTotal();
System.out.println("RTCActionPerformer::processArtifact - " + iTotal + " work items returned");
Thanks again for your help.
Joe