Example usage for com.amazonaws.services.simpledb.model SelectRequest getSelectExpression

List of usage examples for com.amazonaws.services.simpledb.model SelectRequest getSelectExpression

Introduction

In this page you can find the example usage for com.amazonaws.services.simpledb.model SelectRequest getSelectExpression.

Prototype


public String getSelectExpression() 

Source Link

Document

The expression used to query the domain.

Usage

From source file:wwutil.jsoda.SimpleDBService.java

License:Mozilla Public License

@SuppressWarnings("unchecked")
public <T> long queryCount(Class<T> modelClass, Query<T> query) throws JsodaException {
    String modelName = jsoda.getModelName(modelClass);
    String queryStr = toQueryStr(query, true);
    SelectRequest request = new SelectRequest(queryStr, query.consistentRead);

    try {//from ww w .j a  v  a 2s.  c om
        for (Item item : sdbClient.select(request).getItems()) {
            for (Attribute attr : item.getAttributes()) {
                String attrName = attr.getName();
                String fieldValue = attr.getValue();
                long count = Long.parseLong(fieldValue);
                return count;
            }
        }
    } catch (Exception e) {
        throw new JsodaException(
                "Query failed.  Query: " + request.getSelectExpression() + "  Error: " + e.getMessage(), e);
    }
    throw new JsodaException("Query failed.  Not result for count query.");
}

From source file:wwutil.jsoda.SimpleDBService.java

License:Mozilla Public License

@SuppressWarnings("unchecked")
public <T> List<T> queryRun(Class<T> modelClass, Query<T> query, boolean continueFromLastRun)
        throws JsodaException {
    List<T> resultObjs = new ArrayList<T>();

    if (continueFromLastRun && !queryHasNext(query))
        return resultObjs;

    String queryStr = toQueryStr(query, false);
    log.info("Query: " + queryStr);
    SelectRequest request = new SelectRequest(queryStr, query.consistentRead);

    if (continueFromLastRun)
        request.setNextToken((String) query.nextKey);

    try {/* ww w .ja v a 2 s . c om*/
        SelectResult result = sdbClient.select(request);
        query.nextKey = request.getNextToken();
        for (Item item : result.getItems()) {
            String idValue = item.getName(); // get the id from the item's name()
            T obj = buildLoadObj(modelClass, query.modelName, idValue, item.getAttributes(), query);
            resultObjs.add(obj);
        }
        return resultObjs;
    } catch (Exception e) {
        throw new JsodaException(
                "Query failed.  Query: " + request.getSelectExpression() + "  Error: " + e.getMessage(), e);
    }
}