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

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

Introduction

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

Prototype


public void setTableName(String tableName) 

Source Link

Document

The name of the table to contain the item.

Usage

From source file:amazon.dynamodb.config.DynamoDBManager.java

License:Open Source License

public PutPointResult putPoint(PutPointRequest putPointRequest) {
    long geohash = S2Manager.generateGeohash(putPointRequest.getGeoPoint());
    long hashKey = S2Manager.generateHashKey(geohash, config.getHashKeyLength());
    String geoJson = GeoJsonMapper.stringFromGeoObject(putPointRequest.getGeoPoint());

    PutItemRequest putItemRequest = putPointRequest.getPutItemRequest();
    putItemRequest.setTableName(config.getTableName());

    AttributeValue hashKeyValue = new AttributeValue().withN(String.valueOf(hashKey));
    putItemRequest.getItem().put(config.getHashKeyAttributeName(), hashKeyValue);
    putItemRequest.getItem().put(config.getRangeKeyAttributeName(), putPointRequest.getRangeKeyValue());
    AttributeValue geohashValue = new AttributeValue().withN(Long.toString(geohash));
    putItemRequest.getItem().put(config.getGeohashAttributeName(), geohashValue);
    AttributeValue geoJsonValue = new AttributeValue().withS(geoJson);
    putItemRequest.getItem().put(config.getGeoJsonAttributeName(), geoJsonValue);

    PutItemResult putItemResult = config.getDynamoDBClient().putItem(putItemRequest);
    PutPointResult putPointResult = new PutPointResult(putItemResult);

    return putPointResult;
}

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

License:Open Source License

/**
 * Registers the device's ID to the database.
 * @throws IOException //from  www .  ja  v a 2 s . c om
 */
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);
    }
}