You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Øyvind Harboe <oy...@zylin.com> on 2006/08/16 22:47:23 UTC

Is andExp supported on Scalar booleans?

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

Re: Is andExp supported on Scalar booleans?

Posted by Øyvind Harboe <oy...@zylin.com>.
On 8/17/06, Andrus Adamchik <an...@objectstyle.org> wrote:
> Good point. Another suggestion: instead of using ASTScalar, you can
> implement a similar custom subclass that extends ConditionNode. E.g.
> "ASTBoolean extends ASTCondition".

Just looking at some other implementations of ConditionNode, it seems
to me that this would have to go into Cayenne(to support parsing,
etc.)

> We should include this in Cayenne at some point too...

This was not *entirely* trivial, so I don't have a patch after my vain
fleeting attempts.


-- 
Øyvind Harboe
http://www.zylin.com

Re: Is andExp supported on Scalar booleans?

Posted by Andrus Adamchik <an...@objectstyle.org>.
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
>