I have the following situation:
Class A extends B. Other classes, such as C, D, etc. also extend B In Class B, I would like to situate logic with regard to general information common to A, C, and D.
Hence, I would like to have a general query in B that retrieves all general info, but also be able to pass a Query to B so that the correct joins and conditions are fulfilled. Basically:
public B getB(String bUuid, Query extendedQuery) {
SelectQuery bQuery = ... dsl.select(/* general B columns */)
.select(/* SELECT part from extended query */)
.from(/* general B tables */)
.from(/* FROM part from extended query */) // maybe join with some if else logic instead
.where(/* general B conditions */)
.where(/* WHERE part of extended query */)
Is this possible using JOOQ? I would really not like to use plain SQL execution unless absolutely necessary.
EDIT:
Using the below answer, this is the final code I have that I am quite satisfied with:
public Record getB(String bUuid, Consumer<SelectQuery> extender)
Which I call as follows:
Record r = B.getB(uuid, query -> {
query.addSelect(...);
query.addJoin(...);
}
And in getB, after making our "general" SelectQuery query, we simply call:
extender.apply(query);
Afterwards we can simply do query.fetchOne() with our enhanced query.
Think functional, not object oriented! This would be a much simpler approach:
Now, you can call this higher-order function like so: