Java Code Examples for com.amazonaws.services.dynamodbv2.document.Table#getItem()

The following examples show how to use com.amazonaws.services.dynamodbv2.document.Table#getItem() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TryDaxTests.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
void getItemTest(String tableName, DynamoDB client, int pk, int sk, int iterations) {
    long startTime, endTime;
    System.out.println("GetItem test - partition key " + pk + " and sort keys 1-" + sk);
    Table table = client.getTable(tableName);

    for (int i = 0; i < iterations; i++) {
        startTime = System.nanoTime();
        try {
            for (Integer ipk = 1; ipk <= pk; ipk++) {
                for (Integer isk = 1; isk <= sk; isk++) {
                    table.getItem("pk", ipk, "sk", isk);
                }
            }
        } catch (Exception e) {
            System.err.println("Unable to get item:");
            e.printStackTrace();
        }
        endTime = System.nanoTime();
        printTime(startTime, endTime, pk * sk);
    }
}
 
Example 2
Source File: DocumentAPIItemCRUDExample.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
private static void retrieveItem() {
    Table table = dynamoDB.getTable(tableName);

    try {

        Item item = table.getItem("Id", 120, "Id, ISBN, Title, Authors", null);

        System.out.println("Printing item after retrieving it....");
        System.out.println(item.toJSONPretty());

    }
    catch (Exception e) {
        System.err.println("GetItem failed.");
        System.err.println(e.getMessage());
    }

}
 
Example 3
Source File: DocumentAPIItemBinaryExample.java    From aws-dynamodb-examples with Apache License 2.0 6 votes vote down vote up
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");
}
 
Example 4
Source File: DynamoDBInstalledAppContextStore.java    From smartapp-sdk-java with Apache License 2.0 5 votes vote down vote up
private DefaultInstalledAppContext readFromDb(String installedAppId) {
    Table table = dynamoDB.getTable(tableName);
    Item item = table.getItem("installedAppId", installedAppId);

    if (item == null) {
        if (log.isInfoEnabled()) {
            log.info("could not find installed app " + installedAppId);
        }
        return null;
    }

    return contextFromItem(item);
}
 
Example 5
Source File: DynamoDBServiceImpl1.java    From Serverless-Programming-Cookbook with MIT License 5 votes vote down vote up
@Override
public final Response getItem(final Request request) {

    Table table = dynamoDB.getTable(request.getTableName());

    Item item = table.getItem(new PrimaryKey()
            .addComponent(request.getPartitionKey(), request.getPartitionKeyValue())
            .addComponent(request.getSortKey(), Integer.parseInt(request.getSortKeyValue())));

    return new Response("PK of item read using get-item (V1): " + prepareKeyStr(item, request), null);
}
 
Example 6
Source File: DynamoDBAnnouncementWatcher.java    From hollow-reference-implementation with Apache License 2.0 5 votes vote down vote up
public long readLatestVersion() {
    Table table = dynamoDB.getTable(tableName);

    Item item = table.getItem("namespace", blobNamespace,
            "version, pin_version", null);

    if (item.isPresent("pin_version") && !item.isNull("pin_version"))
        return item.getLong("pin_version");

    return item.getLong("version");
}
 
Example 7
Source File: MoviesItemOps02.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
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());
        }

    }
 
Example 8
Source File: DocumentAPIItemBinaryExample.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
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");
    }
 
Example 9
Source File: DocumentAPIItemCRUDExample.java    From aws-dynamodb-examples with Apache License 2.0 4 votes vote down vote up
private static void retrieveItem() {
    Table table = dynamoDB.getTable(tableName);

    try {

        Item item = table.getItem("Id", 120,  "Id, ISBN, Title, Authors", null);

        System.out.println("Printing item after retrieving it....");
        System.out.println(item.toJSONPretty());

    } catch (Exception e) {
        System.err.println("GetItem failed.");
        System.err.println(e.getMessage());
    }   

}
 
Example 10
Source File: SampleDataTryQuery.java    From aws-doc-sdk-examples with Apache License 2.0 3 votes vote down vote up
private static void getBook(int id, String tableName) {

        Table table = dynamoDB.getTable(tableName);

        Item item = table.getItem("Id", // attribute name
            id, // attribute value
            "Id, ISBN, Title, Authors", // projection expression
            null); // name map - don't need this

        System.out.println("GetItem: printing results...");
        System.out.println(item.toJSONPretty());

    }
 
Example 11
Source File: GettingStartedTryQuery.java    From aws-dynamodb-examples with Apache License 2.0 3 votes vote down vote up
private static void getBook(int id, String tableName) {

        Table table = dynamoDB.getTable(tableName);

        Item item = table.getItem("Id", // attribute name
                id, // attribute value
                "Id, ISBN, Title, Authors", // projection expression
                null); // name map - don't need this

        System.out.println("GetItem: printing results...");
        System.out.println(item.toJSONPretty());

    }