In order to avoid re-creating the same part of a dynamic query over and over again, I was going to build the main part once and then reuse this part in different parts of the application. Since building the query is somewhat involved (see question jOOQ: best way to get aliased fields (from #as(alias, aliasFunction)) for one aspect of why this is the case), this should benefit performance...
Unfortunately, I've had to realize that the different "steps" in the builder pattern don't return amended copies, but modify underlying state. Thus, I've looked for a way to create an immutable copy of a specific "step" (e.g. SelectWhereStep
) from which to initialize and subsequently amend a (Select-)query each time I need it. Unfortunately, I haven't been able to identify any ("legal") way of achieving this.
Can it be done? If not, what's the best alternative?