Great, looks like exactly what I was looking for! Sorry for missing that in 
the documentation, it's really vast and I probably skipped this small 
chapter :)

Is the following a correct way to get a SelectQuery without a DSLContext? 
I'd prefer to keep this class a mere transformer, not aware of any 
contexts, dialects and moreover database connections.
SelectQuery<Record> select = DSL.select( fieldsList )
                                .from( table )
                                .getQuery();


On Monday, October 30, 2017 at 5:40:41 PM UTC+2, Lukas Eder wrote:
>
> Hi,
>
> Your use-case is covered by the model API, much better than the DSL API. 
> More info here:
>
> https://www.jooq.org/doc/latest/manual/sql-building/sql-statements/dsl-and-non-dsl
>
> It's also what the DSL delegates all calls to, internally.
>
> Hope this helps,
> Lukas
>
> 2017-10-30 16:36 GMT+01:00 <[email protected] <javascript:>>:
>
>> Suppose I have a decomposed query in some format, like "fields=a,b,c; 
>> whereClause='1=1'; groupBy=b,c;" etc. Some parts of the query might be 
>> missing, which corresponds to missing SQL part (e.g. a select without where 
>> clause). Having that, I'd like to compose a jOOQ query which could be run 
>> by some external executor, suppose a default DSL.using( conn, dialect 
>> ).fetch( constructedQuery ).
>>
>> Currently my code looks like the following:
>>
>> Select select = select( fieldsList ).from( myTable );
>>
>> if( hasWhereClause )
>> {
>>   select = ((SelectJoinStep) select).where( whereClause );
>> }
>>
>> if( hasGroupBy )
>> {
>>   select = ((SelectConditionStep) select).groupBy( groupByClause );
>> }
>>
>> if( hasOrderBy )
>> {
>>   select = ((SelectHavingStep) select).orderBy( orderByClause );
>> }
>>
>> ...
>>
>> return select;
>>
>>
>> As you see, because of the class hierarchy (which I actually like and 
>> admire a bit, since I can see it could not be easily designed), I either 
>> need multiple class casts or lots of nested if-statements - and both 
>> options are not really exciting.
>>
>> So maybe I'm missing something, or maybe there's an alternative builder 
>> for jOOQ queries (if not, I suppose one of the best solutions would be to 
>> have one), with which the code would look like the following:
>> new JooqQueryBuilder()
>>     .withFrom(TableLike)
>>     .withWhereClause(Condition)
>>     .withGroupBy(List<GroupByField>)
>>     ...
>>
>> Hope I managed to clearly describe the problem, but if you need any 
>> further clarification - I would be glad to provide such. 
>>
>> -- 
>> 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] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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.

Reply via email to