Search in sources :

Example 1 with LazyList

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);
    }
}
Also used : LazyList(com.spaceprogram.simplejpa.LazyList) Attribute(com.amazonaws.services.simpledb.model.Attribute) NoSuchDomainException(com.amazonaws.services.simpledb.model.NoSuchDomainException) NotImplementedException(org.apache.commons.lang.NotImplementedException) AmazonClientException(com.amazonaws.AmazonClientException) NoSuchDomainException(com.amazonaws.services.simpledb.model.NoSuchDomainException) SelectResult(com.amazonaws.services.simpledb.model.SelectResult) Item(com.amazonaws.services.simpledb.model.Item) LazyList(com.spaceprogram.simplejpa.LazyList)

Aggregations

AmazonClientException (com.amazonaws.AmazonClientException)1 Attribute (com.amazonaws.services.simpledb.model.Attribute)1 Item (com.amazonaws.services.simpledb.model.Item)1 NoSuchDomainException (com.amazonaws.services.simpledb.model.NoSuchDomainException)1 SelectResult (com.amazonaws.services.simpledb.model.SelectResult)1 LazyList (com.spaceprogram.simplejpa.LazyList)1 NotImplementedException (org.apache.commons.lang.NotImplementedException)1