Example usage for com.amazonaws.services.dynamodbv2.model KeysAndAttributes setConsistentRead

List of usage examples for com.amazonaws.services.dynamodbv2.model KeysAndAttributes setConsistentRead

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.model KeysAndAttributes setConsistentRead.

Prototype


public void setConsistentRead(Boolean consistentRead) 

Source Link

Document

The consistency of a read operation.

Usage

From source file:jp.classmethod.aws.dynamodb.DynamoDbRepository.java

License:Open Source License

private List<E> findAll(Iterable<AttributeValue> ids, boolean useParallelBatches) {
    Preconditions.checkNotNull(ids, "ids may not be null");
    List<AttributeValue> idList = Lists.newArrayList(ids);
    if (idList.isEmpty()) {
        return new ArrayList<>();
    }/*from   w w w. j a v  a2s  .  c o  m*/
    List<Map<String, AttributeValue>> resultantItems = new ArrayList<>();

    StreamSupport.stream(Iterables.partition(idList, 25).spliterator(), useParallelBatches).forEach(inner -> {
        BatchGetItemRequest req = new BatchGetItemRequest();
        KeysAndAttributes keysAndAttributes = new KeysAndAttributes();
        keysAndAttributes.setConsistentRead(true);
        keysAndAttributes.setKeys(
                inner.stream().map(id -> ImmutableMap.of(hashKeyName, id)).collect(Collectors.toList()));
        String tableName = tableName();
        req.withRequestItems(ImmutableMap.of(tableName, keysAndAttributes));

        BatchGetItemResult result;

        do {
            try {
                result = dynamoDB.batchGetItem(req);
                resultantItems.addAll(result.getResponses().get(tableName));
                req.setRequestItems(result.getUnprocessedKeys());
            } catch (AmazonClientException e) {
                throw this.convertDynamoDBException(e, "batch get", null /*no conditions for reads*/);
            }
        } while (false == result.getUnprocessedKeys().isEmpty());
    });

    return resultantItems.stream().map(legacyItem -> Item.fromMap(InternalUtils.toSimpleMapValue(legacyItem)))
            .map(item -> convertItemToDomain(item)).collect(Collectors.toList());
}

From source file:org.iternine.jeppetto.dao.dynamodb.DynamoDBQueryModelDAO.java

License:Apache License

@Override
public Iterable<T> findByIds(ID... ids) throws JeppettoException {
    Collection<Map<String, AttributeValue>> keys = new ArrayList<Map<String, AttributeValue>>();

    for (ID id : ids) {
        keys.add(getKeyFrom(id));/*from w  w w .  ja va 2 s.  co  m*/
    }

    KeysAndAttributes keysAndAttributes = new KeysAndAttributes().withKeys(keys);

    keysAndAttributes.setConsistentRead(consistentRead);
    keysAndAttributes.setProjectionExpression(projectionExpression);

    if (!projectionExpressionNames.isEmpty()) {
        keysAndAttributes.setExpressionAttributeNames(projectionExpressionNames);
    }

    BatchGetItemRequest batchGetItemRequest = new BatchGetItemRequest()
            .withRequestItems(Collections.singletonMap(tableName, keysAndAttributes));

    return new BatchGetIterable<T>(dynamoDB, persistableEnhancer, batchGetItemRequest, tableName);
}