Hello all,
I've the following problem: one of my Cayenne object allows the storage of
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
This object (Name.class) has mailnly 3 fields, a name (String) field
(containing things like "node XXX 123" or "leaf ABC 345"),
a boolean field (named "approved") that tells if the object is a node
(approved == true) or a leaf (approved == false) and a List attibuted (named
"variantForms") generated by Cayenne and modelling the parent-children
relation.
Now I would like to search all nodes whose name contains "XXX" and are
approved, or any nodes that have leaves whose names contain "XXX" (I will
then build a tree showing all these nodes with all their leaves, if any).
I've tried the following code snippets for the "exp" parte of the statement
"new SelectQuery(Name.class, exp)":
1.
Expression exp = ExpressionFactory.likeIgnoreCaseExp("name", "%" + stext +
"%");
exp = exp.orExp(ExpressionFactory.likeIgnoreCaseExp("variantForms.name", "%"
+ stext + "%"));
exp = exp.andExp(ExpressionFactory.matchExp("approved", Boolean.TRUE));
2.
List expList = new ArrayList();
expList.add(
ExpressionFactory.likeIgnoreCaseExp("variantForms.name", "%" + stext +
"%").andExp(
ExpressionFactory.matchExp("approved", Boolean.TRUE)
)
);
expList.add(
ExpressionFactory.likeIgnoreCaseExp("name", "%" + stext + "%").andExp(
ExpressionFactory.matchExp("approved", Boolean.TRUE)
)
);
Expression exp = ExpressionFactory.joinExp(Expression.OR, expList);
but when the query is executed the resul was always:
+ node XXX 123
+ leaf ABC 345
+ leaf DFG 456
+ node AFG 954
+ leaf DFG 456
+ leaf XXX 336
(i.e. nodes "node XXX 123" and "node AFG 954"), instead of
+ node XXX 123
+ leaf ABC 345
+ leaf DFG 456
+ node AFG 954
+ leaf DFG 456
+ leaf XXX 336
+ node XXX 345
(i.e. nodes "node XXX 123", "node AFG 954" ***AND*** "node XXX 345").
That is only nodes that have leaves (children) are returned.
I don't undertand how to build the correct query. There is someone that can
help me?
Thanks in advance.
Claudio
Multimedia <http://www.acsys.it/> Division
Claudio Rosati
Project Manager Advanced Computer Systems S.p.A.
via Della Bufalotta 378
00139 Roma, RM
Italy
claudio.rosat..csys.it
tel:
fax: +39 06 8709 0516
+39 06 8720 1502
<http://www.plaxo.com/signature> Signature powered by Plaxo
<http://www.plaxo.com/signature> Want a signature like this?
<https://www.plaxo.com/add_me?u=4295038861&v0=140354&k0=586510396> Add me
to your address book...
This archive was generated by hypermail 2.0.0 : Tue Aug 24 2004 - 09:52:12 EDT