Example usage for com.amazonaws.services.dynamodbv2.document DynamoDB getTable

List of usage examples for com.amazonaws.services.dynamodbv2.document DynamoDB getTable

Introduction

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

Prototype

public Table getTable(String tableName) 

Source Link

Document

Returns the specified DynamoDB table.

Usage

From source file:oxwodwebdriver.DynamoHelper.java

public static void UploadProcessedWodDataToDynamoDB(String wod, String cardText) {
    System.out.println("About to upload data to DynamoDB");

    BasicAWSCredentials awsCreds = new BasicAWSCredentials("", "");
    AmazonDynamoDBClient client = new AmazonDynamoDBClient(awsCreds).withRegion(Regions.US_EAST_1);
    DynamoDB dynamoDB = new DynamoDB(client);
    Table table = dynamoDB.getTable("OxWod");

    Map<String, String> expressionAttributeNames = new HashMap<String, String>();
    expressionAttributeNames.put("#W", "Wod");
    expressionAttributeNames.put("#C", "CardWod");

    Map<String, Object> expressionAttributeValues = new HashMap<String, Object>();
    expressionAttributeValues.put(":val1", wod);
    expressionAttributeValues.put(":val2", cardText);

    UpdateItemOutcome outcome = table.updateItem("Id", // key attribute name
            1, // key attribute value
            "set #W = :val1, #C = :val2", // UpdateExpression
            expressionAttributeNames, expressionAttributeValues);
    System.out.println("Fnished uploading data to DynamoDB");
}

From source file:vfma.LoadSensorData.java

License:Open Source License

public ArrayList<RawSensorData> getSensorData(String lastTimestamp) throws VFMException {

    ArrayList<RawSensorData> rsdlist = new ArrayList<RawSensorData>();

    try {/*w  ww .  j  ava2s.c  o m*/

        AmazonDynamoDBClient client = new AmazonDynamoDBClient()
                .withEndpoint("https://dynamodb.us-west-2.amazonaws.com");
        DynamoDB dynamoDB = new DynamoDB(client);
        Table table = dynamoDB.getTable("sensorData");
        ScanSpec scanSpec = new ScanSpec();

        System.out.println("Get sensors...");
        ItemCollection<ScanOutcome> items = table.scan(scanSpec);

        String lastTimeValue;

        Iterator<Item> iter = items.iterator();
        while (iter.hasNext()) {
            Item item = iter.next();

            RawSensorData rsd = new RawSensorData();

            rsd.setTimestamp(item.getJSON("pass").replace("\"", ""));
            final JSONObject rawData = new JSONObject(item.getJSON("payload"));
            rsd.setSensorId(rawData.getString("sensor_id_time"));
            rsd.setPassing(rawData.getString("passing"));

            System.out.println("Read " + rsd.getSensorId());

            if (rsd.getTimestamp().compareTo(lastTimestamp) > 0)
                rsdlist.add(rsd);

            lastTimeValue = rsd.getTimestamp();
        }

    } catch (Exception e) {
        System.err.println("Unable to scan the table:");
        System.err.println(e.getMessage());
    }

    return rsdlist;
}