Search in sources :

Example 11 with ValueMap

use of com.amazonaws.services.dynamodbv2.document.utils.ValueMap in project athenz by yahoo.

the class DynamoDBCertRecordStoreConnection method mostUpdatedHostRecord.

private boolean mostUpdatedHostRecord(Item recordToCheck) {
    try {
        // Query all records with the same hostName / provider / service as recordToCheck
        QuerySpec spec = new QuerySpec().withKeyConditionExpression("hostName = :v_host_name").withFilterExpression("attribute_exists(provider) AND provider = :v_provider AND attribute_exists(service) AND service = :v_service").withValueMap(new ValueMap().withString(":v_host_name", recordToCheck.getString(KEY_HOSTNAME)).withString(":v_provider", recordToCheck.getString(KEY_PROVIDER)).withString(":v_service", recordToCheck.getString(KEY_SERVICE)));
        ItemCollection<QueryOutcome> outcome = itemCollectionRetryDynamoDBCommand.run(() -> hostNameIndex.query(spec));
        List<Item> allRecordsWithHost = new ArrayList<>();
        for (Item item : outcome) {
            allRecordsWithHost.add(item);
        }
        // Verify recordToCheck is the most updated record with this hostName
        return dynamoDBNotificationsHelper.isMostUpdatedRecordBasedOnAttribute(recordToCheck, allRecordsWithHost, KEY_CURRENT_TIME, KEY_PRIMARY);
    } catch (Exception ex) {
        LOGGER.error("DynamoDB mostUpdatedHostRecord failed for item: {}, error: {}", recordToCheck.toString(), ex.getMessage());
        return false;
    }
}
Also used : ValueMap(com.amazonaws.services.dynamodbv2.document.utils.ValueMap) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec) ConditionalCheckFailedException(com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)

Example 12 with ValueMap

use of com.amazonaws.services.dynamodbv2.document.utils.ValueMap in project athenz by yahoo.

the class DynamoDBCertRecordStoreConnection method getUnrefreshedCertRecordsByDate.

private List<Item> getUnrefreshedCertRecordsByDate(String provider, long yesterday, String unrefreshedCertDate) {
    try {
        QuerySpec spec = new QuerySpec().withKeyConditionExpression("currentDate = :v_current_date").withFilterExpression("provider = :v_provider AND attribute_exists(hostName) AND (attribute_not_exists(lastNotifiedTime) OR lastNotifiedTime < :v_last_notified)").withValueMap(new ValueMap().withString(":v_current_date", unrefreshedCertDate).withNumber(":v_last_notified", yesterday).withString(":v_provider", provider));
        ItemCollection<QueryOutcome> outcome = itemCollectionRetryDynamoDBCommand.run(() -> currentTimeIndex.query(spec));
        List<Item> items = new ArrayList<>();
        for (Item item : outcome) {
            items.add(item);
        }
        return items;
    } catch (Exception ex) {
        LOGGER.error("DynamoDB getUnrefreshedCertRecordsByDate failed for provider: {}, date: {} error: {}", provider, unrefreshedCertDate, ex.getMessage());
    }
    return new ArrayList<>();
}
Also used : ValueMap(com.amazonaws.services.dynamodbv2.document.utils.ValueMap) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec) ConditionalCheckFailedException(com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)

Example 13 with ValueMap

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

the class DocumentAPIGlobalSecondaryIndexExample method queryIndex.

public static void queryIndex(String indexName) {
    Table table = dynamoDB.getTable(tableName);
    System.out.println("\n***********************************************************\n");
    System.out.print("Querying index " + indexName + "...");
    Index index = table.getIndex(indexName);
    ItemCollection<QueryOutcome> items = null;
    QuerySpec querySpec = new QuerySpec();
    if (indexName == "CreateDateIndex") {
        System.out.println("Issues filed on 2013-11-01");
        querySpec.withKeyConditionExpression("CreateDate = :v_date and begins_with(IssueId, :v_issue)").withValueMap(new ValueMap().withString(":v_date", "2013-11-01").withString(":v_issue", "A-"));
        items = index.query(querySpec);
    } else if (indexName == "TitleIndex") {
        System.out.println("Compilation errors");
        querySpec.withKeyConditionExpression("Title = :v_title and begins_with(IssueId, :v_issue)").withValueMap(new ValueMap().withString(":v_title", "Compilation error").withString(":v_issue", "A-"));
        items = index.query(querySpec);
    } else if (indexName == "DueDateIndex") {
        System.out.println("Items that are due on 2013-11-30");
        querySpec.withKeyConditionExpression("DueDate = :v_date").withValueMap(new ValueMap().withString(":v_date", "2013-11-30"));
        items = index.query(querySpec);
    } else {
        System.out.println("\nNo valid index name provided");
        return;
    }
    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) Index(com.amazonaws.services.dynamodbv2.document.Index) GlobalSecondaryIndex(com.amazonaws.services.dynamodbv2.model.GlobalSecondaryIndex) QueryOutcome(com.amazonaws.services.dynamodbv2.document.QueryOutcome) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)

