Class HqlInClauseBatchHelper

java.lang.Object
com.atlassian.crowd.util.persistence.hibernate.HqlInClauseBatchHelper

public class HqlInClauseBatchHelper extends Object
A reusable batching helper for HQL queries using "in" clause with a list of parameters. This helper is here to help with not exceeding the in clause limit on various databases Clients may supply a Consumer instances for applying various parameters for Hibernate Query. Default batch size is 1000 elements provided to "in" clause, which can be overwritten using "crowd.query.in.batch.size" system property

Sample usage:

 
 final List<String> parameters = Lists.newArrayList("param1", "param2")
 HqlInClauseBatchHelper
      .ofNamedQuery(session, "removeInternalUserAttributesById")
      .executeUpdate("parametersNames", parameters);
 
 
  • Method Details

    • ofNamedQuery

      public static HqlInClauseBatchHelper.HqlInClauseBatchHelperBuilder ofNamedQuery(org.hibernate.Session session, String queryName)
      Constructs a new builder for HQL "in" clause helper with supplied hibernate session object and query name
      Parameters:
      session - hibernate session object
      queryName - name of the HQL query
      Returns:
      new HqlInClauseBatchHelperBuilder
    • ofHqlQuery

      public static HqlInClauseBatchHelper.HqlInClauseBatchHelperBuilder ofHqlQuery(org.hibernate.Session session, String query)
      Constructs a new builder for HQL "in" clause helper with supplied hibernate session object and HQL query
      Parameters:
      session - hibernate session object
      query - the HQL query
      Returns:
      new HqlInClauseBatchHelperBuilder
    • splitIntoBatches

      public static <T> Iterable<List<T>> splitIntoBatches(Iterable<T> inClauseObjects)
    • splitIntoBatchesList

      public static <T> List<List<T>> splitIntoBatchesList(Iterable<T> inClauseObjects)
    • setBatchSize

      public static void setBatchSize(int newBatchSize)
    • getBatchSize

      public static int getBatchSize()
    • executeUpdate

      public <T> void executeUpdate(String inClauseParameterName, Iterable<T> inClauseObjects)
      Executes HQL query in batches
      Type Parameters:
      T - represents a type of objects supplied to the query
      Parameters:
      inClauseParameterName - name of the in clause parameter in query
      inClauseObjects - list of parameters that will be supplied to in cluase parameter in query
    • query

      public <T> List<T> query(String inClauseParameterName, Iterable<?> inClauseObjects)