从 JDO 类访问自定义类
是的,我不知道我是否完全搞错了——我发现 JDO 和 Google AppEngine 有点难以掌握。不管怎样,就这样吧。
我有一个包含另一个类作为其内部变量之一的类(请参阅player1)
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class JDOGame
{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent
private String map;
@Persistent
private RPCDataPlayer player1;
// getters, setters, constructors etc...
}
RPCDataPlayer 类是可序列化的并且非常基本......
public class RPCDataPlayer implements IsSerializable
{
public String name;
public int id;
// getters & setters & constructors oh my
public int getId() { return id; }
}
所以,我的问题是......我如何创建一个查询来获取所有包含 id = x 的 RPCDataPlayer 的 JDOGames?
我无法执行诸如...之类的查询
SELECT FROM JDOGame.class.getName() WHERE player1.getId() == x
...那么人们有哪些技术或建议可以使其发挥作用?
提前致谢。
Right, I don't know if I'm barking entirely up the wrong tree here - I'm finding JDO and the Google AppEngine a bit tricky to get the hang of. Anyway, here goes.
I have a class that contains another class as one of it's internal variables (see player1)
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class JDOGame
{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
@Persistent
private String map;
@Persistent
private RPCDataPlayer player1;
// getters, setters, constructors etc...
}
The class RPCDataPlayer is Serializable and very basic....
public class RPCDataPlayer implements IsSerializable
{
public String name;
public int id;
// getters & setters & constructors oh my
public int getId() { return id; }
}
So, my question is...how do I create a query where I can get all the JDOGames that contain an RPCDataPlayer with id = x?
I can't do a query like...
SELECT FROM JDOGame.class.getName() WHERE player1.getId() == x
...so what techniques or suggestions do people have for this to work?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Google App Engine 数据库不是关系数据库,因此您无法进行连接。您可以将 RPCDataPlayer 保留为表。
然后你就可以这样查询。
一旦你有了 RPCDataPlayer 的实例,你就可以通过调用来获取 JDOGame:
The Google App Engine Database is not a relational database so you can not do joins. You can persist RPCDataPlayer as a table.
And then you can just query this like this.
Once you have and instance of RPCDataPlayer you can get get JDOGame by calling:
您的字段在数据存储中序列化,因此您显然无法在数据存储中执行查询,因此所有这些记录都需要检索并在内存中执行查询。当 GAE/J 最终齐心协力并允许人们这样做时,一切都会变得微不足道,直到那时您需要自己检索所有记录并进行检查。
与连接完全无关
Your field is serialised in the datastore, so you obviously can't do a query in the datastore, hence all of those records need retrieving and the query doing in-memory. When GAE/J finally get their act together and allow people to do that then it will be trivial, until then you need to retrieve all records yourself and do the check.
Nothing to do with joins at all