Good point. Another suggestion: instead of using ASTScalar, you can
implement a similar custom subclass that extends ConditionNode. E.g.
"ASTBoolean extends ASTCondition".
We should include this in Cayenne at some point too...
Andrus
On Aug 16, 2006, at 4:47 PM, Øyvind Harboe wrote:
> I'm getting an exception when I try to invoke andExp() on a Scalar
> expression:
>
> Expression e=new ASTScalar(Boolean.TRUE);
> e=e.andExp(ExpressionFactory.matchExp(propName + (i+1), t));
>
> [v.1.2-dev July 19 2006] And: invalid child - Scalar
> org.objectstyle.cayenne.exp.parser.AggregateConditionNode.jjtAddChild(
> AggregateConditionNode.java:125)
> org.objectstyle.cayenne.exp.parser.SimpleNode.setOperand
> (SimpleNode.java:187)
> org.objectstyle.cayenne.exp.Expression.joinExp(Expression.java:395)
> org.objectstyle.cayenne.exp.Expression.andExp(Expression.java:405)
>
> Some fiendishly clever code to work around horrid database structures
> for implementing trees:
>
> /* returns the non-recursive list of children based upon the old
> scheme for trees */
> public Expression getChildrenQualifierGeneric(
> /* Name of property without the number suffix, e.g.
> "treataspecVc" */
> String propName,
> /* total number of levels, for e.g. treataspecVc==5 */
> int totLevels)
> {
> try
> {
> OgnlContext context = new OgnlContext();
> Expression e=new ASTScalar(Boolean.TRUE);
>
> for (int i=0; i<totLevels; i++)
> {
> Object propObj;
> propObj = Ognl.parseExpression(propName + (i+1));
> String t=(String) Ognl.getValue(propObj, context, this);
> if (t==null)
> {
> e=e.andExp(ExpressionFactory.noMatchExp(propName + (i+1), null));
> e=e.andExp(ExpressionFactory.matchExp(propName + (i+2), null));
> return e;
> } else if ((i+1)<totLevels)
> {
> e=e.andExp(ExpressionFactory.matchExp(propName + (i+1), t));
> }
> }
> return new ASTScalar(Boolean.FALSE);
> } catch (OgnlException e)
> {
> throw new RuntimeException(e);
> }
> }
>
>
> --
> Øyvind Harboe
> http://www.zylin.com
>
This archive was generated by hypermail 2.0.0 : Thu Aug 17 2006 - 09:53:00 EDT