Search in sources :

Example 1 with QueryOutcome

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

the class SampleDataTryQuery method findRepliesInLast15DaysWithConfig.

private static void findRepliesInLast15DaysWithConfig(String tableName, String forumName, String threadSubject) {
    String replyId = forumName + "#" + threadSubject;
    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);
    Table table = dynamoDB.getTable(tableName);
    QuerySpec querySpec = new QuerySpec().withKeyConditionExpression("Id = :v1 and ReplyDateTime > :v2").withValueMap(new ValueMap().withString(":v1", replyId).withString(":v2", twoWeeksAgoStr)).withProjectionExpression("Message, ReplyDateTime, PostedBy");
    ItemCollection<QueryOutcome> items = table.query(querySpec);
    Iterator<Item> iterator = items.iterator();
    System.out.println("Query: printing results...");
    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 2 with QueryOutcome

use of com.amazonaws.services.dynamodbv2.document.QueryOutcome 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 3 with QueryOutcome

use of com.amazonaws.services.dynamodbv2.document.QueryOutcome 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 4 with QueryOutcome

use of com.amazonaws.services.dynamodbv2.document.QueryOutcome 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)

Example 5 with QueryOutcome

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

the class MoviesQuery 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");
    HashMap<String, String> nameMap = new HashMap<String, String>();
    nameMap.put("#yr", "year");
    HashMap<String, Object> valueMap = new HashMap<String, Object>();
    valueMap.put(":yyyy", 1985);
    QuerySpec querySpec = new QuerySpec().withKeyConditionExpression("#yr = :yyyy").withNameMap(nameMap).withValueMap(valueMap);
    ItemCollection<QueryOutcome> items = null;
    Iterator<Item> iterator = null;
    Item item = null;
    try {
        System.out.println("Movies from 1985");
        items = table.query(querySpec);
        iterator = items.iterator();
        while (iterator.hasNext()) {
            item = iterator.next();
            System.out.println(item.getNumber("year") + ": " + item.getString("title"));
        }
    } catch (Exception e) {
        System.err.println("Unable to query movies from 1985");
        System.err.println(e.getMessage());
    }
    valueMap.put(":yyyy", 1992);
    valueMap.put(":letter1", "A");
    valueMap.put(":letter2", "L");
    querySpec.withProjectionExpression("#yr, title, info.genres, info.actors[0]").withKeyConditionExpression("#yr = :yyyy and title between :letter1 and :letter2").withNameMap(nameMap).withValueMap(valueMap);
    try {
        System.out.println("Movies from 1992 - titles A-L, with genres and lead actor");
        items = table.query(querySpec);
        iterator = items.iterator();
        while (iterator.hasNext()) {
            item = iterator.next();
            System.out.println(item.getNumber("year") + ": " + item.getString("title") + " " + item.getMap("info"));
        }
    } catch (Exception e) {
        System.err.println("Unable to query movies from 1992:");
        System.err.println(e.getMessage());
    }
}
Also used : Table(com.amazonaws.services.dynamodbv2.document.Table) HashMap(java.util.HashMap) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) QueryOutcome(com.amazonaws.services.dynamodbv2.document.QueryOutcome) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) Item(com.amazonaws.services.dynamodbv2.document.Item) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)

Aggregations

QuerySpec (com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)18 Item (com.amazonaws.services.dynamodbv2.document.Item)10 QueryOutcome (com.amazonaws.services.dynamodbv2.document.QueryOutcome)10 Table (com.amazonaws.services.dynamodbv2.document.Table)10 ValueMap (com.amazonaws.services.dynamodbv2.document.utils.ValueMap)10 Test (org.testng.annotations.Test)6 Date (java.util.Date)5 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)4 X509CertRecord (com.yahoo.athenz.common.server.cert.X509CertRecord)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Index (com.amazonaws.services.dynamodbv2.document.Index)2 ConditionalCheckFailedException (com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)2 TransactionConflictException (com.amazonaws.services.dynamodbv2.model.TransactionConflictException)2 WorkloadRecord (com.yahoo.athenz.common.server.workload.WorkloadRecord)2 HashMap (java.util.HashMap)2 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)1 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)1 ItemCollection (com.amazonaws.services.dynamodbv2.document.ItemCollection)1