开发者

JDO Queries: Is it possible to filter using complex objects?

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?


You can definitely do "child == childVal" (i.e equality) ... since you can in Java.

You cannot do assignment ("=").

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