Example usage for com.amazonaws.services.dynamodbv2.model PutRequest PutRequest

List of usage examples for com.amazonaws.services.dynamodbv2.model PutRequest PutRequest

Introduction

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

Prototype

public PutRequest() 

Source Link

Document

Default constructor for PutRequest object.

Usage

From source file:org.apache.hadoop.dynamodb.DynamoDBClient.java

License:Open Source License

public BatchWriteItemResult putBatch(String tableName, Map<String, AttributeValue> item, long maxItemsPerBatch,
        Reporter reporter) throws UnsupportedEncodingException {
    int itemSizeBytes = DynamoDBUtil.getItemSizeBytes(item);
    if (itemSizeBytes > maxItemByteSize) {
        throw new RuntimeException("Cannot pass items with size greater than " + maxItemByteSize
                + ". Item with size of " + itemSizeBytes + " was given.");
    }//from  w  w w  .j a  v a  2  s.  c  om
    maxItemsPerBatch = DynamoDBUtil.getBoundedBatchLimit(config, maxItemsPerBatch);
    BatchWriteItemResult result = null;
    if (writeBatchMap.containsKey(tableName)) {

        boolean writeRequestsForTableAtLimit = writeBatchMap.get(tableName).size() >= maxItemsPerBatch;

        boolean totalSizeOfWriteBatchesOverLimit = writeBatchMapSizeBytes + itemSizeBytes > maxBatchSize;

        if (writeRequestsForTableAtLimit || totalSizeOfWriteBatchesOverLimit) {
            result = writeBatch(reporter, itemSizeBytes);
        }
    }
    // writeBatchMap could be cleared from writeBatch()
    List<WriteRequest> writeBatchList;
    if (!writeBatchMap.containsKey(tableName)) {
        writeBatchList = new ArrayList<>((int) maxItemsPerBatch);
        writeBatchMap.put(tableName, writeBatchList);
    } else {
        writeBatchList = writeBatchMap.get(tableName);
    }
    writeBatchList.add(new WriteRequest().withPutRequest(new PutRequest().withItem(item)));
    writeBatchMapSizeBytes += itemSizeBytes;

    return result;
}