Re: split expressions

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Jan 13 2010 - 04:53:15 EST

  • Next message: Andrus Adamchik: "Re: split expressions"

    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 = ExpressionFactory.like("a.name", "foo");
    Expression e2 = ExpressionFactory.like("b.name", "bar");
    Expression e3 = ExpressionFactory.like("b.name", "bar");
    Expression e = e1.andExp(e2).andExp(e3);

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

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

    > Expression e1 = ExpressionFactory.like("paintings.gallery.name",
    > "foo");
    > Expression e2 = ExpressionFactory.like("paintings.gallery.name",
    > "bar");
    > Expression e = e1.andExp(e2);
    >
    > q = new SelectQuery(Artist.class, e);
    > q.aliasPathSplits("paintings.gallery","paintings.gallery");
    >
    > 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.

    Andrus



    This archive was generated by hypermail 2.0.0 : Wed Jan 13 2010 - 04:54:07 EST