@Override public ItemCollection<QueryOutcome> query(KeyAttribute hashKey, RangeKeyCondition rangeKeyCondition, String filterExpression, Map<String, String> nameMap, Map<String, Object> valueMap) { return doQuery(new QuerySpec().withHashKey(hashKey) .withRangeKeyCondition(rangeKeyCondition) .withFilterExpression(filterExpression) .withNameMap(nameMap) .withValueMap(valueMap)); }
@Override public ItemCollection<QueryOutcome> query(KeyAttribute hashKey, RangeKeyCondition rangeKeyCondition, String filterExpression, String projectionExpression, Map<String, String> nameMap, Map<String, Object> valueMap) { return doQuery(new QuerySpec().withHashKey(hashKey) .withRangeKeyCondition(rangeKeyCondition) .withFilterExpression(filterExpression) .withProjectionExpression(projectionExpression) .withNameMap(nameMap) .withValueMap(valueMap)); }
/** * Convenient method to specify expressions (and the associated name map and * value map) via {@link QueryExpressionSpec}. */ @Beta public QuerySpec withExpressionSpec(QueryExpressionSpec xspec) { return withKeyConditionExpression(xspec.getKeyConditionExpression()) .withFilterExpression(xspec.getFilterExpression()) .withProjectionExpression(xspec.getProjectionExpression()) .withNameMap(xspec.getNameMap()) .withValueMap(xspec.getValueMap()) ; } }
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()); } }
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()); } }
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()); } }
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()); } }
.withKeyConditionExpression("#yr = :yyyy") .withNameMap(new NameMap().with("#yr", "year")) .withValueMap(valueMap); .withKeyConditionExpression("#yr = :yyyy and title between :letter1 and :letter2") .withNameMap(nameMap) .withValueMap(valueMap);
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()); } } }
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-")); 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-")); 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);
private static void findRepliesUsingAFilterExpression(String forumName, String threadSubject) { Table table = dynamoDB.getTable(tableName); String replyId = forumName + "#" + threadSubject; QuerySpec spec = new QuerySpec() .withProjectionExpression("Message, ReplyDateTime, PostedBy") .withKeyConditionExpression("Id = :v_id") .withFilterExpression("PostedBy = :v_postedby") .withValueMap(new ValueMap() .withString(":v_id", replyId) .withString(":v_postedby", "User B")); ItemCollection<QueryOutcome> items = table.query(spec); System.out.println("\nfindRepliesUsingAFilterExpression results:"); Iterator<Item> iterator = items.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next().toJSONPretty()); } }
@Override public ItemCollection<QueryOutcome> query(KeyAttribute hashKey, RangeKeyCondition rangeKeyCondition, String filterExpression, Map<String, String> nameMap, Map<String, Object> valueMap) { return doQuery(new QuerySpec().withHashKey(hashKey) .withRangeKeyCondition(rangeKeyCondition) .withFilterExpression(filterExpression) .withNameMap(nameMap) .withValueMap(valueMap)); }
.withValueMap(new ValueMap() .withString(":v_custid", "bob@example.com") .withNumber(":v_isopen", 1)); .withValueMap(new ValueMap() .withString(":v_custid", "bob@example.com") .withNumber(":v_orddate", 20130131)); .withValueMap(new ValueMap() .withString(":v_custid", "bob@example.com"));
@Override public ItemCollection<QueryOutcome> query(KeyAttribute hashKey, RangeKeyCondition rangeKeyCondition, String filterExpression, String projectionExpression, Map<String, String> nameMap, Map<String, Object> valueMap) { return doQuery(new QuerySpec().withHashKey(hashKey) .withRangeKeyCondition(rangeKeyCondition) .withFilterExpression(filterExpression) .withProjectionExpression(projectionExpression) .withNameMap(nameMap) .withValueMap(valueMap)); }
/** * Convenient method to specify expressions (and the associated name map and * value map) via {@link QueryExpressionSpec}. */ @Beta public QuerySpec withExpressionSpec(QueryExpressionSpec xspec) { return withKeyConditionExpression(xspec.getKeyConditionExpression()) .withFilterExpression(xspec.getFilterExpression()) .withProjectionExpression(xspec.getProjectionExpression()) .withNameMap(xspec.getNameMap()) .withValueMap(xspec.getValueMap()) ; } }
/** * Returns the DynamoDB query spec for the specified simple match * query. * * @param simpleMatchQuery The simple match query. Must not be * {@code null}. * * @return The DynamoDB query spec. */ static QuerySpec toQuerySpec(final SimpleMatchQuery<String, String> simpleMatchQuery) { return new QuerySpec() .withKeyConditionExpression("#k = :value") .withNameMap(new NameMap() .with("#k", simpleMatchQuery.getKey())) .withValueMap(new ValueMap() .withString(":value", simpleMatchQuery.getValue())); }
.withConsistentRead(true) .withFilterExpression(IS_DELETED + " = :false") .withValueMap(deleteTrackingValueMap); boolean hasChildren = readOp.retry("get/hasChildren", path.toString(),
private static PageIterable<Item, QueryOutcome> queryGSI(String appid, Pager p) { Pager pager = (p != null) ? p : new Pager(); Index index = getSharedIndex(); QuerySpec spec = new QuerySpec(). withMaxPageSize(pager.getLimit()). withMaxResultSize(pager.getLimit()). withKeyConditionExpression(Config._APPID + " = :aid"). withValueMap(new ValueMap().withString(":aid", appid)); if (!StringUtils.isBlank(pager.getLastKey())) { spec = spec.withExclusiveStartKey(new KeyAttribute(Config._APPID, appid), // HASH/PARTITION KEY new KeyAttribute(Config._ID, pager.getLastKey()), // RANGE/SORT KEY new KeyAttribute(Config._KEY, getKeyForAppid(pager.getLastKey(), appid))); // TABLE PRIMARY KEY } return index != null ? index.query(spec).pages() : null; }
private static PageIterable<Item, QueryOutcome> queryGSI(String appid, Pager p) { Pager pager = (p != null) ? p : new Pager(); Index index = getSharedIndex(); QuerySpec spec = new QuerySpec(). withMaxPageSize(pager.getLimit()). withMaxResultSize(pager.getLimit()). withKeyConditionExpression(Config._APPID + " = :aid"). withValueMap(new ValueMap().withString(":aid", appid)); if (!StringUtils.isBlank(pager.getLastKey())) { spec = spec.withExclusiveStartKey(new KeyAttribute(Config._APPID, appid), // HASH/PARTITION KEY new KeyAttribute(Config._ID, pager.getLastKey()), // RANGE/SORT KEY new KeyAttribute(Config._KEY, getKeyForAppid(pager.getLastKey(), appid))); // TABLE PRIMARY KEY } return index != null ? index.query(spec).pages() : null; }