/** * The primary hash and range keys of the first item that this operation will evaluate. Use the value that was * returned for <i>LastEvaluatedKey</i> in the previous operation. * <p> * The data type for <i>ExclusiveStartKey</i> must be String, Number or Binary. No set data types are allowed. * <p> * Returns a reference to this object so that method calls can be chained together. * * @param hashKey * a map entry including the name and value of the primary hash key. * @param rangeKey * a map entry including the name and value of the primary range key, or null if it is a hash-only table. */ public ScanRequest withExclusiveStartKey(java.util.Map.Entry<String, AttributeValue> hashKey, java.util.Map.Entry<String, AttributeValue> rangeKey) throws IllegalArgumentException { setExclusiveStartKey(hashKey, rangeKey); return this; }
/** * <p> * The primary key of the first item that this operation will evaluate. Use the value that was returned for * <code>LastEvaluatedKey</code> in the previous operation. * </p> * <p> * The data type for <code>ExclusiveStartKey</code> must be String, Number or Binary. No set data types are allowed. * </p> * <p> * In a parallel scan, a <code>Scan</code> request that includes <code>ExclusiveStartKey</code> must specify the * same segment whose previous <code>Scan</code> returned the corresponding value of <code>LastEvaluatedKey</code>. * </p> * * @param exclusiveStartKey * The primary key of the first item that this operation will evaluate. Use the value that was returned for * <code>LastEvaluatedKey</code> in the previous operation.</p> * <p> * The data type for <code>ExclusiveStartKey</code> must be String, Number or Binary. No set data types are * allowed. * </p> * <p> * In a parallel scan, a <code>Scan</code> request that includes <code>ExclusiveStartKey</code> must specify * the same segment whose previous <code>Scan</code> returned the corresponding value of * <code>LastEvaluatedKey</code>. * @return Returns a reference to this object so that method calls can be chained together. */ public ScanRequest withExclusiveStartKey(java.util.Map<String, AttributeValue> exclusiveStartKey) { setExclusiveStartKey(exclusiveStartKey); return this; }
/** * The primary hash and range keys of the first item that this operation will evaluate. Use the value that was * returned for <i>LastEvaluatedKey</i> in the previous operation. * <p> * The data type for <i>ExclusiveStartKey</i> must be String, Number or Binary. No set data types are allowed. * * @param hashKey * a map entry including the name and value of the primary hash key. * @param rangeKey * a map entry including the name and value of the primary range key, or null if it is a hash-only table. */ public void setExclusiveStartKey(java.util.Map.Entry<String, AttributeValue> hashKey, java.util.Map.Entry<String, AttributeValue> rangeKey) throws IllegalArgumentException { java.util.HashMap<String, AttributeValue> exclusiveStartKey = new java.util.HashMap<String, AttributeValue>(); if (hashKey != null) { exclusiveStartKey.put(hashKey.getKey(), hashKey.getValue()); } else { throw new IllegalArgumentException("hashKey must be non-null object."); } if (rangeKey != null) { exclusiveStartKey.put(rangeKey.getKey(), rangeKey.getValue()); } setExclusiveStartKey(exclusiveStartKey); }
private ScanResult scanNextPageOfSegment(int currentSegment, boolean checkLastEvaluatedKey) { ScanRequest segmentScanRequest = parallelScanRequests.get(currentSegment); if (checkLastEvaluatedKey) { ScanResult lastScanResult = segmentScanResults.get(currentSegment); segmentScanRequest.setExclusiveStartKey(lastScanResult.getLastEvaluatedKey()); } else { segmentScanRequest.setExclusiveStartKey(null); } ScanResult scanResult = dynamo.scan(DynamoDBMapper.applyUserAgent(segmentScanRequest)); /** * Cache the scan result in segmentScanResults. * We should never try to get these scan results by calling get() on the cached future tasks. */ segmentScanResults.set(currentSegment, scanResult); /** * Update the state and notify any waiting thread. */ synchronized(segmentScanStates) { if (null == scanResult.getLastEvaluatedKey()) segmentScanStates.set(currentSegment, SegmentScanState.SegmentScanCompleted); else segmentScanStates.set(currentSegment, SegmentScanState.HasNextPage); segmentScanStates.notifyAll(); } return scanResult; }
@Override public Page<Item, ScanOutcome> nextPage() { if (lastEvaluatedKey == null) { throw new NoSuchElementException("No more pages"); } final Integer max = spec.getMaxResultSize(); if (max != null) { int nextLimit = nextRequestLimit(max.intValue()); if (nextLimit == 0) throw new NoSuchElementException("No more pages"); request.setLimit(nextLimit); } request.setExclusiveStartKey(lastEvaluatedKey); // fire off request to the server side ScanResult result = client.scan(request); final int nextIndex = index + this.size(); return new ScanPage(client, spec, request, nextIndex, new ScanOutcome(result)); } }
@Override protected synchronized List<T> fetchNextPage() { scanRequest.setExclusiveStartKey(scanResult.getLastEvaluatedKey()); scanResult = dynamo.scan(DynamoDBMapper.applyUserAgent(scanRequest)); return mapper.marshallIntoObjects(mapper.toParameters( scanResult.getItems(), clazz, scanRequest.getTableName(), config)); }
req.setAttributesToGet(fields); while (count < recordcount) { req.setExclusiveStartKey(startKey); req.setLimit(recordcount - count); ScanResult res;
@Override public int count(Class<?> clazz, DynamoDBScanExpression scanExpression, DynamoDBMapperConfig config) { config = mergeConfig(config); ScanRequest scanRequest = createScanRequestFromExpression(clazz, scanExpression, config); scanRequest.setSelect(Select.COUNT); // Count scans can also be truncated for large datasets int count = 0; ScanResult scanResult = null; do { scanResult = db.scan(applyUserAgent(scanRequest)); count += scanResult.getCount(); scanRequest.setExclusiveStartKey(scanResult.getLastEvaluatedKey()); } while (scanResult.getLastEvaluatedKey() != null); return count; }
@Override public Page<Item, ScanOutcome> firstPage() { ScanRequest request = spec.getRequest(); request.setExclusiveStartKey(startKey); request.setLimit(InternalUtils.minimum( spec.getMaxResultSize(), spec.getMaxPageSize())); ScanResult result = client.scan(request); ScanOutcome outcome = new ScanOutcome(result); setLastLowLevelResult(outcome); return new ScanPage(client, spec, request, 0, outcome); }
protected ItemCollection<ScanOutcome> doScan(ScanSpec spec) { // set the table name String tableName = getTable().getTableName(); ScanRequest req = spec.getRequest().withTableName(tableName); // set up the start key, if any Collection<KeyAttribute> startKey = spec.getExclusiveStartKey(); if (startKey != null) req.setExclusiveStartKey(InternalUtils.toAttributeValueMap(startKey)); // scan filters; Collection<ScanFilter> filters = spec.getScanFilters(); if (filters != null) { req.setScanFilter(InternalUtils.toAttributeConditionMap(filters)); } // set up the value map, if any (when expression API is used) final Map<String,AttributeValue> attrValMap = InternalUtils.fromSimpleMap(spec.getValueMap()); // set up expressions, if any req.withExpressionAttributeNames(spec.getNameMap()) .withExpressionAttributeValues(attrValMap) ; return new ScanCollection(getClient(), spec); } }
ScanResult scanNextPageOfSegment(int currentSegment, boolean checkLastEvaluatedKey) { final ScanRequest segmentScanRequest = parallelScanRequests.get(currentSegment); if (checkLastEvaluatedKey) { final ScanResult lastScanResult = segmentScanResults.get(currentSegment); segmentScanRequest.setExclusiveStartKey(lastScanResult.getLastEvaluatedKey()); } else { segmentScanRequest.setExclusiveStartKey(null); } final ScanResult scanResult = dynamo.scan(DynamoDBMapper.applyUserAgent(segmentScanRequest)); /** * Cache the scan result in segmentScanResults. We should never try to * get these scan results by calling get() on the cached future tasks. */ segmentScanResults.set(currentSegment, scanResult); /** * Update the state and notify any waiting thread. */ synchronized (segmentScanStates) { if (null == scanResult.getLastEvaluatedKey()) { segmentScanStates.set(currentSegment, SegmentScanState.SegmentScanCompleted); } else { segmentScanStates.set(currentSegment, SegmentScanState.HasNextPage); } segmentScanStates.notifyAll(); } return scanResult; }
/** * @param config never null */ private ScanRequest createScanRequestFromExpression(Class<?> clazz, DynamoDBScanExpression scanExpression, DynamoDBMapperConfig config) { ScanRequest scanRequest = new ScanRequest(); scanRequest.setTableName(getTableName(clazz, config)); scanRequest.setIndexName(scanExpression.getIndexName()); scanRequest.setScanFilter(scanExpression.getScanFilter()); scanRequest.setLimit(scanExpression.getLimit()); scanRequest.setExclusiveStartKey(scanExpression.getExclusiveStartKey()); scanRequest.setTotalSegments(scanExpression.getTotalSegments()); scanRequest.setSegment(scanExpression.getSegment()); scanRequest.setConditionalOperator(scanExpression.getConditionalOperator()); scanRequest.setFilterExpression(scanExpression.getFilterExpression()); scanRequest.setExpressionAttributeNames(scanExpression .getExpressionAttributeNames()); scanRequest.setExpressionAttributeValues(scanExpression .getExpressionAttributeValues()); scanRequest.setRequestMetricCollector(config.getRequestMetricCollector()); scanRequest.setSelect(scanExpression.getSelect()); scanRequest.setProjectionExpression(scanExpression.getProjectionExpression()); scanRequest.setReturnConsumedCapacity(scanExpression.getReturnConsumedCapacity()); scanRequest.setConsistentRead(scanExpression.isConsistentRead()); return applyUserAgent(scanRequest); }
@Override protected synchronized List<T> fetchNextPage() { scanRequest.setExclusiveStartKey(scanResult.getLastEvaluatedKey()); scanResult = dynamo.scan(DynamoDBMapper.applyUserAgent(scanRequest)); return mapper.marshallIntoObjects(mapper.toParameters( scanResult.getItems(), clazz, scanRequest.getTableName(), config)); } }
/** * The primary hash and range keys of the first item that this operation will evaluate. Use the value that was * returned for <i>LastEvaluatedKey</i> in the previous operation. * <p> * The data type for <i>ExclusiveStartKey</i> must be String, Number or Binary. No set data types are allowed. * <p> * Returns a reference to this object so that method calls can be chained together. * * @param hashKey * a map entry including the name and value of the primary hash key. * @param rangeKey * a map entry including the name and value of the primary range key, or null if it is a hash-only table. */ public ScanRequest withExclusiveStartKey(java.util.Map.Entry<String, AttributeValue> hashKey, java.util.Map.Entry<String, AttributeValue> rangeKey) throws IllegalArgumentException { setExclusiveStartKey(hashKey, rangeKey); return this; }
/** * Evaluates the specified scan expression and returns the count of matching * items, without returning any of the actual item data. * <p> * This operation will scan your entire table, and can therefore be very * expensive. Use with caution. * * @param clazz The class mapped to a DynamoDB table. * @param scanExpression The parameters for running the scan. * @param config The configuration to use for this scan, which overrides the * default provided at object construction. * @return The count of matching items, without returning any of the actual * item data. */ public int count(Class<?> clazz, DynamoDBScanExpression scanExpression, DynamoDBMapperConfig config) { config = mergeConfig(config); final ScanRequest scanRequest = createScanRequestFromExpression(clazz, scanExpression, config); scanRequest.setSelect(Select.COUNT); // Count scans can also be truncated for large datasets int count = 0; ScanResult scanResult = null; do { scanResult = db.scan(applyUserAgent(scanRequest)); count += scanResult.getCount(); scanRequest.setExclusiveStartKey(scanResult.getLastEvaluatedKey()); } while (scanResult.getLastEvaluatedKey() != null); return count; }
/** * @param config never null */ ScanRequest createScanRequestFromExpression(Class<?> clazz, DynamoDBScanExpression scanExpression, DynamoDBMapperConfig config) { final ScanRequest scanRequest = new ScanRequest(); scanRequest.setTableName(getTableName(clazz, config)); scanRequest.setScanFilter(scanExpression.getScanFilter()); scanRequest.setLimit(scanExpression.getLimit()); scanRequest.setExclusiveStartKey(scanExpression.getExclusiveStartKey()); scanRequest.setTotalSegments(scanExpression.getTotalSegments()); scanRequest.setSegment(scanExpression.getSegment()); scanRequest.setConditionalOperator(scanExpression.getConditionalOperator()); scanRequest.setFilterExpression(scanExpression.getFilterExpression()); scanRequest.setExpressionAttributeNames(scanExpression .getExpressionAttributeNames()); scanRequest.setExpressionAttributeValues(scanExpression .getExpressionAttributeValues()); scanRequest.setRequestMetricCollector(config.getRequestMetricCollector()); return applyUserAgent(scanRequest); }
@Override protected Iterator<? extends Map<String, AttributeValue>> nextIterator(final int count) { // the first iterator should be the initial results if (count == 1) { return currentResult.getItems().iterator(); } // subsequent chained iterators will be obtained from dynamoDB // pagination if ((currentResult.getLastEvaluatedKey() == null) || currentResult.getLastEvaluatedKey().isEmpty()) { return null; } else { request.setExclusiveStartKey(currentResult.getLastEvaluatedKey()); currentResult = dynamoDBClient.scan(request); return currentResult.getItems().iterator(); } } }
@Override protected synchronized List<T> fetchNextPage() { scanRequest.setExclusiveStartKey(scanResult.getLastEvaluatedKey()); scanResult = dynamo.scan(DynamoDBMapper.applyUserAgent(scanRequest)); return mapper.marshallIntoObjects(mapper.toParameters( scanResult.getItems(), clazz, scanRequest.getTableName(), config)); }
@Override public Page<Item, ScanOutcome> firstPage() { ScanRequest request = spec.getRequest(); request.setExclusiveStartKey(startKey); request.setLimit(InternalUtils.minimum( spec.getMaxResultSize(), spec.getMaxPageSize())); ScanResult result = client.scan(request); ScanOutcome outcome = new ScanOutcome(result); setLastLowLevelResult(outcome); return new ScanPage(client, spec, request, 0, outcome); }
@Override public int count(Class<?> clazz, DynamoDBScanExpression scanExpression, DynamoDBMapperConfig config) { config = mergeConfig(config); ScanRequest scanRequest = createScanRequestFromExpression(clazz, scanExpression, config); scanRequest.setSelect(Select.COUNT); // Count scans can also be truncated for large datasets int count = 0; ScanResult scanResult = null; do { scanResult = db.scan(applyUserAgent(scanRequest)); count += scanResult.getCount(); scanRequest.setExclusiveStartKey(scanResult.getLastEvaluatedKey()); } while (scanResult.getLastEvaluatedKey() != null); return count; }