Package ubic.gemma.persistence.util
Class QueryUtils
- java.lang.Object
-
- ubic.gemma.persistence.util.QueryUtils
-
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_PARAMETER_LIST_SIZE
Largest parameter list size for whichoptimizeParameterList(Collection)
should be used.
-
Constructor Summary
Constructors Constructor Description QueryUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Identifiable>
List<List<T>>batchIdentifiableParameterList(Collection<T> list, int batchSize)
static <T extends Comparable<T>>
List<List<T>>batchParameterList(Collection<T> list, int batchSize)
Partition a parameter list into a collection of batches of a given size.static String
escapeLike(String s)
static <S extends Comparable<S>>
intexecuteUpdateByBatch(Query query, String batchParam, Collection<S> list, int batchSize)
Execute an update query by a fixed batch size.static <S extends Comparable<S>,T>
List<T>listByBatch(Query query, String batchParam, Collection<S> list, int batchSize)
static <S extends Comparable<S>,T>
List<T>listByBatch(Query query, String batchParam, Collection<S> list, int batchSize, int maxResults)
List the results of a query by a fixed batch size.static <S extends Identifiable,T>
List<T>listByIdentifiableBatch(Query query, String batchParam, Collection<S> list, int batchSize)
static <S extends Identifiable,T>
List<T>listByIdentifiableBatch(Query query, String batchParam, Collection<S> list, int batchSize, int maxResults)
static <T extends Identifiable>
Collection<T>optimizeIdentifiableParameterList(Collection<T> list)
Optimize a collection ofIdentifiable
entities.static <T extends Comparable<T>>
Collection<T>optimizeParameterList(Collection<T> list)
Optimize a given parameter list by sorting, removing duplicates and padding to the next power of two.static <T> Stream<T>
stream(Query query, Class<T> clazz)
static <S extends Comparable<S>,T>
Stream<T>streamByBatch(Query query, String batchParam, Collection<S> list, int batchSize)
Stream the results of a query by a fixed batch size.static <S extends Comparable<S>,T>
Stream<T>streamByBatch(Query query, String batchParam, Collection<S> list, int batchSize, Class<T> clazz)
-
-
-
Field Detail
-
MAX_PARAMETER_LIST_SIZE
public static final int MAX_PARAMETER_LIST_SIZE
Largest parameter list size for whichoptimizeParameterList(Collection)
should be used. Past this size, no padding will be performed and a warning will be emitted.- See Also:
- Constant Field Values
-
-
Method Detail
-
optimizeParameterList
public static <T extends Comparable<T>> Collection<T> optimizeParameterList(Collection<T> list)
Optimize a given parameter list by sorting, removing duplicates and padding to the next power of two.This is a temporary solution until we update to Hibernate 5.2.18 which introduced
hibernate.query.in_clause_parameter_padding
. Read more about this topic.
-
optimizeIdentifiableParameterList
public static <T extends Identifiable> Collection<T> optimizeIdentifiableParameterList(Collection<T> list)
Optimize a collection ofIdentifiable
entities.- See Also:
optimizeParameterList(Collection)
-
batchParameterList
public static <T extends Comparable<T>> List<List<T>> batchParameterList(Collection<T> list, int batchSize)
Partition a parameter list into a collection of batches of a given size.It is recommended to use a power of two in case the same query is also prepared via
optimizeParameterList(Collection)
. This will make it so that the execution plan can be reused.
-
batchIdentifiableParameterList
public static <T extends Identifiable> List<List<T>> batchIdentifiableParameterList(Collection<T> list, int batchSize)
-
listByBatch
public static <S extends Comparable<S>,T> List<T> listByBatch(Query query, String batchParam, Collection<S> list, int batchSize)
-
listByBatch
public static <S extends Comparable<S>,T> List<T> listByBatch(Query query, String batchParam, Collection<S> list, int batchSize, int maxResults)
List the results of a query by a fixed batch size.- Parameters:
query
- the querybatchParam
- a parameter of the query for batchinglist
- a collection of values for the batch parameters to retrievebatchSize
- the number of elements to fetch in each batchmaxResults
- maximum number of results to return, or -1 to ignore
-
listByIdentifiableBatch
public static <S extends Identifiable,T> List<T> listByIdentifiableBatch(Query query, String batchParam, Collection<S> list, int batchSize)
-
listByIdentifiableBatch
public static <S extends Identifiable,T> List<T> listByIdentifiableBatch(Query query, String batchParam, Collection<S> list, int batchSize, int maxResults)
-
streamByBatch
public static <S extends Comparable<S>,T> Stream<T> streamByBatch(Query query, String batchParam, Collection<S> list, int batchSize, Class<T> clazz)
-
streamByBatch
public static <S extends Comparable<S>,T> Stream<T> streamByBatch(Query query, String batchParam, Collection<S> list, int batchSize)
Stream the results of a query by a fixed batch size.
-
executeUpdateByBatch
public static <S extends Comparable<S>> int executeUpdateByBatch(Query query, String batchParam, Collection<S> list, int batchSize)
Execute an update query by a fixed batch size.- Returns:
- the sum of all performed update executions
- See Also:
Query.executeUpdate()
-
-