You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cayenne.apache.org by Marcel <em...@gmail.com> on 2006/07/25 03:38:22 UTC

ExpressionFactory.matchAllExp(...)

As far as I can tell there is a bug in 
ExpressionFactory.*matchAllExp*(java.util.Map map, int type).

With a map of keys and values, an exception will always arise here:

Thread [main] (Suspended)   
    ASTAnd(AggregateConditionNode).jjtAddChild(Node, int) line: 120   
    ASTAnd(SimpleNode).setOperand(int, Object) line: 187   
    ExpressionFactory.matchAllExp(Map, int) line: 298

jjtAddChild throws an exception whenNode is not of type ConditionNode or 
AggregateConditionNode. However, the Node parameter is just the Object 
parameter from setOperand, which is called from matchAllExp as:

exp.setOperand(0, new ASTObjPath(entry.getKey()));

Where entry.getKey() is the object path (in my case just the name of an 
object attribute). ASTObjPath is not of the correct type, so an 
exception is thrown everytime, regardless of what entry.getKey() happens 
to be.

Folks with more experience? I'll try just stringing my own expression 
together for now.

Marcel

Re: ExpressionFactory.matchAllExp(...)

Posted by Marcel <em...@gmail.com>.
Thanks. As an API comment consider that in:

    public static Expression *matchExp*(String pathSpec, Object value)

'match' implies the use of equals. My mistake was moving from matchExp 
to matchAllExp.

Marcel

Andrus Adamchik wrote:
>>    Expression qual = ExpressionFactory.matchAllExp(map, Expression.AND);
>
> This line should look like:
>
>    Expression qual = ExpressionFactory.matchAllExp(map, 
> Expression.EQUAL_TO);
>
> I.e. the last parameter refers to the operation inside each key/value 
> pair.
>
> Andrus
>
> On Jul 25, 2006, at 1:36 AM, Marcel wrote:
>> Andrus,
>>
>> Sorry, it came out unclearly in the email. The exception, an 
>> ExpressionException, doesn't have a stack trace.
>>
>> Here is a standalone snippet that will create the problem:
>>
>> private void matchAllTest() {
>>    HashMap map = new HashMap();
>>    map.put("test", "test");
>>    Expression qual = ExpressionFactory.matchAllExp(map, Expression.AND);
>> }
>
>

Re: ExpressionFactory.matchAllExp(...)

Posted by Andrus Adamchik <an...@objectstyle.org>.
>    Expression qual = ExpressionFactory.matchAllExp(map,  
> Expression.AND);

This line should look like:

    Expression qual = ExpressionFactory.matchAllExp(map,  
Expression.EQUAL_TO);

I.e. the last parameter refers to the operation inside each key/value  
pair.

Andrus

On Jul 25, 2006, at 1:36 AM, Marcel wrote:
> Andrus,
>
> Sorry, it came out unclearly in the email. The exception, an  
> ExpressionException, doesn't have a stack trace.
>
> Here is a standalone snippet that will create the problem:
>
> private void matchAllTest() {
>    HashMap map = new HashMap();
>    map.put("test", "test");
>    Expression qual = ExpressionFactory.matchAllExp(map,  
> Expression.AND);
> }


Re: ExpressionFactory.matchAllExp(...)

Posted by Marcel <em...@gmail.com>.
Andrus,

Sorry, it came out unclearly in the email. The exception, an 
ExpressionException, doesn't have a stack trace.

Here is a standalone snippet that will create the problem:

private void matchAllTest() {
    HashMap map = new HashMap();
    map.put("test", "test");
    Expression qual = ExpressionFactory.matchAllExp(map, Expression.AND);
}

I thought that ought to create a valid expression, but if you step 
through matchAllExp there is an exception thrown, and it doesn't seem to 
depend on the values of the map entry. I can't see how the unit test 
doesn't throw it.
Here is the stack as the exception is about to be thrown (explicitly 
using throw):

Thread [main] (Suspended)   
    ASTAnd(AggregateConditionNode).jjtAddChild(Node, int) line: 125   
    ASTAnd(SimpleNode).setOperand(int, Object) line: 187   
    ExpressionFactory.matchAllExp(Map, int) line: 298   
    SelectObjectPage2.matchAllTest()

Hope that is clearer. I've worked around it fairly simply.

Marcel

