Search in sources :

Example 1 with GetItemSpec

use of com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec in project aws-doc-sdk-examples by awsdocs.

the class MoviesItemOps02 method main.

public static void main(String[] args) throws Exception {
    AmazonDynamoDB client = AmazonDynamoDBClientBuilder.standard().withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("http://localhost:8000", "us-west-2")).build();
    DynamoDB dynamoDB = new DynamoDB(client);
    Table table = dynamoDB.getTable("Movies");
    int year = 2015;
    String title = "The Big New Movie";
    GetItemSpec spec = new GetItemSpec().withPrimaryKey("year", year, "title", title);
    try {
        System.out.println("Attempting to read the item...");
        Item outcome = table.getItem(spec);
        System.out.println("GetItem succeeded: " + outcome);
    } catch (Exception e) {
        System.err.println("Unable to read item: " + year + " " + title);
        System.err.println(e.getMessage());
    }
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item) Table(com.amazonaws.services.dynamodbv2.document.Table) GetItemSpec(com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB)

Example 2 with GetItemSpec

use of com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec in project aws-doc-sdk-examples by awsdocs.

the class DocumentAPIItemBinaryExample method retrieveItem.

public static void retrieveItem(String threadId, String replyDateTime) throws IOException {
    Table table = dynamoDB.getTable(tableName);
    GetItemSpec spec = new GetItemSpec().withPrimaryKey("Id", threadId, "ReplyDateTime", replyDateTime).withConsistentRead(true);
    Item item = table.getItem(spec);
    // Uncompress the reply message and print
    String uncompressed = uncompressString(ByteBuffer.wrap(item.getBinary("ExtendedMessage")));
    System.out.println("Reply message:\n" + " Id: " + item.getString("Id") + "\n" + " ReplyDateTime: " + item.getString("ReplyDateTime") + "\n" + " PostedBy: " + item.getString("PostedBy") + "\n" + " Message: " + item.getString("Message") + "\n" + " ExtendedMessage (uncompressed): " + uncompressed + "\n");
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item) Table(com.amazonaws.services.dynamodbv2.document.Table) GetItemSpec(com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec)

Aggregations

Item (com.amazonaws.services.dynamodbv2.document.Item)2 Table (com.amazonaws.services.dynamodbv2.document.Table)2 GetItemSpec (com.amazonaws.services.dynamodbv2.document.spec.GetItemSpec)2 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)1 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)1