結果のフェッチにページネーションを実装する必要があるので、周りを見回していると、Google Developerサイトのクエリカーソルへのリンクが表示されましたが、この記事では、低レベルAPIを使用したクエリカーソルの使用について説明しています(ペストのようなものは避けています) 。私がJDOで見たものはすべてsetRange(start, end)
、範囲に先行する結果のフェッチと破棄に伴うオーバーヘッドを支払うため、(私が正しい場合は)それほど効率的ではありません。App Engineデータストア上でJDOのクエリカーソルを使用するにはどうすればよいですか?
質問する
1653 次
1 に答える
5
appengineドキュメントから:
Query q = pm.newQuery(Person.class);
q.setRange(0, 20);
List<Person> results = (List<Person>) q.execute();
// Use the first 20 results
Cursor cursor = JDOCursorHelper.getCursor(results);
https://developers.google.com/appengine/docs/java/datastore/jdo/queries
次に、カーソルを使用するには(提供されているドキュメントにもありますので、読んでおく必要があります)。
String cursorString = cursor.toWebSafeString();
// Send cursor around as string
// Query q = the same query that produced the cursor;
Cursor cursor = Cursor.fromWebSafeString(cursorString);
Map<String, Object> extensionMap = new HashMap<String, Object>();
extensionMap.put(JDOCursorHelper.CURSOR_EXTENSION, cursor);
q.setExtensions(extensionMap);
q.setRange(0, 20); //note, the same range;
//the query should cover everything you expect to load.
q.execute();
于 2012-12-30T11:58:00.687 に答える