Andrus Adamchik wrote:
> Marcel,
>
> Could you post the actual code and exception stack trace? (sorry, I am 
> tired at the end of the day and can't make sense of what you wrote). 
> BTW, this unit test works:
>
>     public void testMatchAllExp() throws Exception {
>         // create expressions and check the counts,
>         // leaf count should be (2N) : 2 leafs for each pair
>         // node count should be (2N + 1) for nodes with more than 1 pair
>         // and 2N for a single pair : 2 nodes for each pair + 1 list node
>         // where N is map size
>
>         // check for N in (1..3)
>         for (int n = 1; n <= 3; n++) {
>             Map map = new HashMap();
>
>             // populate map
>             for (int i = 1; i <= n; i++) {
>                 map.put("k" + i, "v" + i);
>             }
>
>             Expression exp = ExpressionFactory.matchAllExp(map, 
> Expression.LESS_THAN);
>             assertNotNull(exp);
>             handler.traverseExpression(exp);
>
>             // assert statistics
>             handler.assertConsistency();
>             assertEquals("Failed: " + exp, 2 * n, handler.getLeafs());
>             assertEquals("Failed: " + exp, n < 2 ? 2 * n : 2 * n + 1, 
> handler
>                     .getNodeCount());
>         }
>     }
>
>
>
>
> On Jul 24, 2006, at 9:38 PM, Marcel wrote:
>
>>
>> As far as I can tell there is a bug in 
>> ExpressionFactory.*matchAllExp*(java.util.Map map, int type).
>>
>> With a map of keys and values, an exception will always arise here:
>>
>> Thread [main] (Suspended)      
>> ASTAnd(AggregateConditionNode).jjtAddChild(Node, int) line: 120      
>> ASTAnd(SimpleNode).setOperand(int, Object) line: 187      
>> ExpressionFactory.matchAllExp(Map, int) line: 298
>>
>> jjtAddChild throws an exception whenNode is not of type ConditionNode 
>> or AggregateConditionNode. However, the Node parameter is just the 
>> Object parameter from setOperand, which is called from matchAllExp as:
>>
>> exp.setOperand(0, new ASTObjPath(entry.getKey()));
>>
>> Where entry.getKey() is the object path (in my case just the name of 
>> an object attribute). ASTObjPath is not of the correct type, so an 
>> exception is thrown everytime, regardless of what entry.getKey() 
>> happens to be.
>>
>> Folks with more experience? I'll try just stringing my own expression 
>> together for now.
>>
>> Marcel
>>
>
>

Re: ExpressionFactory.matchAllExp(...)

Posted by Andrus Adamchik <an...@objectstyle.org>.
Marcel,

Could you post the actual code and exception stack trace? (sorry, I  
am tired at the end of the day and can't make sense of what you  
wrote). BTW, this unit test works:

     public void testMatchAllExp() throws Exception {
         // create expressions and check the counts,
         // leaf count should be (2N) : 2 leafs for each pair
         // node count should be (2N + 1) for nodes with more than 1  
pair
         // and 2N for a single pair : 2 nodes for each pair + 1 list  
node
         // where N is map size

         // check for N in (1..3)
         for (int n = 1; n <= 3; n++) {
             Map map = new HashMap();

             // populate map
             for (int i = 1; i <= n; i++) {
                 map.put("k" + i, "v" + i);
             }

             Expression exp = ExpressionFactory.matchAllExp(map,  
Expression.LESS_THAN);
             assertNotNull(exp);
             handler.traverseExpression(exp);

             // assert statistics
             handler.assertConsistency();
             assertEquals("Failed: " + exp, 2 * n, handler.getLeafs());
             assertEquals("Failed: " + exp, n < 2 ? 2 * n : 2 * n +  
1, handler
                     .getNodeCount());
         }
     }




On Jul 24, 2006, at 9:38 PM, Marcel wrote:

>
> As far as I can tell there is a bug in  
> ExpressionFactory.*matchAllExp*(java.util.Map map, int type).
>
> With a map of keys and values, an exception will always arise here:
>
> Thread [main] (Suspended)      ASTAnd 
> (AggregateConditionNode).jjtAddChild(Node, int) line: 120       
> ASTAnd(SimpleNode).setOperand(int, Object) line: 187       
> ExpressionFactory.matchAllExp(Map, int) line: 298
>
> jjtAddChild throws an exception whenNode is not of type  
> ConditionNode or AggregateConditionNode. However, the Node  
> parameter is just the Object parameter from setOperand, which is  
> called from matchAllExp as:
>
> exp.setOperand(0, new ASTObjPath(entry.getKey()));
>
> Where entry.getKey() is the object path (in my case just the name  
> of an object attribute). ASTObjPath is not of the correct type, so  
> an exception is thrown everytime, regardless of what entry.getKey()  
> happens to be.
>
> Folks with more experience? I'll try just stringing my own  
> expression together for now.
>
> Marcel
>