Hi,
I searched around in the group but didn't find much in the way of a
stylistic guide on using the DSL to write queries with *conditional*
components. The best way to illustrate what I mean is an example:
Let's say may "base" query is
SELECT * FROM A
But sometimes I need to join B
SELECT * FROM A JOIN B ON (A.id = B.id)
Let's also say that I need to add multiple predicates to the result...
again sometimes
SELECT * FROM A JOIN B ON (A.id = B.id)
WHERE A.foo = '1' -- sometimes we look for these *foo* values
AND B.bar = '2' -- sometimes we look for these *bar* values
AND A.baz = '3' -- sometimes we look for these *baz* values
Let's say that the need to add each of the above predicates is dictated by
some condition in my code. The problem is the nice clean fluent DSL starts
to look messy and ugly because it gets broken up by a bunch of conditionals
TableOnConditionStep fromClause = table("B")
.join(table("B")).on("A.id = B.id");
if (joinTableC == true){
fromClause = fromClause.join(table("C")).on("B.id = C.d");
}
dsl.select( ... )
.from( fromClause );
Another example
SelectOnConditionStep statement = select(Temperatures.VALUE, Temperatures.
TIMESTAMP)
.from(Temperatures)
.where(Temperatures.VALUE.greaterOrEqual(0));
if (filter.hasMaxValue())
statement.and(Temperatures.VALUE.lessOrEqual(filter.getMaxValue());
if (filter.hasLocation())
statement.and(Temperatures.LOCATION.equal(filter.getLocation());
// And so on with the rest of filters to end with:
statement.orderBy(Temperature.TIMESTAMP)
.fetch();
The once pretty fluent style becomes chopped up and hard to follow. The
blog post here
<http://www.programania.net/diseno-de-software/functional-trick-to-compose-conditions-in-jooq/>
discusses this in more detail and presents an elegant solution. I'd like to
hear how other people are handling this... Also wondering if future
versions of JOOQ will have this in mind,
Thanks,
Max
--
You received this message because you are subscribed to the Google Groups "jOOQ
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.