Example usage for com.amazonaws.services.dynamodbv2.document Item withString

List of usage examples for com.amazonaws.services.dynamodbv2.document Item withString

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.document Item withString.

Prototype

public Item withString(String attrName, String val) 

Source Link

Document

Sets the value of the specified attribute in the current item to the given string value.

Usage

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

public static String upload_resource(BaseResource resource,
        String primary_key /* if no primary key in case of post, send null*/ ) throws Exception {
    String id = add_primary_as_extension(resource, primary_key);
    String resource_string = DynamoDBConnection.fCtx.newJsonParser().setPrettyPrint(true)
            .encodeResourceToString(resource);
    ;// w w w  . jav a2  s.  c o  m
    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);
        retreived_item.withInt("version", -1);
    }

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

    Item item_to_upload = retreived_item//Item.fromJSON(retreived_item.toJSONPretty())
            .withString("text" + new_version.toString(), resource_string)
            .withMap("json-document", new ObjectMapper().readValue(resource_string, LinkedHashMap.class));
    PutItemSpec putItemSpec = new PutItemSpec().withItem(item_to_upload);
    table.putItem(putItemSpec);
    return id;
}

From source file:io.helixservice.feature.configuration.dynamo.DynamoConfigResourceLocator.java

License:Open Source License

private void createEmptyConfiguration(String environmentName) {
    try {/*from www  .  j  a  v a 2  s.co m*/
        Item item = new Item();
        item.withString("environment", environmentName);
        item.withString("service", serviceName);
        item.withJSON("config", "{}");
        configTable.putItem(item);
        LOG.info("Created default configuration in DynamoDB for environment=" + environmentName);
    } catch (Throwable t) {
        LOG.error("Unable to create default configuration in DynamoDB for environment=" + environmentName, t);
    }
}