accumulatedConsumedCapacity.setCapacityUnits(consumedCapacity.getCapacityUnits()); accumulatedConsumedCapacity.setGlobalSecondaryIndexes( clone(consumedCapacity.getGlobalSecondaryIndexes())); accumulatedConsumedCapacity.setLocalSecondaryIndexes( clone(consumedCapacity.getLocalSecondaryIndexes())); accumulatedConsumedCapacity.setTable(clone(consumedCapacity.getTable())); accumulatedConsumedCapacity.setTableName(consumedCapacity.getTableName()); } else { if (gsi == null) { accumulatedConsumedCapacity.setGlobalSecondaryIndexes( clone(consumedCapacity.getGlobalSecondaryIndexes())); } else { accumulatedConsumedCapacity.setGlobalSecondaryIndexes(add( consumedCapacity.getGlobalSecondaryIndexes(), accumulatedConsumedCapacity.getGlobalSecondaryIndexes())); if (lsi == null) { accumulatedConsumedCapacity.setLocalSecondaryIndexes( clone(consumedCapacity.getLocalSecondaryIndexes())); } else { accumulatedConsumedCapacity.setLocalSecondaryIndexes(add( consumedCapacity.getLocalSecondaryIndexes(), accumulatedConsumedCapacity.getLocalSecondaryIndexes())); accumulatedConsumedCapacity.setTable(clone(consumedCapacity.getTable())); } else { accumulatedConsumedCapacity.setTable(add(consumedCapacity.getTable(), accumulatedConsumedCapacity.getTable()));
private Map<String, Capacity> add(Map<String, Capacity> from, Map<String, Capacity> to) { if (to == null) return clone(from); if (from != null) { for (Map.Entry<String, Capacity> entryFrom : from.entrySet()) { final String key = entryFrom.getKey(); final Capacity tocap = to.get(key); final Capacity fromcap = entryFrom.getValue(); if (tocap == null) { to.put(key, clone(fromcap)); } else { to.put(key, new Capacity().withCapacityUnits( doubleOf(tocap) + doubleOf(fromcap))); } } } return to; }
/** * Returns the consumed capacity accumulated so far. * @deprecated This method returns the accumulated consumed capacity and not the total. * Use {@link #getAccumulatedScannedCount} instead. */ @Deprecated public ConsumedCapacity getTotalConsumedCapacity() { return getAccumulatedConsumedCapacity(); }
private static void findProductsForPriceLessThanZero() { Table table = dynamoDB.getTable(tableName); Map<String, Object> expressionAttributeValues = new HashMap<String, Object>(); expressionAttributeValues.put(":pr", 100); ItemCollection<ScanOutcome> items = table.scan( "Price < :pr", //FilterExpression "Id, Title, ProductCategory, Price", //ProjectionExpression null, //ExpressionAttributeNames - not used in this example expressionAttributeValues); System.out.println("Scan of " + tableName + " for items with a price less than 100."); Iterator<Item> iterator = items.iterator(); while (iterator.hasNext()) { System.out.println(iterator.next().toJSONPretty()); } }
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()); } } }
protected void setLastLowLevelResult(QueryOutcome lowLevelResult) { super.setLastLowLevelResult(lowLevelResult); QueryResult result = lowLevelResult.getQueryResult(); accumulateStats(result.getConsumedCapacity(), result.getCount(), result.getScannedCount()); } }
requestFactory.getAllItems(table).forEach(item -> {
/** * Returns the count of items accumulated so far. * @deprecated This method returns the accumulated count and not the total count. * Use {@link #getAccumulatedItemCount} instead. */ @Deprecated public int getTotalCount() { return getAccumulatedItemCount(); }
/** * Returns the scanned count accumulated so far. * @deprecated This method returns the accumulated count and not the total count. * Use {@link #getAccumulatedScannedCount} instead. */ @Deprecated public int getTotalScannedCount() { return getAccumulatedScannedCount(); }
private Map<String, Capacity> clone(Map<String, Capacity> capacityMap) { if (capacityMap == null) return null; Map<String,Capacity> clone = new HashMap<String,Capacity>(capacityMap.size()); for (Map.Entry<String, Capacity> e : capacityMap.entrySet()) clone.put(e.getKey(), clone(e.getValue())); return clone; }
Iterator<Item> iterator = items.iterator();
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; }
protected void setLastLowLevelResult(ScanOutcome lowLevelResult) { super.setLastLowLevelResult(lowLevelResult); ScanResult result = lowLevelResult.getScanResult(); accumulateStats(result.getConsumedCapacity(), result.getCount(), result.getScannedCount()); } }
requestFactory.getAllItems(table).forEach(item -> {
/** * Returns the count of items accumulated so far. * @deprecated This method returns the accumulated count and not the total count. * Use {@link #getAccumulatedItemCount} instead. */ @Deprecated public int getTotalCount() { return getAccumulatedItemCount(); }
/** * Returns the scanned count accumulated so far. * @deprecated This method returns the accumulated count and not the total count. * Use {@link #getAccumulatedScannedCount} instead. */ @Deprecated public int getTotalScannedCount() { return getAccumulatedScannedCount(); }
private Map<String, Capacity> clone(Map<String, Capacity> capacityMap) { if (capacityMap == null) return null; Map<String,Capacity> clone = new HashMap<String,Capacity>(capacityMap.size()); for (Map.Entry<String, Capacity> e : capacityMap.entrySet()) clone.put(e.getKey(), clone(e.getValue())); return clone; }
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()); } }