【发布时间】:2018-06-15 10:35:28
【问题描述】:
我正在使用具有 10000 多个实体的 PersistenceManager 查询获取数据存储实体,我只想获取实体的键,因为我使用限制为 1000 的游标,但获取后游标为空
PersistenceManager pm = PMF.get().getPersistenceManager();
Query q = null;
List<String> idList = null;
int cursorLimit = 1000;
Map<String, Object> cursorMap = null;
Cursor cursorObj = null;
CommonUtil utility = new CommonUtil();
HashMap<String, Object> responseMap = null;
responseMap = new HashMap<String, Object>();
Query q = pm.newQuery("select id from " + Person.class.getName());
if( requestMap.containsKey("cursor") )
{
cursorMap = new HashMap<String,Object>();
cursorObj = Cursor.fromWebSafeString( String.valueOf( requestMap.get("cursor") ) );
cursorMap.put(JDOCursorHelper.CURSOR_EXTENSION, cursorObj);
q.setExtensions(cursorMap);
}
q.setRange(0, cursorLimit);
idList = (List<String>) q.execute();
cursorObj = JDOCursorHelper.getCursor(idList);
responseMap.put("contactIdList", idList);
if(idList.size() == cursorLimit && cursorObj != null)
responseMap.put("cursor", cursorObj.toWebSafeString());
else
responseMap.put("cursor", "");
q.closeAll();
pm.close();
但是 cursorObj 总是为空,有没有人提出这个问题或如何克服它
光标在获取整个实体时工作正常,但在键中仅查询它不能按预期工作
【问题讨论】:
标签: google-app-engine google-cloud-datastore datastore