{
Thread.sleep(500);
}
catch (InterruptedException e)
{
throw new TorqueException("Unexpected interruption", e);
}
}
}
// Going in reverse direction, trying to limit db hits so assume user
// might want at least 2 sets of data.
else if (start < blockBegin && start >= 0)
{
if (log.isDebugEnabled())
{
log.debug("getResults(): Paging backwards as start (" + start
+ ") < blockBegin (" + blockBegin + ") && start >= 0");
}
stopQuery();
if (memoryLimit >= 2 * size)
{
blockBegin = start - size;
if (blockBegin < 0)
{
blockBegin = 0;
}
}
else
{
blockBegin = start;
}
blockEnd = blockBegin + memoryLimit - 1;
startQuery(size);
// Re-invoke getResults() to provide the wait processing.
return getResults(start, size);
}
// Assume we are moving on, do not retrieve any records prior to start.
else if ((start + size - 1) > blockEnd)
{
if (log.isDebugEnabled())
{
log.debug("getResults(): Paging past end of loaded data as "
+ "start+size-1 (" + (start + size - 1)
+ ") > blockEnd (" + blockEnd + ")");
}
stopQuery();
blockBegin = start;
blockEnd = blockBegin + memoryLimit - 1;
startQuery(size);
// Re-invoke getResults() to provide the wait processing.
return getResults(start, size);
}
else
{
throw new IllegalArgumentException("Parameter configuration not "
+ "accounted for.");
}
int fromIndex = start - blockBegin;
int toIndex = fromIndex + Math.min(size, results.size() - fromIndex);
if (log.isDebugEnabled())
{
log.debug("getResults(): Retrieving records from results elements "
+ "start-blockBegin (" + fromIndex + ") through "
+ "fromIndex + Math.min(size, results.size() - fromIndex) ("
+ toIndex + ")");
}
List returnResults = results.subList(fromIndex, toIndex);
if (null != returnBuilderClass)
{
// Invoke the populateObjects() method
Object[] theArgs = { returnResults };
try
{
returnResults =
(List) populateObjectsMethod.invoke(
returnBuilderClass.newInstance(),
theArgs);
}
catch (Exception e)
{
throw new TorqueException("Unable to populate results", e);
}
}
position = start + size;
lastResults = returnResults;
return returnResults;