Package ubic.gemma.persistence.util
Class QueryUtils
- java.lang.Object
-
- ubic.gemma.persistence.util.QueryUtils
-
-
Field Summary
Fields Modifier and Type Field Description static intMAX_PARAMETER_LIST_SIZELargest 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 <T> Stream<T>createStream(SessionFactory sessionFactory, Function<Session,Stream<T>> streamFactory, boolean createNewSession)static StringescapeLike(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 <T> List<T>list(Query query)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 ofIdentifiableentities.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(Criteria criteria, Class<T> resultType, int fetchSize, boolean useCursorFetchIfSupported, boolean isQueryStateless)static <T> Stream<T>stream(Query query, Class<T> resultType, int fetchSize, boolean useCursorFetchIfSupported, boolean isQueryStateless)Stream the result of a query with the given fetch size.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)static <T> TuniqueResult(Query query)
-
-
-
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
-
list
public static <T> List<T> list(Query query)
- See Also:
Query.list()
-
uniqueResult
public static <T> T uniqueResult(Query query)
- See Also:
Query.uniqueResult()
-
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 ofIdentifiableentities.- 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.
-
stream
public static <T> Stream<T> stream(Query query, Class<T> resultType, int fetchSize, boolean useCursorFetchIfSupported, boolean isQueryStateless)
Stream the result of a query with the given fetch size.If it is determined that setFetchSize() will not work, a strategy based on offset/limit will be used.
- Parameters:
useCursorFetchIfSupported- if cursor fetching is supported by the JDBC driver, it will be used. This has implications on performance of the database server because the whole result set will be loaded in memoryisQueryStateless- indicate if the query is stateless. A stateless query does not trigger any additional SQL statements upon being retrieved. If this is true, streaming will be enabled ifuseCursorFetchIfSupportedis set to false.
-
stream
public static <T> Stream<T> stream(Criteria criteria, Class<T> resultType, int fetchSize, boolean useCursorFetchIfSupported, boolean isQueryStateless)
-
createStream
public static <T> Stream<T> createStream(SessionFactory sessionFactory, Function<Session,Stream<T>> streamFactory, boolean createNewSession)
- Parameters:
streamFactory- a function that produces the stream from a givenSession. It may return null, in which case the session will be closed immediately
-
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()
-
-