Example usage for com.amazonaws.services.dynamodbv2.model PutItemRequest setItem

List of usage examples for com.amazonaws.services.dynamodbv2.model PutItemRequest setItem

Introduction

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

Prototype


public void setItem(java.util.Map<String, AttributeValue> item) 

Source Link

Document

A map of attribute name/value pairs, one for each attribute.

Usage

From source file:com.vitembp.embedded.configuration.CloudConfigSync.java

License:Open Source License

/**
 * Registers the device's ID to the database.
 * @throws IOException /*w  w  w  .ja  va 2s .  co  m*/
 */
private static void registerDevice() throws IOException {
    // get configuration string
    String config;
    try {
        config = SystemConfig.getConfig().writeToString();
    } catch (XMLStreamException ex) {
        throw new IOException("Could not generate configuration string.", ex);
    }

    // add holds data to store in table.
    Map<String, AttributeValue> itemToSet = new HashMap<>();
    PutItemRequest pir = new PutItemRequest();
    pir.setConditionExpression("attribute_not_exists(ID)");
    // add the system ID
    itemToSet.put("ID", new AttributeValue(SystemConfig.getConfig().getSystemUUID().toString()));
    itemToSet.put("CONFIG", new AttributeValue(config));
    itemToSet.put("UPDATED", new AttributeValue(Boolean.toString(false)));
    pir.setTableName("DEVICES");
    pir.setItem(itemToSet);

    try {
        CloudConfigSync.client.putItem(pir);
        CloudConfigSync.deviceRegistered = true;
        LOGGER.info("Device successfully registered.");
    } catch (ConditionalCheckFailedException e) {
        CloudConfigSync.deviceRegistered = true;
        LOGGER.debug("Device already registered.");
    } catch (ResourceNotFoundException e) {
        LOGGER.error("The database does not contain the device index table.", e);
    } catch (AmazonServiceException e) {
        LOGGER.error("Exception occurred writing to database.", e);
    }
}