You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-user@db.apache.org by Neil Aggarwal <ne...@JAMMConsulting.com> on 2006/12/16 21:39:37 UTC
Need help with query to select items through maps and sets
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.
Re: Need help with query to select items through maps and sets
Posted by Michael Bouschen <mb...@spree.de>.
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
Re: Need help with query to select items through maps and sets
Posted by Craig L Russell <Cr...@Sun.COM>.
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!