@Override protected boolean atEndOfResults() { return queryResult.getLastEvaluatedKey() == null; }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getItems() != null) sb.append("Items: ").append(getItems()).append(","); if (getCount() != null) sb.append("Count: ").append(getCount()).append(","); if (getScannedCount() != null) sb.append("ScannedCount: ").append(getScannedCount()).append(","); if (getLastEvaluatedKey() != null) sb.append("LastEvaluatedKey: ").append(getLastEvaluatedKey()).append(","); if (getConsumedCapacity() != null) sb.append("ConsumedCapacity: ").append(getConsumedCapacity()); sb.append("}"); return sb.toString(); }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getItems() == null) ? 0 : getItems().hashCode()); hashCode = prime * hashCode + ((getCount() == null) ? 0 : getCount().hashCode()); hashCode = prime * hashCode + ((getScannedCount() == null) ? 0 : getScannedCount().hashCode()); hashCode = prime * hashCode + ((getLastEvaluatedKey() == null) ? 0 : getLastEvaluatedKey().hashCode()); hashCode = prime * hashCode + ((getConsumedCapacity() == null) ? 0 : getConsumedCapacity().hashCode()); return hashCode; }
@Override public <T> int count(Class<T> clazz, DynamoDBQueryExpression<T> queryExpression, DynamoDBMapperConfig config) { config = mergeConfig(config); QueryRequest queryRequest = createQueryRequestFromExpression(clazz, queryExpression, config); queryRequest.setSelect(Select.COUNT); // Count queries can also be truncated for large datasets int count = 0; QueryResult queryResult = null; do { queryResult = db.query(applyUserAgent(queryRequest)); count += queryResult.getCount(); queryRequest.setExclusiveStartKey(queryResult.getLastEvaluatedKey()); } while (queryResult.getLastEvaluatedKey() != null); return count; }
public QueryPage( AmazonDynamoDB client, QuerySpec spec, QueryRequest request, int index, QueryOutcome outcome) { super(Collections.unmodifiableList( toItemList(outcome.getQueryResult().getItems())), outcome); this.client = client; this.spec = spec; this.request = request; this.index = index; final Integer max = spec.getMaxResultSize(); final QueryResult result = outcome.getQueryResult(); final List<?> ilist = result.getItems(); final int size = ilist == null ? 0 : ilist.size(); if (max != null && (index + size) > max) { this.lastEvaluatedKey = null; } else { this.lastEvaluatedKey = result.getLastEvaluatedKey(); } }
if (other.getScannedCount() != null && other.getScannedCount().equals(this.getScannedCount()) == false) return false; if (other.getLastEvaluatedKey() == null ^ this.getLastEvaluatedKey() == null) return false; if (other.getLastEvaluatedKey() != null && other.getLastEvaluatedKey().equals(this.getLastEvaluatedKey()) == false) return false; if (other.getConsumedCapacity() == null ^ this.getConsumedCapacity() == null)
@Override protected synchronized List<T> fetchNextPage() { queryRequest.setExclusiveStartKey(queryResult.getLastEvaluatedKey()); queryResult = dynamo.query(DynamoDBMapper.applyUserAgent(queryRequest)); return mapper.marshallIntoObjects(mapper.toParameters( queryResult.getItems(), clazz, queryRequest.getTableName(), config)); } }
@Override protected boolean atEndOfResults() { return queryResult.getLastEvaluatedKey() == null; }
@Override public <T> QueryResultPage<T> queryPage(Class<T> clazz, DynamoDBQueryExpression<T> queryExpression, DynamoDBMapperConfig config) { config = mergeConfig(config); QueryRequest queryRequest = createQueryRequestFromExpression(clazz, queryExpression, config); QueryResult queryResult = db.query(applyUserAgent(queryRequest)); QueryResultPage<T> result = new QueryResultPage<T>(); List<AttributeTransformer.Parameters<T>> parameters = toParameters(queryResult.getItems(), clazz, queryRequest.getTableName(), config); result.setResults(marshallIntoObjects(parameters)); result.setLastEvaluatedKey(queryResult.getLastEvaluatedKey()); result.setCount(queryResult.getCount()); result.setScannedCount(queryResult.getScannedCount()); result.setConsumedCapacity(queryResult.getConsumedCapacity()); return result; }
/** * Returns a string representation of this object; useful for testing and * debugging. * * @return A string representation of this object. * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getItems() != null) sb.append("Items: " + getItems() + ","); if (getCount() != null) sb.append("Count: " + getCount() + ","); if (getScannedCount() != null) sb.append("ScannedCount: " + getScannedCount() + ","); if (getLastEvaluatedKey() != null) sb.append("LastEvaluatedKey: " + getLastEvaluatedKey() + ","); if (getConsumedCapacity() != null) sb.append("ConsumedCapacity: " + getConsumedCapacity()); sb.append("}"); return sb.toString(); }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getItems() == null) ? 0 : getItems().hashCode()); hashCode = prime * hashCode + ((getCount() == null) ? 0 : getCount().hashCode()); hashCode = prime * hashCode + ((getScannedCount() == null) ? 0 : getScannedCount().hashCode()); hashCode = prime * hashCode + ((getLastEvaluatedKey() == null) ? 0 : getLastEvaluatedKey().hashCode()); hashCode = prime * hashCode + ((getConsumedCapacity() == null) ? 0 : getConsumedCapacity().hashCode()); return hashCode; }
/** * Evaluates the specified query expression and returns the count of * matching items, without returning any of the actual item data. * * @param clazz The class mapped to a DynamoDB table. * @param queryExpression The parameters for running the scan. * @param config The mapper configuration to use for the query, which * overrides the default provided at object construction. * @param <T> the type of the object. * @return The count of matching items, without returning any of the actual * item data. */ public <T> int count(Class<T> clazz, DynamoDBQueryExpression<T> queryExpression, DynamoDBMapperConfig config) { config = mergeConfig(config); final QueryRequest queryRequest = createQueryRequestFromExpression(clazz, queryExpression, config); queryRequest.setSelect(Select.COUNT); // Count queries can also be truncated for large datasets int count = 0; QueryResult queryResult = null; do { queryResult = db.query(applyUserAgent(queryRequest)); count += queryResult.getCount(); queryRequest.setExclusiveStartKey(queryResult.getLastEvaluatedKey()); } while (queryResult.getLastEvaluatedKey() != null); return count; }
&& other.getScannedCount().equals(this.getScannedCount()) == false) return false; if (other.getLastEvaluatedKey() == null ^ this.getLastEvaluatedKey() == null) return false; if (other.getLastEvaluatedKey() != null && other.getLastEvaluatedKey().equals(this.getLastEvaluatedKey()) == false) return false; if (other.getConsumedCapacity() == null ^ this.getConsumedCapacity() == null)
@Override protected synchronized List<T> fetchNextPage() { queryRequest.setExclusiveStartKey(queryResult.getLastEvaluatedKey()); queryResult = dynamo.query(DynamoDBMapper.applyUserAgent(queryRequest)); return mapper.marshallIntoObjects(mapper.toParameters( queryResult.getItems(), clazz, queryRequest.getTableName(), config)); } }
nextKey = result.getLastEvaluatedKey(); if (nextKey == null || nextKey.size() == 0) { isDone = true;
/** * Queries an Amazon DynamoDB table and returns a single page of matching * results. The table to query is determined by looking at the annotations * on the specified class, which declares where to store the object data in * Amazon DynamoDB, and the query expression parameter allows the caller to * filter results and control how the query is executed. * * @param <T> The type of the objects being returned. * @param clazz The class annotated with DynamoDB annotations describing how * to store the object data in AWS DynamoDB. * @param queryExpression Details on how to run the query, including any * conditions on the key values * @param config The configuration to use for this query, which overrides * the default provided at object construction. * @return a single page of matching results */ public <T> QueryResultPage<T> queryPage(Class<T> clazz, DynamoDBQueryExpression<T> queryExpression, DynamoDBMapperConfig config) { config = mergeConfig(config); final QueryRequest queryRequest = createQueryRequestFromExpression(clazz, queryExpression, config); final QueryResult scanResult = db.query(applyUserAgent(queryRequest)); final QueryResultPage<T> result = new QueryResultPage<T>(); final List<AttributeTransformer.Parameters<T>> parameters = toParameters(scanResult.getItems(), clazz, queryRequest.getTableName(), config); result.setResults(marshallIntoObjects(parameters)); result.setLastEvaluatedKey(scanResult.getLastEvaluatedKey()); return result; }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getItems() == null) ? 0 : getItems().hashCode()); hashCode = prime * hashCode + ((getCount() == null) ? 0 : getCount().hashCode()); hashCode = prime * hashCode + ((getScannedCount() == null) ? 0 : getScannedCount().hashCode()); hashCode = prime * hashCode + ((getLastEvaluatedKey() == null) ? 0 : getLastEvaluatedKey().hashCode()); hashCode = prime * hashCode + ((getConsumedCapacity() == null) ? 0 : getConsumedCapacity().hashCode()); return hashCode; }
QueryRequest request = new QueryRequest(); request.setTableName(tablename); QueryResult result = dynamoDB.query(request); ItemCollection<QueryOutcome> items = result.getItems(); Map<String,AttributeValue> lastKey = result.getLastEvaluatedKey();
@Override protected synchronized List<T> fetchNextPage() { queryRequest.setExclusiveStartKey(queryResult.getLastEvaluatedKey()); queryResult = dynamo.query(DynamoDBMapper.applyUserAgent(queryRequest)); return mapper.marshallIntoObjects(mapper.toParameters( queryResult.getItems(), clazz, queryRequest.getTableName(), config)); } }
@Override protected PageResults<Map<String, AttributeValue>> fetchPage(RequestLimit lim) { // Read from DynamoDB RetryResult<QueryResult> retryResult = context.getClient().queryTable(tableName, context .getSplit().getFilterPushdown(), lastEvaluatedKey, lim.items, context.getReporter()); QueryResult result = retryResult.result; int retries = retryResult.retries; return new PageResults<>(result.getItems(), result.getLastEvaluatedKey(), result .getConsumedCapacity().getCapacityUnits(), retries); } }