Example usage for com.amazonaws.services.dynamodbv2.model ReturnValue NONE

List of usage examples for com.amazonaws.services.dynamodbv2.model ReturnValue NONE

Introduction

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

Prototype

ReturnValue NONE

To view the source code for com.amazonaws.services.dynamodbv2.model ReturnValue NONE.

Click Source Link

Usage

From source file:com.eho.dynamodb.DynamoDBConnection.java

public static PutItemOutcome upload_resource_old(String resource) throws Exception {
    String id;// ww w .j  a v a 2  s .  c  o  m
    JSONObject json_resource = new JSONObject(resource);
    //does the resource have a primary key?
    if (json_resource.has(PRIMARY_KEY))//if it does not have a primary key, create one using uuid
        id = json_resource.getString(PRIMARY_KEY);
    else
        id = UUID.randomUUID().toString();

    DynamoDB dynamoDB = new DynamoDB(dynamoDBClient);
    Table table = dynamoDB.getTable(PATIENT_TABLE);

    //lets retreive based on the key. if key invalid (not assigned yet) nullis returned.
    Item retreived_item = table.getItem(PRIMARY_KEY, id);
    if (retreived_item == null)//if null instantiate it
    {
        retreived_item = new Item();
        retreived_item.withPrimaryKey(PRIMARY_KEY, id);
    }

    Integer new_version = retreived_item.getInt("version") + 1;
    retreived_item.withInt("version", new_version);

    Item item_to_upload = Item.fromJSON(retreived_item.toJSONPretty()).withJSON("Document", resource);
    PutItemSpec putItemSpec = new PutItemSpec().withItem(item_to_upload).withReturnValues(ReturnValue.NONE);
    return table.putItem(putItemSpec);
}