If you have the following tree:
+ node XXX 123
+ leaf ABC 345
+ leaf DFG 456
+ node AFG 954
+ leaf DFG 456
+ leaf XXX 336
+ node XXX 345
+ node HFK 456
+ leaf DFG 194
+ node XXX 234
+ leaf XXX 555
The first query will return
+ node XXX 123
+ leaf ABC 345
+ leaf DFG 456
+ node XXX 345
+ node XXX 234
+ leaf XXX 555
And the second one
+ node AFG 954
+ leaf DFG 456
+ leaf XXX 336
+ node XXX 234
+ leaf XXX 555
As you can see the subtree rooted at "node XXX 234" appears twice.
I think should be 3 possible solution:
1. formulate the right query that will return all right objects;
2. make two queries, where the second one should return only
first level nodes without leaves
(getApproved().booleanValue() == true, getVariantForms().size == 0)
3. make the the following two queries
i. ExpressionFactory.likeIgnoreCaseExp("variantForms.name", "%" +
stext + "%").andExp(
ExpressionFactory.matchExp("approved", Boolean.TRUE)
)
ii. ExpressionFactory.likeIgnoreCaseExp("name", "%" + stext +
"%").andExp(
ExpressionFactory.matchExp("approved", Boolean.TRUE)
)
checking every elements in the list returned by II.) if contained
into the list returned by i.) and removing it from one list.
I think that solution 1) should be possible. Moreover is to only solution
that let you query "ordered" results. The problem is that I don't know how
formulate it!
Claudio
------------------------------------
Advanced Computer Systems S.p.A.
Claudio Rosati
Project Manager
claudio.rosat..csys.it
via Della Bufalotta 378
00139 Roma, RM
Italy
tel: +39 06 8709 0516
fax: +39 06 8720 1502
------------------------------------
> -----Messaggio originale-----
> Da: Tore Halset [mailto:halse..vv.ntnu.no]
> Inviato: mercoledė 25 agosto 2004 9.39
> A: Claudio Rosati
> Cc: cayenne-use..bjectstyle.org
> Oggetto: Re: R: Unable to build the right expression
>
> On Aug 25, 2004, at 9:32, Claudio Rosati wrote:
>
> > OK, but how can I query for nodes without leaves? The following
> > expression will work
> > exp =
> exp.andExp(ExpressionFactory.matchExp("variantForms", null))
> > (I think no, because being "variantForms" a List mapping a to-many
> > relation, ti will be always non-null but, eventually, empty).
>
> I guess I do not fully understand your problem. My solution
> was to create two separate queries:
>
> 1: query for nodes containing stext.
> ExpressionFactory.likeIgnoreCaseExp("name", "%" + stext + "%");
> + node XXX 123
> + leaf ABC 345
> + leaf DFG 456
> + node XXX 345
>
> 2: query for nodes that has a leaf that contains stext.
> ExpressionFactory.likeIgnoreCaseExp("variantForms.name", "%" + stext +
> "%")
> + node AFG 954
> + leaf DFG 456
> + leaf XXX 336
>
> Of cource some nodes might qualify for both query 1 and 2,
> but that should be easy to filter out in your application.
>
> - Tore.
This archive was generated by hypermail 2.0.0 : Wed Aug 25 2004 - 04:06:50 EDT