//This needs to be improved, but it works fine. It just doesn't go in true ascending order
Query q = em.createQuery ("SELECT rosie FROM RosieIndexes rosie WHERE rosie.xmlBlobId = :xmlBlobId AND rosie." + file_index_column + " = (SELECT MIN(rosie." + file_index_column + ") FROM RosieIndexes rosie WHERE rosie.used = 0)");
if (id != null) {
q.setParameter ("xmlBlobId",(new BigInteger(id)));
RosieIndexes r = null;
try {
@SuppressWarnings("unchecked")
List<RosieIndexes> resultList = q.getResultList();
for (RosieIndexes i : resultList) {
log.info("RosieIndexes record ID returned in getNextIndexToProcess is: " + i.getId());
}
r = (RosieIndexes) q.getSingleResult();
}
catch (NoResultException nr) {
log.info("no results from query. wait, then try again.");
try {
Thread.sleep(70);
r = (RosieIndexes) q.getSingleResult();
}
catch (NoResultException nr1) {
log.info("no results from query. wait, then try again.");
try {
Thread.sleep(200);
r = (RosieIndexes) q.getSingleResult();
}
catch (NoResultException nr2) {
log.info("no results from query, even after waiting twice.");
nextIndexRecord[0] = "-1";
nextIndexRecord[1] = "-1";
return nextIndexRecord;
}
catch (InterruptedException ie) {
log.info("Timer issue: ");
ie.printStackTrace();
}
}
catch (InterruptedException ie) {
log.info("Timer issue: ");
ie.printStackTrace();
}
}
String idResult = r.getId().toString();
String indexResult = null;
indexResult = r.getFile2index();
nextIndexRecord[0] = idResult;
nextIndexRecord[1] = indexResult;
log.info("getNextIndexToProcess got next id: " + idResult + " and next index: " + indexResult);
if (nextIndexRecord[0] == null || nextIndexRecord[0].isEmpty()) {
nextIndexRecord[0] = "-1";