Datastore Query 是依赖于网络会话还是某个执行线程?
Do the Datastore Query is relying on a web session or some thread of execution?
我想知道数据存储区查询网络安全游标是否与任何网络会话或某些执行线程相关?,来自示例:
public class ListPeopleServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
resp.setContentType("text/html");
resp.getWriter().println("<ul>");
int pageSize = 15;
FetchOptions fetchOptions = FetchOptions.Builder.withLimit(pageSize);
String startCursor = req.getParameter("cursor");
// If this servlet is passed a cursor parameter, let's use it
if (startCursor != null) {
fetchOptions.startCursor(Cursor.fromWebSafeString(startCursor));
}
Query q = new Query("Person");
PreparedQuery pq = datastore.prepare(q);
QueryResultList<Entity> results = pq.asQueryResultList(fetchOptions);
for (Entity entity : results) {
resp.getWriter().println("<li>" + entity.getProperty("name") + "</li>");
}
resp.getWriter().println("</ul>");
String cursorString = results.getCursor().toWebSafeString();
// Assuming this servlet lives at '/people'
resp.getWriter().println(
"<a href='/people?cursor=" + cursorString + "'>Next page</a>");
}
}
我问这个是为了知道如果在 Restful 服务上,每个请求都是唯一的,并且根本没有会话处于活动状态,网络安全字符串是否仍然准确?
游标只是指向索引中某个位置的指针。它与任何网络会话或某些执行线程无关。您可以在多个线程或不同的用户会话中安全地使用它。
我想知道数据存储区查询网络安全游标是否与任何网络会话或某些执行线程相关?,来自示例:
public class ListPeopleServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
resp.setContentType("text/html");
resp.getWriter().println("<ul>");
int pageSize = 15;
FetchOptions fetchOptions = FetchOptions.Builder.withLimit(pageSize);
String startCursor = req.getParameter("cursor");
// If this servlet is passed a cursor parameter, let's use it
if (startCursor != null) {
fetchOptions.startCursor(Cursor.fromWebSafeString(startCursor));
}
Query q = new Query("Person");
PreparedQuery pq = datastore.prepare(q);
QueryResultList<Entity> results = pq.asQueryResultList(fetchOptions);
for (Entity entity : results) {
resp.getWriter().println("<li>" + entity.getProperty("name") + "</li>");
}
resp.getWriter().println("</ul>");
String cursorString = results.getCursor().toWebSafeString();
// Assuming this servlet lives at '/people'
resp.getWriter().println(
"<a href='/people?cursor=" + cursorString + "'>Next page</a>");
}
}
我问这个是为了知道如果在 Restful 服务上,每个请求都是唯一的,并且根本没有会话处于活动状态,网络安全字符串是否仍然准确?
游标只是指向索引中某个位置的指针。它与任何网络会话或某些执行线程无关。您可以在多个线程或不同的用户会话中安全地使用它。