I use DynamoDBMapper for a class, say, "User" (username is the primary key), which has a field that says "Status". This is a Hash + Range key table, and every time a user’s status changes (changes rarely occur), we add a new record to the table along with a time stamp (which is a range key). To get the current status, this is what I do:
DynamoDBQueryExpression expr =
new DynamoDBQueryExpression(new AttributeValue().withS(userName))
.withScanIndexForward(false).withLimit(1);
PaginatedQueryList<User> result =
this.getMapper().query(User.class, expr);
if(result == null || result.size() == 0) {
return null;
}
for(final User user : result) {
System.out.println(user.getStatus());
}
This for some reason prints all the statuses that the user has had so far. I set it scanIndexForwardto false to be in descending order, and I imposed a restriction 1. I expect this to return the last single entry in the table for this username.
, , , , 1. :
final String currentStatus = result.get(0).getStatus();
, , , withLimit , - ?