Class SelectQueryExtender


  • public class SelectQueryExtender
    extends java.lang.Object
    Provides a convenient (and MySQL-friendly) way of solving the use-case of querying records by N-tuples of identifiers. The simplest case is querying by a list of IDs in which case it could be expressed with a simple IN. However in terms of performance (and logs) it's better to do a join with a temporary table populated with those IDs instead. This class does it automatically. In the more complicated case where the lookup is done by two fields (e.g. profile/affcode), it is impossible to express it with an IN condition and a temp table has to be used in this case. Example of simple usage:
     AdCriterias ac = AdCriterias.TABLE;
     SelectConditionStep<Record2<String, Integer>> query = dslContext.select(ac.affcode, ac.criteria_id)
             .from(ac).where(ac.profile_id.eq(profileId));
     try (QueryExtension<SelectConditionStep<Record2<String, Integer>>> queryExtension =
             SelectQueryExtender.of(query).withCondition(ac.affcode).in(affcodes)) {
         return queryExtension.getQuery().fetchMap(ac.affcode, ac.criteria_id);
     }
     
    The returned object is a resource and it is crucial to place it inside try/finally block so it could be closed
    • Constructor Detail

      • SelectQueryExtender

        public SelectQueryExtender()
    • Method Detail

      • of

        public static <Q extends org.jooq.SelectFinalStep> QueryExtension<Q> of​(org.jooq.DSLContext dslContext,
                                                                                Q query,
                                                                                java.util.List<FieldAndValues<?>> conditions)