本文整理汇总了Java中com.amazonaws.services.dynamodbv2.model.QueryResult.getItems方法的典型用法代码示例。如果您正苦于以下问题:Java QueryResult.getItems方法的具体用法?Java QueryResult.getItems怎么用?Java QueryResult.getItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.dynamodbv2.model.QueryResult
的用法示例。
在下文中一共展示了QueryResult.getItems方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: query
import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
private QueryOutcome query(Object hk, QuerySpec querySpec, PageIterator pageIterator) {
if ( null == _convertMarker ) {
throw new IllegalStateException("Index must first be initialized with ConvertMarker");
}
if ( pageIterator.getPageSize() <= 0 ) {
return new QueryOutcome(new QueryResult());
}
ItemCollection<QueryOutcome> itemCollection =
maybeBackoff(true, () ->
_query.query(withMarker(querySpec.withHashKey(_hkName, hk), pageIterator, hk)));
if ( null != itemCollection ) {
Iterator<Page<Item, QueryOutcome>> iterator = itemCollection.pages().iterator();
if ( iterator.hasNext() ) {
QueryOutcome outcome = maybeBackoff(true, () -> iterator.next().getLowLevelResult());
QueryResult result = outcome.getQueryResult();
if ( null != pageIterator.getMarker() && null != result.getItems() && result.getItems().size() > 0 ) {
pageIterator.setPrevMarker(toMarker(result.getItems().get(0), true));
} else {
pageIterator.setPrevMarker(null);
}
Map<String,AttributeValue> lastKey = result.getLastEvaluatedKey();
if ( null != lastKey && ! lastKey.isEmpty() ) {
pageIterator.setMarker(toMarker(lastKey, true));
} else {
pageIterator.setMarker(null);
}
return outcome;
}
}
pageIterator.setPrevMarker(null);
pageIterator.setMarker(null);
return new QueryOutcome(new QueryResult());
}
示例2: query
import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
/**
*
* @param targetClass
* @param queryRequest
* @return
* @see #find(Class, QueryRequest)
*/
public DataSet query(final Class<?> targetClass, final QueryRequest queryRequest) {
if (targetClass == null || Map.class.isAssignableFrom(targetClass)) {
final QueryResult queryResult = dynamoDB.query(queryRequest);
final List<Map<String, AttributeValue>> items = queryResult.getItems();
if (N.notNullOrEmpty(queryResult.getLastEvaluatedKey()) && N.isNullOrEmpty(queryRequest.getExclusiveStartKey())) {
final QueryRequest newQueryRequest = queryRequest.clone();
QueryResult newQueryResult = queryResult;
while (N.notNullOrEmpty(newQueryResult.getLastEvaluatedKey())) {
newQueryRequest.setExclusiveStartKey(newQueryResult.getLastEvaluatedKey());
newQueryResult = dynamoDB.query(newQueryRequest);
items.addAll(newQueryResult.getItems());
}
}
return extractData(items, 0, items.size());
} else {
return N.newDataSet(find(targetClass, queryRequest));
}
}
示例3: accountGetAccountByToken
import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
public Account accountGetAccountByToken(String token) {
Condition hashKeyCondition = new Condition();
hashKeyCondition.withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(new AttributeValue().withS(token));
Map<String, Condition> keyConditions = new HashMap<String, Condition>();
keyConditions.put("accountToken", hashKeyCondition);
QueryRequest queryRequest = new QueryRequest();
queryRequest.withTableName("accountsv2");
queryRequest.withIndexName("accountToken-index");
queryRequest.withKeyConditions(keyConditions);
QueryResult result = dynamoDB.query(queryRequest);
for(Map<String, AttributeValue> item : result.getItems()) {
Account mappedItem = mapper.marshallIntoObject(Account.class, item);
// Only want the First one
return mappedItem;
}
return null;
}
示例4: findRepliesForAThread
import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
private static void findRepliesForAThread(String forumName, String threadSubject) {
String replyId = forumName + "#" + threadSubject;
Condition hashKeyCondition = new Condition()
.withComparisonOperator(ComparisonOperator.EQ)
.withAttributeValueList(new AttributeValue().withS(replyId));
Map<String, Condition> keyConditions = new HashMap<String, Condition>();
keyConditions.put("Id", hashKeyCondition);
QueryRequest queryRequest = new QueryRequest()
.withTableName(tableName)
.withKeyConditions(keyConditions);
QueryResult result = client.query(queryRequest);
for (Map<String, AttributeValue> item : result.getItems()) {
printItem(item);
}
}
示例5: findRepliesForAThreadSpecifyOptionalLimit
import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
private static void findRepliesForAThreadSpecifyOptionalLimit(String forumName, String threadSubject) {
Map<String, AttributeValue> lastEvaluatedKey = null;
do {
QueryRequest queryRequest = new QueryRequest()
.withTableName(tableName)
.withKeyConditions(makeReplyKeyConditions(forumName, threadSubject))
.withLimit(1)
.withExclusiveStartKey(lastEvaluatedKey);
QueryResult result = client.query(queryRequest);
for (Map<String, AttributeValue> item : result.getItems()) {
printItem(item);
}
lastEvaluatedKey = result.getLastEvaluatedKey();
} while (lastEvaluatedKey != null);
}
示例6: findRepliesInLast15DaysWithConfig
import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
private static void findRepliesInLast15DaysWithConfig(String forumName, String 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);
Condition rangeKeyCondition = new Condition()
.withComparisonOperator(ComparisonOperator.GT.toString())
.withAttributeValueList(new AttributeValue().withS(twoWeeksAgoStr));
Map<String, Condition> keyConditions = makeReplyKeyConditions(forumName, threadSubject);
keyConditions.put("ReplyDateTime", rangeKeyCondition);
QueryRequest queryRequest = new QueryRequest().withTableName(tableName)
.withKeyConditions(keyConditions)
.withProjectionExpression("Message, ReplyDateTime, PostedBy");
QueryResult result = client.query(queryRequest);
for (Map<String, AttributeValue> item : result.getItems()) {
printItem(item);
}
}
示例7: findRepliesUsingAFilterExpression
import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
private static void findRepliesUsingAFilterExpression(String forumName, String threadSubject) {
Map<String, Condition> keyConditions = makeReplyKeyConditions(forumName, threadSubject);
Map<String, AttributeValue> expressionAttributeValues = new HashMap<String, AttributeValue>();
expressionAttributeValues.put(":val", new AttributeValue().withS("User B"));
QueryRequest queryRequest = new QueryRequest()
.withTableName(tableName)
.withKeyConditions(keyConditions)
.withFilterExpression("PostedBy = :val")
.withExpressionAttributeValues(expressionAttributeValues)
.withProjectionExpression("Message, ReplyDateTime, PostedBy");
QueryResult result = client.query(queryRequest);
for (Map<String, AttributeValue> item : result.getItems()) {
printItem(item);
}
}
示例8: fetchPage
import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
@Override
protected PageResults<Map<String, AttributeValue>> fetchPage(RequestLimit lim) {
// Read from DynamoDB
RetryResult<QueryResult> retryResult = context.getClient().queryTable(tableName, context
.getSplit().getFilterPushdown(), lastEvaluatedKey, lim.items, context.getReporter());
QueryResult result = retryResult.result;
int retries = retryResult.retries;
return new PageResults<>(result.getItems(), result.getLastEvaluatedKey(), result
.getConsumedCapacity().getCapacityUnits(), retries);
}
示例9: buildRecordIteratorFromQueryResult
import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
private StaticRecordIterator buildRecordIteratorFromQueryResult(final QueryResult queryResult) {
final List<Entry> entries = Lists.newLinkedList();
for (Map<String, AttributeValue> item : queryResult.getItems()) {
// DynamoDB's between includes the end of the range, but Titan's slice queries expect the end key to be exclusive
final Entry entry = new EntryBuilder(item).slice(rangeKeySliceQuery.getSliceStart(), rangeKeySliceQuery.getSliceEnd())
.build();
if (entry != null) {
entries.add(entry);
}
}
return new StaticRecordIterator(entries);
}
示例10: query
import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
public <T> List<T> query(String tableName, String indexName, Map<String, Condition> keyConditions, final ObjectExtractor<T> extractor, String... columnsToInclude) throws EmptyResultDataAccessException {
Assert.notNull(tableName, "Table must not be null");
Assert.notNull(extractor, "ObjectExtractor must not be null");
if (logger.isDebugEnabled()) {
logger.debug("Executing query on " + tableName + " for " + renderKey(keyConditions));
}
QueryRequest request = new QueryRequest(tableName) //
.withConsistentRead(false) // because query is used on GSIs [where consistent reads are not supported] - if we needed to query on the primary index could make this a parameter
.withKeyConditions(keyConditions);
if (columnsToInclude != null && columnsToInclude.length > 0) {
request.setAttributesToGet(Arrays.asList(columnsToInclude));
}
if (indexName != null) {
request.setIndexName(indexName);
}
QueryResult result = client.query(request);
List<Map<String, AttributeValue>> items = result.getItems();
List<T> convertedItems = new ArrayList<T>(items.size());
for (Map<String, AttributeValue> item : items) {
convertedItems.add(extractor.extract(item));
}
return convertedItems;
}
示例11: findRepliesPostedWithinTimePeriod
import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
private static void findRepliesPostedWithinTimePeriod(String forumName, String threadSubject) {
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);
Condition rangeKeyCondition = new Condition()
.withComparisonOperator(ComparisonOperator.BETWEEN.toString())
.withAttributeValueList(
new AttributeValue().withS(startDate),
new AttributeValue().withS(endDate));
Map<String, Condition> keyConditions = makeReplyKeyConditions(forumName, threadSubject);
keyConditions.put("ReplyDateTime", rangeKeyCondition);
QueryRequest queryRequest = new QueryRequest()
.withTableName(tableName)
.withKeyConditions(keyConditions)
.withProjectionExpression("Message, ReplyDateTime, PostedBy");
QueryResult result = client.query(queryRequest);
for (Map<String, AttributeValue> item : result.getItems()) {
printItem(item);
}
}
示例12: domainsGetDomainsByToken
import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
public List<Domain> domainsGetDomainsByToken(String token) {
Condition hashKeyCondition = new Condition();
hashKeyCondition.withComparisonOperator(ComparisonOperator.EQ).withAttributeValueList(new AttributeValue().withS(token));
Map<String, Condition> keyConditions = new HashMap<String, Condition>();
keyConditions.put("accountToken", hashKeyCondition);
QueryRequest queryRequest = new QueryRequest();
queryRequest.withTableName("domainsv2");
queryRequest.withIndexName("accountToken-index");
queryRequest.withKeyConditions(keyConditions);
QueryResult result = dynamoDB.query(queryRequest);
List<Domain> mappedItems = new ArrayList<Domain>();
for(Map<String, AttributeValue> item : result.getItems()) {
Domain mappedItem = mapper.marshallIntoObject(Domain.class, item);
mappedItems.add(mappedItem);
}
return mappedItems;
}
示例13: query
import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
public static void query(String indexName) {
System.out.println("\n***********************************************************\n");
System.out.println("Querying table " + tableName + "...");
QueryRequest queryRequest = new QueryRequest()
.withTableName(tableName)
.withConsistentRead(true).withScanIndexForward(true)
.withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL);
HashMap<String, Condition> keyConditions = new HashMap<String, Condition>();
keyConditions.put(
"CustomerId",
new Condition()
.withComparisonOperator(ComparisonOperator.EQ)
.withAttributeValueList(new AttributeValue()
.withS("[email protected]")));
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");
queryRequest.setIndexName(indexName);
keyConditions.put(
"IsOpen",
new Condition()
.withComparisonOperator(ComparisonOperator.EQ)
.withAttributeValueList(new AttributeValue().withN("1")));
// ProjectionExpression
queryRequest.setProjectionExpression("OrderCreationDate, ProductCategory, ProductName, OrderStatus");
} else if (indexName == "OrderCreationDateIndex") {
System.out.println("\nUsing index: '" + indexName
+ "': Bob's orders that were placed after 01/31/2013.");
System.out.println("Only the projected attributes are returned\n");
queryRequest.setIndexName(indexName);
keyConditions.put("OrderCreationDate", new Condition()
.withComparisonOperator(ComparisonOperator.GT)
.withAttributeValueList(new AttributeValue()
.withN("20130131")));
// Select
queryRequest.setSelect(Select.ALL_PROJECTED_ATTRIBUTES);
} else {
System.out.println("\nNo index: All of Bob's orders, by OrderId:\n");
}
queryRequest.setKeyConditions(keyConditions);
QueryResult result = client.query(queryRequest);
List<Map<String, AttributeValue>> items = result.getItems();
Iterator<Map<String, AttributeValue>> itemsIter = items.iterator();
while (itemsIter.hasNext()) {
Map<String, AttributeValue> currentItem = itemsIter.next();
Iterator<String> currentItemIter = currentItem.keySet().iterator();
while (currentItemIter.hasNext()) {
String attr = (String) currentItemIter.next();
if (attr == "OrderId" || attr == "IsOpen"
|| attr == "OrderCreationDate") {
System.out.println(attr + "---> "
+ currentItem.get(attr).getN());
} else {
System.out.println(attr + "---> "
+ currentItem.get(attr).getS());
}
}
System.out.println();
}
System.out.println("\nConsumed capacity: " + result.getConsumedCapacity() + "\n");
}
示例14: queryIndex
import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
public static void queryIndex(String indexName) {
System.out.println
("\n***********************************************************\n");
System.out.print("Querying index " + indexName + "...");
QueryRequest queryRequest = new QueryRequest()
.withTableName(tableName)
.withIndexName(indexName)
.withScanIndexForward(true);
HashMap<String, Condition> keyConditions = new HashMap<String, Condition>();
if (indexName == "CreateDateIndex") {
System.out.println("Issues filed on 2013-11-01");
keyConditions.put("CreateDate",new Condition()
.withComparisonOperator(ComparisonOperator.EQ)
.withAttributeValueList(new AttributeValue()
.withS("2013-11-01")));
keyConditions.put("IssueId",new Condition()
.withComparisonOperator(ComparisonOperator.BEGINS_WITH)
.withAttributeValueList(new AttributeValue().withS("A-")));
} else if (indexName == "TitleIndex") {
System.out.println("Compilation errors");
keyConditions.put("Title",new Condition()
.withComparisonOperator( ComparisonOperator.EQ)
.withAttributeValueList(new AttributeValue()
.withS("Compilation error")));
keyConditions.put("IssueId", new Condition()
.withComparisonOperator(ComparisonOperator.BEGINS_WITH)
.withAttributeValueList(new AttributeValue().withS("A-")));
// Select
queryRequest.setSelect(Select.ALL_PROJECTED_ATTRIBUTES);
} else if (indexName == "DueDateIndex") {
System.out.println("Items that are due on 2013-11-30");
keyConditions.put("DueDate",new Condition()
.withComparisonOperator(ComparisonOperator.EQ)
.withAttributeValueList(new AttributeValue().withS("2013-11-30")));
// Select
queryRequest.setSelect(Select.ALL_PROJECTED_ATTRIBUTES);
} else {
System.out.println("\nNo valid index name provided");
return;
}
queryRequest.setKeyConditions(keyConditions);
QueryResult result = client.query(queryRequest);
List<Map<String, AttributeValue>> items = result.getItems();
Iterator<Map<String, AttributeValue>> itemsIter = items.iterator();
System.out.println();
while (itemsIter.hasNext()) {
Map<String, AttributeValue> currentItem = itemsIter.next();
Iterator<String> currentItemIter = currentItem.keySet().iterator();
while (currentItemIter.hasNext()) {
String attr = (String) currentItemIter.next();
if (attr == "Priority" ) {
System.out.println(attr + "---> " + currentItem.get(attr).getN());
} else {
System.out.println(attr + "---> " + currentItem.get(attr).getS());
}
}
System.out.println();
}
}
示例15: findMatching
import com.amazonaws.services.dynamodbv2.model.QueryResult; //导入方法依赖的package包/类
private <T extends Message> List<T> findMatching(T matcher, List<Modifier> modifiers) throws DataStoreException {
DynamoClassMapping<T> tableInfo = getClassMapping(matcher);
log.debug("findAll {} {}", matcher.getClass().getSimpleName(), matcher);
AttributeValue hashKey = tableInfo.buildHashKey(matcher);
if (hashKey == null) {
log.warn("No hash-query provided for query, full table scan required: {}", matcher);
// XXX: throw?
return scan(matcher, modifiers);
}
Map<FieldDescriptor, Object> matcherFields = matcher.getAllFields();
// TODO: Remove PK fields
QueryRequest request = new QueryRequest();
// TODO: Modifier for eventually consistent read?
request.setConsistentRead(true);
request.setTableName(tableInfo.getDynamoTableName());
Map<String, Condition> keyConditions = Maps.newHashMap();
keyConditions.put(FIELD_HASH_KEY, new Condition().withComparisonOperator(ComparisonOperator.EQ)
.withAttributeValueList(hashKey));
tableInfo.addRangeKeyCondition(matcher, keyConditions);
request.setKeyConditions(keyConditions);
// int limit = Integer.MAX_VALUE;
for (Modifier modifier : modifiers) {
if (modifier instanceof ComparatorModifier) {
throw new UnsupportedOperationException();
} else if (modifier instanceof LimitModifier) {
throw new UnsupportedOperationException();
// limitModifier = (LimitModifier) modifier;
// limit = limitModifier.getLimit();
} else {
throw new UnsupportedOperationException();
}
}
QueryResult response = dynamoDB.query(request);
Map<String, AttributeValue> lastEvaluatedKey = response.getLastEvaluatedKey();
if (lastEvaluatedKey != null) {
throw new UnsupportedOperationException("Multiple page results not implemented");
}
List<T> items = Lists.newArrayList();
List<Map<String, AttributeValue>> responseItems = response.getItems();
for (Map<String, AttributeValue> itemData : responseItems) {
T item = tableInfo.mapFromDb(itemData);
if (!DataStore.matches(matcherFields, matcher)) {
continue;
}
items.add(item);
}
return items;
}