lundi 12 octobre 2015

Dynamodb pagination of 10 results

I have a message table which I would like to get the last 10 messages for that user and if they click more it would retrieve another 10 until there were no more message left. I could not see how to do this, so far I am able to get message based on time, but this is not exactly what I want. Reading through the documentation I can see it a method called LastEvaluatedKey, but where and how do I use this I can't find a working example of this. This is my code for time:

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);


                                            QuerySpec spec = new QuerySpec()
                                                .withProjectionExpression("to,fr,sta,cr")
                                                .withKeyConditionExpression("to = :v_to and cr between :v_start_dt and :v_end_dt")
                                                .withValueMap(new ValueMap()
                                                    .withString(":v_id", username)
                                                    .withString(":v_start_dt", startDate)
                                                    .withString(":v_end_dt", endDate));

                                            ItemCollection<QueryOutcome> items = table.query(spec);

                                            System.out.println("\nfindRepliesPostedWithinTimePeriod results:");
                                            Iterator<Item> iterator = items.iterator();
                                            while (iterator.hasNext()) {
                                                System.out.println(iterator.next().toJSONPretty());
                                            }    

How can I modify this to eliminate the time based pagination and use instead a last 10 messages type of pagination?




Aucun commentaire:

Enregistrer un commentaire