Skip to content

Commit cd94971

Browse files
committed
Merge branch 'timlim/add-scroll' into MM/scroll
2 parents 74cc629 + 60a1411 commit cd94971

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,17 @@ user = User.find(params);
134134
user.addCustomAttribute(CustomAttribute.newStringAttribute("role", "captain"));
135135
User.update(user);
136136

137-
// Iterate over all users
137+
// Iterate over all users (up to 10k records, to read all use Scroll API)
138138
UserCollection users = User.list();
139139
while(users.hasNext()) {
140140
System.out.println(users.next().getUserId());
141141
}
142142

143+
// Retrieve users via Scroll API
144+
ScrollableUserCollection usersScroll = User.scroll();
145+
List<User> users = usersScroll.getPage();
146+
usersScroll = usersScroll.scroll();
147+
143148
// Bulk submit users
144149
final List<JobItem<User>> items = Lists.newArrayList();
145150
items.add(new JobItem<User>("post", user1));
@@ -187,12 +192,18 @@ while(contacts.hasNext()) {
187192
System.out.println(contacts.next());
188193
}
189194

190-
// Iterate over all contacts
195+
// Iterate over all contacts (up to 10k records, to read all use Scroll API)
191196
ContactCollection allContacts = Contact.list();
192197
while(allContacts.hasNext()) {
193198
System.out.println(allContacts.next());
194199
}
195200

201+
// Retrieve contacts via Scroll API
202+
ScrollableContactCollection contactsScroll = Contact.scroll();
203+
List<Contact> contacts = contactsScroll.getPage();
204+
contactsScroll = contactsScroll.scroll();
205+
206+
196207
// Remove a contact
197208
Contact.delete(contact);
198209

@@ -586,6 +597,8 @@ These return a Collection object (eg `UserCollection`) which can be iterated in
586597

587598
- Java's inbuilt iterator methods `next()` and `hasNext()` - these are useful when you want to fetch data without manually handling pagination.
588599

600+
- User and Contact listing only works up to 10k records. To retrieve all records use the Scroll API via `scroll()`
601+
589602
### Error handling
590603

591604
You do not need to deal with the HTTP response from an API call directly.

0 commit comments

Comments
 (0)