JDO 查询:是否可以使用复杂对象进行过滤?
我对 JDO 很陌生,想询问是否可以使用复杂对象进行过滤。我知道你可以这样做:
Query q = pm.newQuery(MyClass.class, "field1 < value");
q.declareParameters("int value");
List results = q.execute(205);
Iterator iter = results.iterator();
但假设我有以下情况:
@PersistenceCapable(...)
class ParentObj{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
String id;
...
@Persistent
ChildObj child;
}
@PersistenceCapable(...)
class ChildObj{
@Persistent
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
String id;
...
}
现在假设我想过滤所有具有给定 ChildObj
的 ParentObj
对象。我有
public List<ParentObj> getAllParentObjBy(ChildObj child){
PersistenceManager pm = ...
Query query = pm.newQuery(ParentObj.class, "child = childVal");
query.declareParameters("ChildObj childVal");
Collection result = (Collection)query.execute(child);
//???
return result;
}
这是非常伪代码,但我希望这个想法是清楚的。我可以像第一个示例一样使用 Query 对象,但在本例中使用 child
实例吗?
I'm quite new to JDO and wanted to ask if it is possible to filter using complex objects. I know that you can do something like this:
Query q = pm.newQuery(MyClass.class, "field1 < value");
q.declareParameters("int value");
List results = q.execute(205);
Iterator iter = results.iterator();
But assume I have the following situation:
@PersistenceCapable(...)
class ParentObj{
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
String id;
...
@Persistent
ChildObj child;
}
@PersistenceCapable(...)
class ChildObj{
@Persistent
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
String id;
...
}
Now assume I want to filter all ParentObj
objects that have some given ChildObj
. I have
public List<ParentObj> getAllParentObjBy(ChildObj child){
PersistenceManager pm = ...
Query query = pm.newQuery(ParentObj.class, "child = childVal");
query.declareParameters("ChildObj childVal");
Collection result = (Collection)query.execute(child);
//???
return result;
}
This is very pseudocode, but I hope the idea is clear. Can I somehow use the Query object like in the first example but in this case with the child
instance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你绝对可以做“child == childVal”(即相等)......因为你可以在Java中做。
您不能进行赋值(“=”)。
You can definitely do "child == childVal" (i.e equality) ... since you can in Java.
You cannot do assignment ("=").