本文整理汇总了Java中com.amazonaws.services.dynamodbv2.model.ScanRequest.withExclusiveStartKey方法的典型用法代码示例。如果您正苦于以下问题:Java ScanRequest.withExclusiveStartKey方法的具体用法?Java ScanRequest.withExclusiveStartKey怎么用?Java ScanRequest.withExclusiveStartKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.dynamodbv2.model.ScanRequest
的用法示例。
在下文中一共展示了ScanRequest.withExclusiveStartKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scan
import com.amazonaws.services.dynamodbv2.model.ScanRequest; //导入方法依赖的package包/类
private Stream<Entry> scan(SecretEventStream.Filter<Entry> filter, Converters converters) {
ScanRequest scanRequest = new ScanRequest();
scanRequest.withConsistentRead(true);
scanRequest.withTableName(tableName);
FilterGenerator filterGenerator = new FilterGenerator();
FilterGenerator.Filter generated = filterGenerator.process(filter.parsedAttributeCondition.get(), converters);
if(!generated.expressionAttributeNames.isEmpty()) {
scanRequest.withExpressionAttributeNames(generated.expressionAttributeNames);
}
if (!generated.expressionAttributeValues.isEmpty()) {
scanRequest.withExpressionAttributeValues(generated.expressionAttributeValues);
}
scanRequest.withFilterExpression(generated.filterExpression);
ScanResult result = client.scan(scanRequest);
List<Map<String, AttributeValue>> results = new ArrayList<>();
results.addAll(result.getItems());
while (result.getLastEvaluatedKey() != null) {
scanRequest = scanRequest.withExclusiveStartKey(result.getLastEvaluatedKey());
result = client.scan(scanRequest);
results.addAll(result.getItems());
}
Stream<Entry> typedResult = results.stream().map(this::fromMap);
if (filter.reverse) {
typedResult = Lists.reverse(typedResult.collect(Collectors.toCollection(LinkedList::new))).stream();
}
return typedResult;
}
示例2: run
import com.amazonaws.services.dynamodbv2.model.ScanRequest; //导入方法依赖的package包/类
@Override
public void run() {
Map<String, AttributeValue> exclusiveStartKey = null;
ScanRequest scanRequest = new ScanRequest().withTableName(tableName).withAttributesToGet(attributesToGet)
.withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL).withTotalSegments(numOfSegments).withSegment(segmentNum);
boolean scanNumLimitReached = false;
while (!scanNumLimitReached) {
scanRequest.withExclusiveStartKey(exclusiveStartKey);
ScanResult scanResult = dynamoDBClient.scan(scanRequest);
if(!isRunningOnDDBLocal) {
// DDB Local does not support rate limiting
tableReadRateLimiter.adjustRateWithConsumedCapacity(scanResult.getConsumedCapacity());
}
for (Map<String, AttributeValue> item : scanResult.getItems()) {
checkItemViolationAndAddDeleteRequest(item);
itemsScanned.addAndGet(1);
itemScannedByThread += 1;
scanNumLimitReached = isScanNumberLimitReached();
if(scanNumLimitReached) {
break;
}
}
if (deleteViolationAfterFound) {
sendDeleteViolations();
}
PrintHelper.printScanProgress(itemsScanned.get(), itemScannedByThread, violationFoundByThread, violationDeleteByThread);
if (null == (exclusiveStartKey = scanResult.getLastEvaluatedKey())) {
break;
}
}
return;
}
示例3: readPageFromTable
import com.amazonaws.services.dynamodbv2.model.ScanRequest; //导入方法依赖的package包/类
/**
* Reads a page from a standard DynamoDB table.
* @param <P> type of object
* @param appid the app identifier (name)
* @param p a {@link Pager}
* @return the last row key of the page, or null.
*/
public static <P extends ParaObject> List<P> readPageFromTable(String appid, Pager p) {
Pager pager = (p != null) ? p : new Pager();
ScanRequest scanRequest = new ScanRequest().
withTableName(getTableNameForAppid(appid)).
withLimit(pager.getLimit()).
withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);
if (!StringUtils.isBlank(pager.getLastKey())) {
scanRequest = scanRequest.withExclusiveStartKey(Collections.
singletonMap(Config._KEY, new AttributeValue(pager.getLastKey())));
}
ScanResult result = getClient().scan(scanRequest);
LinkedList<P> results = new LinkedList<>();
for (Map<String, AttributeValue> item : result.getItems()) {
P obj = fromRow(item);
if (obj != null) {
results.add(obj);
}
}
if (result.getLastEvaluatedKey() != null) {
pager.setLastKey(result.getLastEvaluatedKey().get(Config._KEY).getS());
} else if (!results.isEmpty()) {
// set last key to be equal to the last result - end reached.
pager.setLastKey(results.peekLast().getId());
}
return results;
}
示例4: all
import com.amazonaws.services.dynamodbv2.model.ScanRequest; //导入方法依赖的package包/类
private Stream<Entry> all() {
ScanRequest scanRequest = new ScanRequest();
scanRequest.withConsistentRead(true);
scanRequest.withTableName(tableName);
ScanResult result = client.scan(scanRequest);
List<Map<String, AttributeValue>> results = new ArrayList<>();
results.addAll(result.getItems());
while (result.getLastEvaluatedKey() != null) {
scanRequest = scanRequest.withExclusiveStartKey(result.getLastEvaluatedKey());
result = client.scan(scanRequest);
results.addAll(result.getItems());
}
return results.stream().map(this::fromMap);
}
示例5: getPagedItems
import com.amazonaws.services.dynamodbv2.model.ScanRequest; //导入方法依赖的package包/类
/**
* @{inheritDoc
*/
@SuppressWarnings("unchecked")
@Override
public PagedDatabaseResult getPagedItems(String tableName, Object nextToken, String minRange,
String maxRange, String instanceId, String jobId) {
List<Item> ret = new ArrayList<Item>();
Map<String, AttributeValue> lastKeyEvaluated = (Map<String, AttributeValue>) nextToken;
ScanRequest scanRequest = new ScanRequest().withTableName(tableName);
Map<String, Condition> conditions = new HashMap<String, Condition>();
if (jobId != null) {
Condition jobIdCondition = new Condition();
jobIdCondition.withComparisonOperator(ComparisonOperator.EQ)
.withAttributeValueList(new AttributeValue().withS(jobId));
conditions.put(DatabaseKeys.JOB_ID_KEY.getShortKey(), jobIdCondition);
}
if (StringUtils.isNotBlank(instanceId)) {
// add a filter
Condition filter = new Condition();
filter.withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(
new AttributeValue().withS(instanceId));
scanRequest.addScanFilterEntry(DatabaseKeys.INSTANCE_ID_KEY.getShortKey(), filter);
}
Condition rangeKeyCondition = new Condition();
if (minRange != null && maxRange != null) {
rangeKeyCondition.withComparisonOperator(ComparisonOperator.BETWEEN.toString())
.withAttributeValueList(new AttributeValue().withS(minRange))
.withAttributeValueList(new AttributeValue().withS(maxRange));
} else if (minRange != null) {
rangeKeyCondition.withComparisonOperator(ComparisonOperator.GE.toString())
.withAttributeValueList(new AttributeValue().withS(minRange));
} else if (maxRange != null) {
rangeKeyCondition.withComparisonOperator(ComparisonOperator.LT.toString())
.withAttributeValueList(new AttributeValue().withS(maxRange));
} else {
rangeKeyCondition = null;
}
if (rangeKeyCondition != null) {
conditions.put(DatabaseKeys.REQUEST_NAME_KEY.getShortKey(), rangeKeyCondition);
}
scanRequest.withScanFilter(conditions);
scanRequest.withExclusiveStartKey(lastKeyEvaluated);
ScanResult result = dynamoDb.scan(scanRequest);
for (Map<String, AttributeValue> item : result.getItems()) {
ret.add(getItemFromResult(item));
}
return new PagedDatabaseResult(ret, result.getLastEvaluatedKey());
}