Hello jOOQ users,

My goal is to allow a user to filter and order returned data based on a 
variety of fields. For this, I am using jOOQ to construct an ad-hoc query. 
For optimal performance, I don't want to join any tables unless they are 
necessary for the user-specified filtering and ordering configuration. 
However, if I put redundant joins to the same table, I will get a 
BadSqlGrammarException ('table name "address" specified more than once'). 
How can I inspect the query object to determine which tables have already 
been joined?

To clarify what I'm trying to do, I have included a simplified example 
below. How should I write the commented-out "address table not yet joined?" 
condition?


// I start with a base query
Select query = dsl.select(field('name')).from(table('person'));

// ... later, I join in tables needed for my 'where' clause
if(filter.city != ""){
  query = query.join(table('address')).on(field('person.address_id').equal(
field('address.id')));
}

// ... elsewhere, I join in tables needed for my 'order by' clause
if(order.byCity && /* address table not yet joined? */ ){
  query = query.join(table('address')).on(field('person.address_id').equal(
field('address.id')));
}

// ... and finally, I will construct the actual clauses
if(filter.city != ""){
  query = query.where(field('city').equal(filter.city));
}
if(order.byCity){
  query = query.orderBy(field('city').asc());
}



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