Java Google App Engine:检索按属性排序并插入的所有实体以供以后检索,但保持其插入顺序
我正在使用 Java Google App Engine 和 Objectify3.0(因此某些类型可能看起来与标准 JPO/JPA 不同)。
无论如何,我希望能够检索按属性排序的所有实体并将其插入以供以后检索,以便您按照插入的排序顺序获取结果。
基本上,这意味着我想要一些东西:
- 检索所有实体(大约 10,000 个) 按“名称”升序排序。如果我尝试获取,将达到 30 秒响应限制 所有实体都一次性完成。
- 将顺序检索的实体插入另一种名为: 按游戏名称排序。这与游戏完全相同(见下文)。
- 从 SortedByNameGame 类型中检索实体(使用过滤器,例如流派=动作),但拥有它们 以升序排列的“名称”属性顺序返回,其中 实体被插入。
我的游戏类型如下所示:
public class Game {
@Id private Long id; //This is my key, auto generated by objectify
private String name;
private String genre;
private Date releasedate;
//ommitting getters and setters
}
我的 SortedByNameGame 类型如下所示:
public class SortedByNameGame {
@Id private Long id; //This is my key, auto generated by objectify
private Long gameid; //This is the Long id of the Game kind shown above
private String name;
private String genre;
private Date releasedate;
//ommitting getters and setters
}
我已经考虑并尝试了几种方法(围绕递归请求)但没有成功。例如:
带有任务的游标:我基本上使用此方法:http://code.google.com/p/objectify-appengine/wiki/IntroductionToObjectify#Cursors
带有RequestDispatcher.forward(请求,响应)的游标。类似于 http://code.google.com/p/objectify-appengine /wiki/IntroductionToObjectify#Cursors
带有 HttpServletResponse.sendRedirect(/pathToThisServlet) 的游标。类似于 http://code.google.com/p/objectify-appengine /wiki/IntroductionToObjectify#Cursors
后端:http: //code.google.com/appengine/docs/java/backends/overview.html。对此进行调查是因为他们没有 30 秒的响应时间限制。但是,我还没有让这些工作,即不知道如何通过浏览器访问它们。我收到 404 错误禁止。
我怀疑请求相同 URL/Servlet 的递归方法是不可能的,即“为了防止应用程序导致请求的无限递归,不允许请求处理程序获取自己的 URL。仍然可以通过其他方式导致无限递归,因此如果您的应用可以获取用户提供的 URL 请求,请务必小心。”(来源:http://code.google.com/appengine/docs/java/urlfetch/overview.html#Responses )
我的问题是
我做错了什么,导致这些递归队列任务没有被创建或递归请求不起作用?
或者,还有哪些其他方法可以实现我想要的功能?
I'm using Java Google App Engine with Objectify3.0 (so some of the kinds may look different to standard JPO/JPA).
Anyways, I want to be able to retrieve all entities sorted by a property and insert it for later retrieval so that you get the results back in the sorted order that it was inserted.
Basically, this means I want a few things:
- Retrieve all entities (around 10,000)
sorted by "name" in ascending order.The 30 seconds response limit will be hit if I try to get
all of the entities in one go. - Insert the order retrieved entities into another kind called:
SortedByNameGame. This is the exact same kind as game (see below). - Retrieve entities (with filters e.g. genre = action) from the SortedByNameGame kind but have them
returned in the sorted ascending "name" property order in which
entities were inserted.
My Game kind looks like this:
public class Game {
@Id private Long id; //This is my key, auto generated by objectify
private String name;
private String genre;
private Date releasedate;
//ommitting getters and setters
}
My SortedByNameGame kind looks like this:
public class SortedByNameGame {
@Id private Long id; //This is my key, auto generated by objectify
private Long gameid; //This is the Long id of the Game kind shown above
private String name;
private String genre;
private Date releasedate;
//ommitting getters and setters
}
I've considered and tried a couple of approaches (all around recursive requests) but have been unsuccessful. For example:
Cursors with tasks: I'm basically using this method: http://code.google.com/p/objectify-appengine/wiki/IntroductionToObjectify#Cursors
Cursors with RequestDispatcher.forward(request, response). Similar to http://code.google.com/p/objectify-appengine/wiki/IntroductionToObjectify#Cursors
Cursors with HttpServletResponse.sendRedirect(/pathToThisServlet). Similar to http://code.google.com/p/objectify-appengine/wiki/IntroductionToObjectify#Cursors
Backends: http://code.google.com/appengine/docs/java/backends/overview.html. Looking into this since they dont have a 30 second reponse timelimit. However, I haven't got these working yet i.e. don't know how to access them via the browser. I'm getting a 404 Error Forbidden.
I suspect that recursive approach of requesting the same URL/Servlet aren't possible i.e. "To prevent an app from causing an endless recursion of requests, a request handler is not allowed to fetch its own URL. It is still possible to cause an endless recursion with other means, so exercise caution if your app can be made to fetch requests for URLs supplied by the user." (source: http://code.google.com/appengine/docs/java/urlfetch/overview.html#Responses)
My questions are
What am I doing wrong such that these recursive queue tasks aren't being created or recursive requests aren't working?
Alternatively, what other approaches exist to do what I want?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论