use of com.amazonaws.services.simpledb.model.SelectRequest in project camel by apache.
the class SelectCommand method execute.
public void execute() {
SelectRequest request = new SelectRequest().withSelectExpression(determineSelectExpression()).withConsistentRead(determineConsistentRead()).withNextToken(determineNextToken());
log.trace("Sending request [{}] for exchange [{}]...", request, exchange);
SelectResult result = this.sdbClient.select(request);
log.trace("Received result [{}]", result);
Message msg = getMessageForResponse(exchange);
msg.setHeader(SdbConstants.ITEMS, result.getItems());
msg.setHeader(SdbConstants.NEXT_TOKEN, result.getNextToken());
}
use of com.amazonaws.services.simpledb.model.SelectRequest in project simplejpa by appoxy.
the class DomainHelper method listAllItems.
/**
* A utility method for loading up all the items in a domain.
*
* @param db
* @param domainName
* @param consistentRead true to read consistently, false to use eventual consistency
* @return
* @throws AmazonClientException
*/
public static List<Item> listAllItems(AmazonSimpleDB db, String domainName, boolean consistentRead) throws AmazonClientException {
SelectResult results = new SelectResult();
List<Item> items = new ArrayList<Item>();
do {
results = db.select(new SelectRequest().withConsistentRead(consistentRead).withSelectExpression("select * from `" + domainName + "`").withNextToken(results.getNextToken()));
items.addAll(results.getItems());
} while (results.getNextToken() != null);
return items;
}
use of com.amazonaws.services.simpledb.model.SelectRequest in project siena by mandubian.
the class SdbPersistenceManager method doFetchIterable.
protected <T> Iterable<T> doFetchIterable(Query<T> query, int limit, int offset, boolean recursing) {
preFetch(query, limit, offset, recursing);
QueryOptionSdbContext sdbCtx = (QueryOptionSdbContext) query.option(QueryOptionSdbContext.ID);
// if previousPage has detected there is no more data, simply returns an empty list
if (sdbCtx.noMoreDataBefore || sdbCtx.noMoreDataAfter) {
return new ArrayList<T>();
}
// manages cursor limitations for IN and != operators with offsets
if (!sdbCtx.isActive()) {
StringBuffer domainBuf = new StringBuffer();
SelectRequest req = SdbMappingUtils.buildQuery(query, prefix, domainBuf);
req.setConsistentRead(isReadConsistent());
checkDomain(domainBuf.toString());
SelectResult res = sdb.select(req);
// activates the SdbCtx now that it is initialised
sdbCtx.activate();
postFetch(query, res);
return new SdbSienaIterable<T>(this, res.getItems(), query);
} else {
// we prepare the query each time
StringBuffer domainBuf = new StringBuffer();
SelectRequest req = SdbMappingUtils.buildQuery(query, prefix, domainBuf);
req.setConsistentRead(isReadConsistent());
checkDomain(domainBuf.toString());
// we can't use real asynchronous function with cursors
// so the page is extracted at once and wrapped into a SienaFuture
String token = sdbCtx.currentToken();
if (token != null) {
req.setNextToken(token);
}
SelectResult res = sdb.select(req);
postFetch(query, res);
return new SdbSienaIterable<T>(this, res.getItems(), query);
}
}
use of com.amazonaws.services.simpledb.model.SelectRequest in project siena by mandubian.
the class SdbPersistenceManager method doFetchList.
protected <T> void doFetchList(Query<T> query, int limit, int offset, List<T> resList, int depth) {
if (depth >= MAX_DEPTH) {
throw new SienaException("Reached maximum depth of recursion when retrieving more data (" + MAX_DEPTH + ")");
}
preFetch(query, limit, offset, !resList.isEmpty());
QueryOptionSdbContext sdbCtx = (QueryOptionSdbContext) query.option(QueryOptionSdbContext.ID);
QueryOptionFetchType fetchType = (QueryOptionFetchType) query.option(QueryOptionFetchType.ID);
QueryOptionOffset off = (QueryOptionOffset) query.option(QueryOptionOffset.ID);
// if previousPage has detected there is no more data, simply returns an empty list
if (sdbCtx.noMoreDataBefore || sdbCtx.noMoreDataAfter) {
return;
}
// manages cursor limitations for IN and != operators with offsets
if (!sdbCtx.isActive()) {
StringBuffer domainBuf = new StringBuffer();
SelectRequest req = SdbMappingUtils.buildQuery(query, prefix, domainBuf);
req.setConsistentRead(isReadConsistent());
checkDomain(domainBuf.toString());
SelectResult res = sdb.select(req);
// activates the SdbCtx now that it is really initialised
sdbCtx.activate();
postFetch(query, res);
// cursor not yet created
switch(fetchType.fetchType) {
case KEYS_ONLY:
if (off.isActive()) {
SdbMappingUtils.mapSelectResultToListKeysOnly(res, resList, query.getQueriedClass(), off.offset);
} else {
SdbMappingUtils.mapSelectResultToListKeysOnly(res, resList, query.getQueriedClass());
}
break;
case NORMAL:
default:
if (off.isActive()) {
SdbMappingUtils.mapSelectResultToList(res, resList, query.getQueriedClass(), off.offset);
} else {
SdbMappingUtils.mapSelectResultToList(res, resList, query.getQueriedClass());
}
// join management
if (!query.getJoins().isEmpty() || !ClassInfo.getClassInfo(query.getQueriedClass()).joinFields.isEmpty())
mapJoins(query, resList);
}
continueFetchNextToken(query, resList, depth);
postMapping(query);
} else {
// we prepare the query each time
StringBuffer domainBuf = new StringBuffer();
SelectRequest req = SdbMappingUtils.buildQuery(query, prefix, domainBuf);
req.setConsistentRead(isReadConsistent());
checkDomain(domainBuf.toString());
// we can't use real asynchronous function with cursors
// so the page is extracted at once and wrapped into a SienaFuture
String token = sdbCtx.currentToken();
if (token != null) {
req.setNextToken(token);
}
SelectResult res = sdb.select(req);
postFetch(query, res);
switch(fetchType.fetchType) {
case KEYS_ONLY:
if (off.isActive()) {
SdbMappingUtils.mapSelectResultToListKeysOnly(res, resList, query.getQueriedClass(), off.offset);
} else {
SdbMappingUtils.mapSelectResultToListKeysOnly(res, resList, query.getQueriedClass());
}
break;
case NORMAL:
default:
if (off.isActive()) {
SdbMappingUtils.mapSelectResultToList(res, resList, query.getQueriedClass(), off.offset);
} else {
SdbMappingUtils.mapSelectResultToList(res, resList, query.getQueriedClass());
}
// join management
if (!query.getJoins().isEmpty() || !ClassInfo.getClassInfo(query.getQueriedClass()).joinFields.isEmpty())
mapJoins(query, resList);
}
continueFetchNextToken(query, resList, depth);
postMapping(query);
}
}
use of com.amazonaws.services.simpledb.model.SelectRequest in project siena by mandubian.
the class SdbPersistenceManager method count.
public <T> int count(Query<T> query) {
StringBuffer domainBuf = new StringBuffer();
SelectRequest req = SdbMappingUtils.buildCountQuery(query, prefix, domainBuf);
try {
checkDomain(domainBuf.toString());
req.setConsistentRead(isReadConsistent());
SelectResult res = sdb.select(req);
return SdbMappingUtils.mapSelectResultToCount(res);
} catch (AmazonClientException ex) {
throw new SienaException(ex);
}
}
Aggregations