use of com.spaceprogram.simplejpa.LazyList in project simplejpa by appoxy.
the class AbstractQuery method getResultList.
public List getResultList() {
// convert to amazon query
AmazonQueryString amazonQuery;
try {
amazonQuery = createAmazonQuery();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
if (amazonQuery == null) {
return new ArrayList();
}
try {
// String qToSend = amazonQuery != null ? amazonQuery.toString() : null;
em.incrementQueryCount();
if (amazonQuery.isCount()) {
// String domainName = em.getDomainName(tClass);
String nextToken = null;
SelectResult qr;
long count = 0;
while ((qr = DomainHelper.selectItems(this.em.getSimpleDb(), amazonQuery.getValue(), nextToken)) != null) {
Map<String, List<Attribute>> itemMap = new HashMap<String, List<Attribute>>();
for (Item item : qr.getItems()) {
itemMap.put(item.getName(), item.getAttributes());
}
for (String id : itemMap.keySet()) {
List<Attribute> list = itemMap.get(id);
for (Attribute itemAttribute : list) {
if (itemAttribute.getName().equals("Count")) {
count += Long.parseLong(itemAttribute.getValue());
}
}
}
nextToken = qr.getNextToken();
if (nextToken == null) {
break;
}
}
return Arrays.asList(count);
} else {
LazyList ret = new LazyList(em, tClass, this);
return ret;
}
} catch (NoSuchDomainException e) {
// no need to throw here
return new ArrayList();
} catch (Exception e) {
throw new PersistenceException(e);
}
}
Aggregations