本文整理汇总了Java中com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper.query方法的典型用法代码示例。如果您正苦于以下问题:Java DynamoDBMapper.query方法的具体用法?Java DynamoDBMapper.query怎么用?Java DynamoDBMapper.query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper
的用法示例。
在下文中一共展示了DynamoDBMapper.query方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: FindRepliesInLast15Days
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入方法依赖的package包/类
private static void FindRepliesInLast15Days(DynamoDBMapper mapper,
String forumName,
String threadSubject) throws Exception {
System.out.println("FindRepliesInLast15Days: Replies within last 15 days.");
String hashKey = forumName + "#" + threadSubject;
long twoWeeksAgoMilli = (new Date()).getTime() - (15L*24L*60L*60L*1000L);
Date twoWeeksAgo = new Date();
twoWeeksAgo.setTime(twoWeeksAgoMilli);
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
dateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
String twoWeeksAgoStr = dateFormatter.format(twoWeeksAgo);
Condition rangeKeyCondition = new Condition()
.withComparisonOperator(ComparisonOperator.GT.toString())
.withAttributeValueList(new AttributeValue().withS(twoWeeksAgoStr.toString()));
Reply replyKey = new Reply();
replyKey.setId(hashKey);
DynamoDBQueryExpression<Reply> queryExpression = new DynamoDBQueryExpression<Reply>()
.withHashKeyValues(replyKey)
.withRangeKeyCondition("ReplyDateTime", rangeKeyCondition);
List<Reply> latestReplies = mapper.query(Reply.class, queryExpression);
for (Reply reply : latestReplies) {
System.out.format("Id=%s, Message=%s, PostedBy=%s %n, ReplyDateTime=%s %n",
reply.getId(), reply.getMessage(), reply.getPostedBy(), reply.getReplyDateTime() );
}
}
示例2: FindRepliesPostedWithinTimePeriod
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入方法依赖的package包/类
private static void FindRepliesPostedWithinTimePeriod(
DynamoDBMapper mapper,
String forumName,
String threadSubject) throws Exception {
String hashKey = forumName + "#" + threadSubject;
System.out.println("FindRepliesPostedWithinTimePeriod: Find replies for thread Message = 'DynamoDB Thread 2' posted within a period.");
long startDateMilli = (new Date()).getTime() - (14L*24L*60L*60L*1000L); // Two weeks ago.
long endDateMilli = (new Date()).getTime() - (7L*24L*60L*60L*1000L); // One week ago.
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
dateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
String startDate = dateFormatter.format(startDateMilli);
String endDate = dateFormatter.format(endDateMilli);
Condition rangeKeyCondition = new Condition()
.withComparisonOperator(ComparisonOperator.BETWEEN.toString())
.withAttributeValueList(new AttributeValue().withS(startDate),
new AttributeValue().withS(endDate));
Reply replyKey = new Reply();
replyKey.setId(hashKey);
DynamoDBQueryExpression<Reply> queryExpression = new DynamoDBQueryExpression<Reply>()
.withHashKeyValues(replyKey)
.withRangeKeyCondition("ReplyDateTime", rangeKeyCondition);
List<Reply> betweenReplies = mapper.query(Reply.class, queryExpression);
for (Reply reply : betweenReplies) {
System.out.format("Id=%s, Message=%s, PostedBy=%s %n, PostedDateTime=%s %n",
reply.getId(), reply.getMessage(), reply.getPostedBy(), reply.getReplyDateTime() );
}
}
示例3: getHNItemsByd
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; //导入方法依赖的package包/类
@DynamoDBIgnore
public HashSet<HNItemItem> getHNItemsByd(int minutes_ago, DynamoDBMapper mapper, DynamoDBMapperConfig dynamo_config) {
// set up an expression to query screename#id
DynamoDBQueryExpression<HNItemItem> queryExpression = new DynamoDBQueryExpression<HNItemItem>()
.withIndexName("by-time-index")
.withScanIndexForward(true)
.withConsistentRead(false);
// set the user_id part
HNItemItem key = new HNItemItem();
key.setBy(getId());
queryExpression.setHashKeyValues(key);
// set the msfe range part
if(minutes_ago > 0)
{
//System.out.println("Getting comment children with a valid cutoff time.");
Calendar cal = Calendar.getInstance();
cal.add(Calendar.MINUTE, (minutes_ago * -1));
long time_cutoff = cal.getTimeInMillis() / 1000;
// set the msfe range part
Map<String, Condition> keyConditions = new HashMap<String, Condition>();
keyConditions.put("time",new Condition()
.withComparisonOperator(ComparisonOperator.GT)
.withAttributeValueList(new AttributeValue().withN(new Long(time_cutoff).toString())));
queryExpression.setRangeKeyConditions(keyConditions);
}
// execute
List<HNItemItem> notificationitems = mapper.query(HNItemItem.class, queryExpression, dynamo_config);
if(notificationitems != null && notificationitems.size() > 0)
{
HashSet<HNItemItem> returnset = new HashSet<HNItemItem>();
for (HNItemItem notificationitem : notificationitems) {
returnset.add(notificationitem);
}
return returnset;
}
else
{
return null;
}
}