Class QueryUtils
Query.
Pre-phase-2 this class also accepted legacy org.hibernate.Criteria
inputs and tinkered with the MySQL JDBC driver to enable cursor-based
streaming. Hibernate 6 removed the Criteria API and the Hibernate-internal
accessors that streaming hack relied on. Streaming now uses
Query.scroll(ScrollMode) when supported and an offset/limit
fallback otherwise. Cursor-fetch tuning can be re-added if needed.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intLargest parameter list size for whichoptimizeParameterList(Collection)should be used. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <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 StringescapeLike(String s, char escapeChar) Escape the SQLLIKEwildcards insusing an explicit escape character.static <S extends Comparable<S>>
intexecuteUpdateByBatch(org.hibernate.query.Query<?> query, String batchParam, Collection<S> list, int batchSize) static <T> List<T> list(org.hibernate.query.Query<?> query) static <S extends Comparable<S>, T>
List<T> listByBatch(org.hibernate.query.Query<?> query, String batchParam, Collection<S> list, int batchSize) static <S extends Comparable<S>, T>
List<T> listByBatch(org.hibernate.query.Query<?> query, String batchParam, Collection<S> list, int batchSize, int maxResults) static <S extends Identifiable, T>
List<T> listByIdentifiableBatch(org.hibernate.query.Query<?> query, String batchParam, Collection<S> list, int batchSize) static <S extends Identifiable, T>
List<T> listByIdentifiableBatch(org.hibernate.query.Query<?> query, String batchParam, Collection<S> list, int batchSize, int maxResults) static <T extends Identifiable>
Collection<T> Optimize a collection ofIdentifiableentities by ID.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 org.hibernate.query.Query<?> setMaxResultsIfPositive(org.hibernate.query.Query<?> query, int maxResults) ApplyQuery.setMaxResults(int)only whenmaxResultsis positive.static <T> Stream<T> stream(org.hibernate.query.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(org.hibernate.query.Query<?> query, String batchParam, Collection<S> list, int batchSize) static <S extends Identifiable, T>
Stream<T> streamByIdentifiableBatch(org.hibernate.query.Query<?> query, String batchParam, Collection<S> list, int batchSize) static <T> TuniqueResult(org.hibernate.query.Query<?> query)
-
Field Details
-
MAX_PARAMETER_LIST_SIZE
public static final int MAX_PARAMETER_LIST_SIZELargest parameter list size for whichoptimizeParameterList(Collection)should be used.- See Also:
-
-
Constructor Details
-
QueryUtils
public QueryUtils()
-
-
Method Details
-
list
-
setMaxResultsIfPositive
public static org.hibernate.query.Query<?> setMaxResultsIfPositive(org.hibernate.query.Query<?> query, int maxResults) ApplyQuery.setMaxResults(int)only whenmaxResultsis positive.Hibernate 5+ rejects
setMaxResults(<0); many Gemma DAOs pass-1to mean "no limit". -
uniqueResult
public static <T> T uniqueResult(org.hibernate.query.Query<?> query) -
optimizeParameterList
Optimize a given parameter list by sorting, removing duplicates and padding to the next power of two. -
optimizeIdentifiableParameterList
public static <T extends Identifiable> Collection<T> optimizeIdentifiableParameterList(Collection<T> list) Optimize a collection ofIdentifiableentities by ID. -
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. -
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(org.hibernate.query.Query<?> query, String batchParam, Collection<S> list, int batchSize) -
listByBatch
public static <S extends Comparable<S>, T> List<T> listByBatch(org.hibernate.query.Query<?> query, String batchParam, Collection<S> list, int batchSize, int maxResults) -
listByIdentifiableBatch
public static <S extends Identifiable, T> List<T> listByIdentifiableBatch(org.hibernate.query.Query<?> query, String batchParam, Collection<S> list, int batchSize) -
listByIdentifiableBatch
public static <S extends Identifiable, T> List<T> listByIdentifiableBatch(org.hibernate.query.Query<?> query, String batchParam, Collection<S> list, int batchSize, int maxResults) -
streamByBatch
public static <S extends Comparable<S>, T> Stream<T> streamByBatch(org.hibernate.query.Query<?> query, String batchParam, Collection<S> list, int batchSize) -
streamByIdentifiableBatch
public static <S extends Identifiable, T> Stream<T> streamByIdentifiableBatch(org.hibernate.query.Query<?> query, String batchParam, Collection<S> list, int batchSize) -
stream
public static <T> Stream<T> stream(org.hibernate.query.Query<?> query, Class<T> resultType, int fetchSize, boolean useCursorFetchIfSupported, boolean isQueryStateless) Stream the result of a query with the given fetch size.Uses
Query.scroll(ScrollMode)when possible, otherwise falls back to offset/limit pagination. TheuseCursorFetchIfSupportedandisQueryStatelesshints are accepted for source compatibility but no longer dispatch on driver-specific tricks. -
createStream
-
executeUpdateByBatch
public static <S extends Comparable<S>> int executeUpdateByBatch(org.hibernate.query.Query<?> query, String batchParam, Collection<S> list, int batchSize) -
escapeLike
-
escapeLike
Escape the SQLLIKEwildcards insusing an explicit escape character.Both wildcards must be escaped,
_as much as%—_matches any single character, so leaving it raw makes a search for1007_s_atquietly match neighbours. The escape character itself is escaped too, so it is safe for it to occur in the data.The caller MUST emit a matching
escapeclause. Relying on the backslash default is not enough: under MySQL'sNO_BACKSLASH_ESCAPESmode a backslash is an ordinary character, and the escaped pattern then matches nothing at all rather than matching too much — which is exactly how underscore searches came to return empty results everywhere.
-