Search in sources :

Example 11 with SelectRequest

use of com.amazonaws.services.simpledb.model.SelectRequest in project siena by mandubian.

the class SdbMappingUtils method buildQuery.

public static <T> SelectRequest buildQuery(Query<T> query, String prefix, StringBuffer domainBuf) {
    Class<?> clazz = query.getQueriedClass();
    String domain = getDomainName(clazz, prefix);
    domainBuf.append(domain);
    QueryOptionFetchType fetchType = (QueryOptionFetchType) query.option(QueryOptionFetchType.ID);
    StringBuilder q = new StringBuilder();
    switch(fetchType.fetchType) {
        case KEYS_ONLY:
            q.append(SELECT + ITEM_NAME + FROM + domain);
            break;
        case NORMAL:
        default:
            q.append(SELECT + ALL_COLS + FROM + domain);
            break;
    }
    return new SelectRequest(buildFilterOrder(query, q).toString());
}
Also used : QueryOptionFetchType(siena.core.options.QueryOptionFetchType) SelectRequest(com.amazonaws.services.simpledb.model.SelectRequest)

Example 12 with SelectRequest

use of com.amazonaws.services.simpledb.model.SelectRequest in project siena by mandubian.

the class SdbPersistenceManager method rawGetByKeys.

protected <T> List<T> rawGetByKeys(Class<T> clazz, Iterable<?> keys) {
    try {
        StringBuffer domainBuf = new StringBuffer();
        SelectRequest req = SdbMappingUtils.buildBatchGetQueryByKeys(clazz, keys, prefix, domainBuf);
        checkDomain(domainBuf.toString());
        req.setConsistentRead(isReadConsistent());
        SelectResult res = sdb.select(req);
        List<T> models = new ArrayList<T>();
        SdbMappingUtils.mapSelectResultToListOrderedFromKeys(res, models, clazz, keys);
        // join management
        if (!ClassInfo.getClassInfo(clazz).joinFields.isEmpty()) {
            mapJoins(models);
        }
        return models;
    } catch (AmazonClientException ex) {
        throw new SienaException(ex);
    }
}
Also used : SelectResult(com.amazonaws.services.simpledb.model.SelectResult) AmazonClientException(com.amazonaws.AmazonClientException) ArrayList(java.util.ArrayList) SienaException(siena.SienaException) SelectRequest(com.amazonaws.services.simpledb.model.SelectRequest)

Example 13 with SelectRequest

use of com.amazonaws.services.simpledb.model.SelectRequest in project simplejpa by appoxy.

the class DomainHelper method selectItems.

/**
 * Runs a query on the passed in domain with the passed in whereClause.  If the nextToken is included for pagination.
 *
 * @param db
 * @param domainName
 * @param whereClause
 * @param nextToken
 * @param consistentRead true to read consistently, false to use eventual consistency
 * @return
 * @throws AmazonClientException
 */
public static SelectResult selectItems(AmazonSimpleDB db, String domainName, String whereClause, String nextToken, boolean consistentRead) throws AmazonClientException {
    String selectExpression = "select * from `" + domainName + "`";
    if (whereClause != null) {
        selectExpression += " where " + whereClause;
    }
    SelectResult results = db.select(new SelectRequest().withConsistentRead(consistentRead).withSelectExpression(selectExpression).withNextToken(nextToken));
    return results;
}
Also used : SelectResult(com.amazonaws.services.simpledb.model.SelectResult) SelectRequest(com.amazonaws.services.simpledb.model.SelectRequest)

Aggregations

SelectRequest (com.amazonaws.services.simpledb.model.SelectRequest)13 SelectResult (com.amazonaws.services.simpledb.model.SelectResult)12 ArrayList (java.util.ArrayList)4 SienaException (siena.SienaException)4 AmazonClientException (com.amazonaws.AmazonClientException)3 Item (com.amazonaws.services.simpledb.model.Item)3 Date (java.util.Date)2 LinkedHashMap (java.util.LinkedHashMap)2 Test (org.testng.annotations.Test)2 QueryOptionFetchType (siena.core.options.QueryOptionFetchType)2 Attribute (com.amazonaws.services.simpledb.model.Attribute)1 ReplaceableAttribute (com.amazonaws.services.simpledb.model.ReplaceableAttribute)1 EventType (com.netflix.simianarmy.EventType)1 MonkeyType (com.netflix.simianarmy.MonkeyType)1 Resource (com.netflix.simianarmy.Resource)1 AWSResource (com.netflix.simianarmy.aws.AWSResource)1 AWSResourceType (com.netflix.simianarmy.aws.AWSResourceType)1 BasicRecorderEvent (com.netflix.simianarmy.basic.BasicRecorderEvent)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1