Refine search
@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()) ; } }
public QuerySpec withExclusiveStartKey( String hashKeyName, Object hashKeyValue) { return withExclusiveStartKey(new KeyAttribute(hashKeyName, hashKeyValue)); }
@Override public ItemCollection<QueryOutcome> query(KeyAttribute hashKey, RangeKeyCondition rangeKeyCondition, QueryFilter... queryFilters) { return doQuery(new QuerySpec().withHashKey(hashKey) .withRangeKeyCondition(rangeKeyCondition) .withQueryFilters(queryFilters)); }
@Override public ItemCollection<QueryOutcome> query(KeyAttribute hashKey, RangeKeyCondition rangeKeyCondition) { return doQuery(new QuerySpec().withHashKey(hashKey) .withRangeKeyCondition(rangeKeyCondition)); }
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()); } }
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; }
Table table = dynamoDB.getTable("Movies"); QuerySpec querySpec = new QuerySpec(); querySpec.withKeyConditionExpression("yearkey = :yearval") .withValueMap( new ValueMap().withNumber(":yearval", yearkey)) .withScanIndexForward(false); IteratorSupport<Item, QueryOutcome> iterator = table.query(querySpec).iterator(); while (iterator.hasNext()) { Item movieItem = iterator.next(); System.out.println("Movie data ====================>" + movieItem.toJSONPretty()); moviesJsonList.add(movieItem.toJSON()); }
System.out.println("Querying table " + tableName + "..."); QuerySpec querySpec = new QuerySpec() .withConsistentRead(true) .withScanIndexForward(true) .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL); 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"); querySpec.withKeyConditionExpression("CustomerId = :v_custid and OrderCreationDate >= :v_orddate") .withValueMap(new ValueMap() .withString(":v_custid", "bob@example.com") .withNumber(":v_orddate", 20130131)); querySpec.withSelect(Select.ALL_PROJECTED_ATTRIBUTES); querySpec.withKeyConditionExpression("CustomerId = :v_custid") .withValueMap(new ValueMap() .withString(":v_custid", "bob@example.com"));
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()); } } }
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()); } }
final QuerySpec spec = new QuerySpec() .withHashKey(pathToParentKeyAttribute(path)) .withConsistentRead(true) .withFilterExpression(IS_DELETED + " = :false") .withValueMap(deleteTrackingValueMap); boolean hasChildren = readOp.retry("get/hasChildren", path.toString(),
@Override public ItemCollection<QueryOutcome> query(KeyAttribute hashKey) { return doQuery(new QuerySpec().withHashKey(hashKey)); }
QuerySpec querySpec = new QuerySpec() .withHashKey("cityName", "Rockingham") .withProjectionExpression("Id, mainName, floatVariable, road"); ItemCollection<QueryOutcome> items = table.query(querySpec);
true, () -> { final QuerySpec spec = new QuerySpec() .withHashKey(pathToParentKeyAttribute(path)) .withConsistentRead(true); // strictly consistent read final ItemCollection<QueryOutcome> items = table.query(spec);
String number="0000000025"; String docnumber="0000000027"; QuerySpec qspec=new QuerySpec(WTPart.class); qspec.appendWhere(new SearchCondition(WTPart.class,WTPart.NUMBER,SearchCondition.LIKE,number),new int[]{0,1}); QueryResult qr=PersistenceHelper.manager.find((StatementSpec)qspec); while(qr.hasMoreElements()) QuerySpec qspec1=new QuerySpec(WTDocument.class); qspec1.appendWhere(new SearchCondition(WTDocument.class,WTDocument.NUMBER,SearchCondition.LIKE,docnumber),new int[]{0,1}); QueryResult qr1=PersistenceHelper.manager.find((StatementSpec)qspec1); while(qr1.hasMoreElements())
/** * Returns the result of a request to get all items from the specified * DynamoDB table. * * @param table The DynamoDB table. * * @return The iterable item collection. */ ItemCollection<?> getAllItems(final Table table) { if (applyRangeKey) { RangeKeyCondition c = new RangeKeyCondition(rangeKeyName).eq(rangeKeyValue); return table.getIndex(getRangeKeyGSIName()).query(new QuerySpec().withRangeKeyCondition(c)); } return table.scan(new ScanSpec()); }
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 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; }
QuerySpec querySpec = new QuerySpec(); querySpec.withKeyConditionExpression("yearkey = :yearval and title = :title") .withFilterExpression("contains (subscriptions, :subscriptions)") .withValueMap( new ValueMap().withNumber(":yearval", yearKey) .withString(":title", title) .withString(":subscriptions", subscriptions));