/** * Simple wrapper around executing a query. * @param db * @param query * @param nextToken * @param consistentRead true to read consistently, false to use eventual consistency * @return * @throws AmazonClientException */ public static SelectResult selectItems(AmazonSimpleDB db, String query, String nextToken, boolean consistentRead) throws AmazonClientException { SelectResult results = db.select(new SelectRequest() .withConsistentRead(consistentRead) .withSelectExpression(query) .withNextToken(nextToken)); return results; }
/** * 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; }
/** * 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; }