Search in sources :

Example 51 with Item

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

the class StreamsAdapterDemoHelper method putItem.

public static void putItem(AmazonDynamoDB dynamoDBClient, String tableName, String id, String val) {
    java.util.Map<String, AttributeValue> item = new HashMap<String, AttributeValue>();
    item.put("Id", new AttributeValue().withN(id));
    item.put("attribute-1", new AttributeValue().withS(val));
    PutItemRequest putItemRequest = new PutItemRequest().withTableName(tableName).withItem(item);
    dynamoDBClient.putItem(putItemRequest);
}
Also used : AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) HashMap(java.util.HashMap) PutItemRequest(com.amazonaws.services.dynamodbv2.model.PutItemRequest)

Example 52 with Item

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

the class DocumentAPIItemBinaryExample method createItem.

public static void createItem(String threadId, String replyDateTime) throws IOException {
    Table table = dynamoDB.getTable(tableName);
    // Craft a long message
    String messageInput = "Long message to be compressed in a lengthy forum reply";
    // Compress the long message
    ByteBuffer compressedMessage = compressString(messageInput.toString());
    table.putItem(new Item().withPrimaryKey("Id", threadId).withString("ReplyDateTime", replyDateTime).withString("Message", "Long message follows").withBinary("ExtendedMessage", compressedMessage).withString("PostedBy", "User A"));
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item) Table(com.amazonaws.services.dynamodbv2.document.Table) ByteBuffer(java.nio.ByteBuffer)

Example 53 with Item

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

the class DocumentAPIQuery method findRepliesInLast15DaysWithConfig.

private static void findRepliesInLast15DaysWithConfig(String forumName, String threadSubject) {
    Table table = dynamoDB.getTable(tableName);
    long twoWeeksAgoMilli = (new Date()).getTime() - (15L * 24L * 60L * 60L * 1000L);
    Date twoWeeksAgo = new Date();
    twoWeeksAgo.setTime(twoWeeksAgoMilli);
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    String twoWeeksAgoStr = df.format(twoWeeksAgo);
    String replyId = forumName + "#" + threadSubject;
    QuerySpec spec = new QuerySpec().withProjectionExpression("Message, ReplyDateTime, PostedBy").withKeyConditionExpression("Id = :v_id and ReplyDateTime <= :v_reply_dt_tm").withValueMap(new ValueMap().withString(":v_id", replyId).withString(":v_reply_dt_tm", twoWeeksAgoStr));
    ItemCollection<QueryOutcome> items = table.query(spec);
    System.out.println("\nfindRepliesInLast15DaysWithConfig results:");
    Iterator<Item> iterator = items.iterator();
    while (iterator.hasNext()) {
        System.out.println(iterator.next().toJSONPretty());
    }
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item) Table(com.amazonaws.services.dynamodbv2.document.Table) ValueMap(com.amazonaws.services.dynamodbv2.document.utils.ValueMap) QueryOutcome(com.amazonaws.services.dynamodbv2.document.QueryOutcome) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 54 with Item

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

the class DocumentAPIQuery method findRepliesForAThread.

private static void findRepliesForAThread(String forumName, String threadSubject) {
    Table table = dynamoDB.getTable(tableName);
    String replyId = forumName + "#" + threadSubject;
    QuerySpec spec = new QuerySpec().withKeyConditionExpression("Id = :v_id").withValueMap(new ValueMap().withString(":v_id", replyId));
    ItemCollection<QueryOutcome> items = table.query(spec);
    System.out.println("\nfindRepliesForAThread results:");
    Iterator<Item> iterator = items.iterator();
    while (iterator.hasNext()) {
        System.out.println(iterator.next().toJSONPretty());
    }
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item) Table(com.amazonaws.services.dynamodbv2.document.Table) ValueMap(com.amazonaws.services.dynamodbv2.document.utils.ValueMap) QueryOutcome(com.amazonaws.services.dynamodbv2.document.QueryOutcome) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)

Example 55 with Item

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

the class DocumentAPIQuery method findRepliesForAThreadSpecifyOptionalLimit.

private static void findRepliesForAThreadSpecifyOptionalLimit(String forumName, String threadSubject) {
    Table table = dynamoDB.getTable(tableName);
    String replyId = forumName + "#" + threadSubject;
    QuerySpec spec = new QuerySpec().withKeyConditionExpression("Id = :v_id").withValueMap(new ValueMap().withString(":v_id", replyId)).withMaxPageSize(1);
    ItemCollection<QueryOutcome> items = table.query(spec);
    System.out.println("\nfindRepliesForAThreadSpecifyOptionalLimit results:");
    // Process each page of results
    int pageNum = 0;
    for (Page<Item, QueryOutcome> page : items.pages()) {
        System.out.println("\nPage: " + ++pageNum);
        // Process each item on the current page
        Iterator<Item> item = page.iterator();
        while (item.hasNext()) {
            System.out.println(item.next().toJSONPretty());
        }
    }
}
Also used : Item(com.amazonaws.services.dynamodbv2.document.Item) Table(com.amazonaws.services.dynamodbv2.document.Table) ValueMap(com.amazonaws.services.dynamodbv2.document.utils.ValueMap) QueryOutcome(com.amazonaws.services.dynamodbv2.document.QueryOutcome) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)

Aggregations

AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)107 Item (com.amazonaws.services.dynamodbv2.document.Item)95 HashMap (java.util.HashMap)60 Table (com.amazonaws.services.dynamodbv2.document.Table)53 Test (org.testng.annotations.Test)49 QuerySpec (com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)42 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)35 AmazonServiceException (com.amazonaws.AmazonServiceException)31 ValueMap (com.amazonaws.services.dynamodbv2.document.utils.ValueMap)27 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)26 ArrayList (java.util.ArrayList)25 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)24 List (java.util.List)23 Test (org.junit.Test)23 QueryOutcome (com.amazonaws.services.dynamodbv2.document.QueryOutcome)22 IOException (java.io.IOException)21 X509CertRecord (com.yahoo.athenz.common.server.cert.X509CertRecord)20 AmazonDynamoDBException (com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException)18 Date (java.util.Date)18 Map (java.util.Map)17