Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Support for multi-column in-clauses #313
When dealing with multi column primary keys in-clause becomes
While this can be achieved using custom extension, it would be nice to have "official" support - or is there one already? ArrayPath?
Here's an example, how this works using custom template-extension:
There is one caveat to be aware of: how to do subQuery.list differs in different DB's. In H2 one needs to use similar expression in select-subquery: where (x, y) in (select (x2, y2) from...). Can this kind of difference be resolved with SQLTemplates? Something like MultiColumnKeyExpression<Object> that has different serialization in select and where part of the query.
A nice helper for MultiColumnExpressions could be added to into PrimaryKey and ForeignKey - something similar to getLocalColumns() but returning an Expression instead of List. Having serialization of this kind of MultiColumnExpression take single-column expression as an special case into account (serialize without parenthesis), this would probably be quite usable shortcut for single or multi-column comparisons.
The following static method in ExpressionUtils does it
But I will put it into the Expressions class as well, which is more part of the public API
Should be possible.
...or maybe PrimaryKey and ForeignKey could them selves implement this kind of (multi) column expression? That would be most handy.
There seems to be quite much variance in how this kind of statements are supported. At least when tested with http://sqlfiddle.com/. In some DB's you can even use this kind of comparisons: (a,b) = (c,d) in joins and where.
Having Querydsl solve those mismatches (e.g. converting previous example into (a=c and b=d) in Oracle) would be great! - And I guess that requires support at SQLTemplates level (i.e. Querydsl internal) - ?