db-jdo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Bouschen <mbo.t...@spree.de>
Subject Re: Need help with query to select items through maps and sets
Date Sun, 17 Dec 2006 14:12:17 GMT
Hi Neil,

I agree the query should return a result. However, the query does not 
use the candidate class instances in the filter, instead it defines a 
variable of the same class Product. I think you intended to restrict the 
products being returned by the query. You can use the keyword this to 
refer the candidate class instances. Maybe you can try the following and 
see whether it returns a different result:
  Query q = pm.newQuery(Product.class);
  q.declareImports("import persistent.*");
  q.declareParameters("Department d");
  q.declareVariables("ClassNode c; Subclass s");
  q.setFilter("d.classesMap.containsValue(c) && 
c.subclassMap.containsValue(s) && s.products.contains(this) && 
(this.qtyAvailable>0)");
  Collection result = (Collection) q.execute(dept);

I hope this helps.

Regards Michael
> Hi Neil,
>
> The query looks fine to me. You probably should post this question on 
> the JPOX.org forum as well.
>
> Regards,
>
> Craig
>
> On Dec 16, 2006, at 12:39 PM, Neil Aggarwal wrote:
>
>> Hello:
>>
>> I am using JDO 2 (The JPOX implementation).
>>
>> I have four related persistent classes:
>> Product - contains a qtyAvailable for the quantity we can sell
>> Subclass - has a set of products
>> ClassNode - has a map of String to Subclass objects
>> Department - has a map of String to ClassNode objects.
>>
>> I want to get all of the products that are contained in
>> a department, so I wrote the query below.  Unfortunately,
>> it is giving me zero results.
>>
>> Here is the code I am using:
>>
>> Query q = pm.newQuery(Product.class);
>> q.declareImports("import persistent.*");
>> q.declareParameters("Department d");
>> q.declareVariables("ClassNode c; Subclass s; Product p");
>> q.setFilter("d.classesMap.containsValue(c) && 
>> c.subclassMap.containsValue(s)
>> && s.products.contains(p) && (p.qtyAvailable>0)");
>> Collection result = (Collection) q.execute(dept);
>>
>> Did I do something wrong in my query?
>>
>> Thanks,
>> Neil
>>
>>
>> -- 
>> Neil Aggarwal, (214)986-3533, www.JAMMConsulting.com
>> FREE! Eliminate junk email and reclaim your inbox.
>> Visit http://www.spammilter.com for details.
>>
>
> Craig Russell
> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
> 408 276-5638 mailto:Craig.Russell@sun.com
> P.S. A good JDO? O, Gasp!
>


-- 
Michael Bouschen		Tech@Spree Engineering GmbH
mailto:mbo.tech@spree.de	http://www.tech.spree.de/
Tel.:++49/30/235 520-33		Buelowstr. 66			
Fax.:++49/30/2175 2012		D-10783 Berlin			


Mime
View raw message