Example 14 with ValueMap

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

the class DocumentAPILocalSecondaryIndexExample method query.

public static void query(String indexName) {
    Table table = dynamoDB.getTable(tableName);
    System.out.println("\n***********************************************************\n");
    System.out.println("Querying table " + tableName + "...");
    QuerySpec querySpec = new QuerySpec().withConsistentRead(true).withScanIndexForward(true).withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);
    if (indexName == "IsOpenIndex") {
        System.out.println("\nUsing index: '" + indexName + "': Bob's orders that are open.");
        System.out.println("Only a user-specified list of attributes are returned\n");
        Index index = table.getIndex(indexName);
        querySpec.withKeyConditionExpression("CustomerId = :v_custid and IsOpen = :v_isopen").withValueMap(new ValueMap().withString(":v_custid", "bob@example.com").withNumber(":v_isopen", 1));
        querySpec.withProjectionExpression("OrderCreationDate, ProductCategory, ProductName, OrderStatus");
        ItemCollection<QueryOutcome> items = index.query(querySpec);
        Iterator<Item> iterator = items.iterator();
        System.out.println("Query: printing results...");
        while (iterator.hasNext()) {
            System.out.println(iterator.next().toJSONPretty());
        }
    } else if (indexName == "OrderCreationDateIndex") {
        System.out.println("\nUsing index: '" + indexName + "': Bob's orders that were placed after 01/31/2015.");
        System.out.println("Only the projected attributes are returned\n");
        Index index = table.getIndex(indexName);
        querySpec.withKeyConditionExpression("CustomerId = :v_custid and OrderCreationDate >= :v_orddate").withValueMap(new ValueMap().withString(":v_custid", "bob@example.com").withNumber(":v_orddate", 20150131));
        querySpec.withSelect(Select.ALL_PROJECTED_ATTRIBUTES);
        ItemCollection<QueryOutcome> items = index.query(querySpec);
        Iterator<Item> iterator = items.iterator();
        System.out.println("Query: printing results...");
        while (iterator.hasNext()) {
            System.out.println(iterator.next().toJSONPretty());
        }
    } else {
        System.out.println("\nNo index: All of Bob's orders, by OrderId:\n");
        querySpec.withKeyConditionExpression("CustomerId = :v_custid").withValueMap(new ValueMap().withString(":v_custid", "bob@example.com"));
        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) Iterator(java.util.Iterator) LocalSecondaryIndex(com.amazonaws.services.dynamodbv2.model.LocalSecondaryIndex) Index(com.amazonaws.services.dynamodbv2.document.Index) QueryOutcome(com.amazonaws.services.dynamodbv2.document.QueryOutcome) ItemCollection(com.amazonaws.services.dynamodbv2.document.ItemCollection) QuerySpec(com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)

Example 15 with ValueMap

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

the class DocumentAPIQuery method findRepliesPostedWithinTimePeriod.

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

Aggregations

Table (com.amazonaws.services.dynamodbv2.document.Table)19 ValueMap (com.amazonaws.services.dynamodbv2.document.utils.ValueMap)19 QuerySpec (com.amazonaws.services.dynamodbv2.document.spec.QuerySpec)12 Item (com.amazonaws.services.dynamodbv2.document.Item)11 QueryOutcome (com.amazonaws.services.dynamodbv2.document.QueryOutcome)10 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)6 DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)6 UpdateItemOutcome (com.amazonaws.services.dynamodbv2.document.UpdateItemOutcome)6 UpdateItemSpec (com.amazonaws.services.dynamodbv2.document.spec.UpdateItemSpec)6 NameMap (com.amazonaws.services.dynamodbv2.document.utils.NameMap)5 IOException (java.io.IOException)4 SimpleDateFormat (java.text.SimpleDateFormat)3 Date (java.util.Date)3 Index (com.amazonaws.services.dynamodbv2.document.Index)2 PrimaryKey (com.amazonaws.services.dynamodbv2.document.PrimaryKey)2 DeleteItemSpec (com.amazonaws.services.dynamodbv2.document.spec.DeleteItemSpec)2 ConditionalCheckFailedException (com.amazonaws.services.dynamodbv2.model.ConditionalCheckFailedException)2 HashMap (java.util.HashMap)2 DeleteItemOutcome (com.amazonaws.services.dynamodbv2.document.DeleteItemOutcome)1 ItemCollection (com.amazonaws.services.dynamodbv2.document.ItemCollection)1