如何在GAE上使用jpa的数据存储库游标

时间:2010-03-21 09:35:54

标签: java google-app-engine jpa google-cloud-datastore cursors

任何团体都知道如何在JPA中使用Datastore Cursors?

1 个答案:

答案 0 :(得分:2)

你可以尝试这个(改编自JDO sample):

List<Employee> results = (List<Employee>) query.execute();
// Use the first 20 results...

Cursor cursor = JPACursorHelper.getCursor(results);
String cursorString = cursor.toWebSafeString();
// Store the cursorString...

// ...

// Query query = the same query that produced the cursor
// String cursorString = the string from storage
Cursor cursor = Cursor.fromWebSafeString(cursorString);
query.setHint(JPACursorHelper.CURSOR_HINT, cursor);
query.setFirstResult(0);
query.setMaxResults(20);

List<Employee> results = (List<Employee>) query.execute();
// Use the next 20 results...