cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <>
Subject Re: split expressions
Date Wed, 13 Jan 2010 09:53:15 GMT

On Jan 13, 2010, at 11:21 AM, Aristedes Maniatis wrote:

> On 13/01/10 6:53 PM, Andrus Adamchik wrote:
>> Essentially the pipe symbol can only be used with 'matchAllExp'.  
>> This is
>> a special case, and I am not sure it makes sense in a general case.
>> General case is handled a bit differently via "path aliases". I.e.  
>> for
>> each group of paths that you want to be executed as a single join,  
>> you
>> create a single alias. Different aliases over matching paths generate
>> separate joins.
> Would it make sense to incorporate this idea into the new typesafe  
> Expression syntax planned for 3.1?

Yes, we'll need some kind of support for that.

> That is, you might combine expressions with:
>  exp1.and(exp2, Expression.SPLIT_PATH)
>  exp1.and(exp2, Expression.MERGE_PATH)
>  exp1.and(exp2)

I don't understand how the second argument is applicable in the  
context of "and"? Anyways,

> How do you use the aliases approach? The docs are a bit light in  
> that area.

Expression e1 ="", "foo");
Expression e2 ="", "bar");
Expression e3 ="", "bar");
Expression e = e1.andExp(e2).andExp(e3);

q = new SelectQuery(Artist.class, e);
q.aliasPathSplits("", "a", "b");

// e1 will have its own join; e2 and e3 will be run over the same  
single join

> Expression e1 ="",  
> "foo");
> Expression e2 ="",  
> "bar");
> Expression e = e1.andExp(e2);
> q = new SelectQuery(Artist.class, e);
> q.aliasPathSplits("","");
> In this example, can the alias and the path have the same name (this  
> means we don't need to change all the expressions)?

It can, but it will do the same thing that Cayenne is doing without  
the aliases - generate a single join. The only time you'll see a  
difference is when there are at least 2 (or more) different aliases  
for the same path, as in my example above.

> In any case, for us this is going to be complicated because the  
> expressions are created in one place long way away (in code) from  
> where the SelectQuery is created. So we might have to subclass  
> Expression in order to carry the extra information about aliases.

You will have to do some expression assembly magic one way or another.  
In the place where an Expression is created you may or may not know  
which subexpressions need to reuse joins and which don't. Thinking  
about it, it may be helpful to allow attaching aliases to path  
expressions after the fact in Cayenne. I.e. define aliases during the  
query assembly stage. Something to think about for 3.1.


View raw message