Paged vs PagedLater

24 views
Skip to first unread message

John Gentilin

unread,
Jan 18, 2012, 3:59:39 PM1/18/12
to BatchFB

Using the Photos / Comments example you have here
http://code.google.com/p/batchfb/source/browse/trunk/src-test/com/googlecode/batchfb/test/PagedTests.java#119

I am trying to understand the differences between Paged and PagedLater
in regards
to iterating over the whole set of Photos and all the comments for a
Photo assuming
that each can have multiple pages...

From my understanding, Paging gives you a single page that is a List
of objects.
Iterating the List won't automatically move to the next page, and you
have to
request the next page at the end of the List.

To iterate over The Photos I have

PagedLater<Photo> photoRequest =
batcher.paged("/" + fbEventID+ "/photos", Photo.class);

List<Photo> photoPage = null;
do {
photoPage = photoRequest.get();
if (photoPage.isEmpty()) break;
for(Photo p : photoPage)
{
updatePhoto( p);
updatePhotoComments(p);
}
} while ( photoRequest.next() );

This seems to work fine.

My question is around the Comment field that is defined as Paged.
It's not clear how to iterate the pages of comments
p.comments.getPaging().next() returns String vs PagedLater<T>
so I don't think it will actually page through the comments..

My questions is, how do you page through a data set that is contained
in
PagedLater object ? Will paging through the internal object mess with
the
context of the inner object ?

updatePhotoComments(Photo p)
{
List<Comment> comments = null;
do {
comments = p.comments.getData();
if (comments.isEmpty()) break;
for(Comment c : comments)
{
updateComment(c);
}
} while ( p.comments.getPaging().next());

Jeff Schnitzer

unread,
Jan 18, 2012, 8:32:27 PM1/18/12
to bat...@googlegroups.com
Look at the code for PagedLaterAdapter, especially the createRequest()
method. To page back and forth through the Paged results it just
takes the next/previous string, parses it, then calls the paged()
method on the batcher again. You can do the exact same thing.

Paged is the actual data structure that facebook returns, with data,
paging/next, paging/previous.

PagedLater is a wrapper around this raw structure that provides a more
convenient interface, making it easier to page forward and backward.

Jeff

John Gentilin

unread,
Jan 18, 2012, 10:35:14 PM1/18/12
to BatchFB
Hi Jeff,

I took a look at the PagedLaterAdapter and I can see how it adds in
the helper functions
to locate the prev / next URL's and issue the next GraphRequest. The
problem I am running
into is the problem I was originally having.. If I declare the
comments field to be PagedLater
vs Paged, to get the helper functionality, I get a JSON parse error
when I execute the get on
the /photos request,

Can not construct instance of com.googlecode.batchfb.PagedLater,
problem: abstract types can
only be instantiated with additional type information at [Source: N/A;
line: -1, column: -1] (through
reference chain: com.googlecode.batchfb.type.Paged["data"]-
>com.CloudTvApps.PicRollr.shared.FBObjects.Photo["comments"])

-John G

On Jan 18, 5:32 pm, Jeff Schnitzer <j...@infohazard.org> wrote:
> Look at the code for PagedLaterAdapter, especially the createRequest()
> method.  To page back and forth through the Paged results it just
> takes the next/previous string, parses it, then calls the paged()
> method on the batcher again.  You can do the exact same thing.
>
> Paged is the actual data structure that facebook returns, with data,
> paging/next, paging/previous.
>
> PagedLater is a wrapper around this raw structure that provides a more
> convenient interface, making it easier to page forward and backward.
>
> Jeff
>
>
>
>
>
>
>
> On Wed, Jan 18, 2012 at 3:59 PM, John Gentilin <gent...@gmail.com> wrote:
>
> > Using the Photos / Comments example you have here
> >http://code.google.com/p/batchfb/source/browse/trunk/src-test/com/goo...

Jeff Schnitzer

unread,
Jan 18, 2012, 10:45:55 PM1/18/12
to bat...@googlegroups.com
Right. PagedLater is not a data structure that can be mapped from
JSON; it's an interface that the PagedLaterAdapter (or possibly some
adapter of your own devising) provides based on the data that gets
mapped into a Paged.

There currently isn't a way to directly map a structure that
*contains* a PagedLater. In order to make PagedLater work, the
adapter needs a reference back to the batcher so that it can enqueue
the next/previous requests. Right now there's no obvious mechanism
for passing this info into the jackson-created classes.

What I would do if I were you is create a utility method somewhere
that takes the Paged comment structure and a batcher and returns the
next or previous stretch as a PagedLater, which you can then page as
normal. Not quite as pretty as having a PagedLater embedded in the
Photo structure, but it will work without digging deep into the
jackson binding mechanisms.

Jeff

Reply all
Reply to author
Forward
0 new messages