Class QueryUtil
java.lang.Object
com.ssgllc.fish.service.util.registered.QueryUtil
-
Constructor Summary
ConstructorsConstructorDescriptionQueryUtil
(jakarta.persistence.EntityManager entityManager, com.ssgllc.fish.service.GenericQueryService genericQueryService) -
Method Summary
Modifier and TypeMethodDescriptionstatic jakarta.persistence.EntityManager
Retrieves the EntityManager instance used for executing queries.Executes an HQL query and returns the result as a list of objects.queryListLimit
(String queryStr, Integer limit) Executes an HQL query with a result limit and returns the result as a list of objects.queryListLimitPage
(String queryStr, Integer limit, Integer pageNumber) Executes an HQL query with pagination and a result limit, returning the result as a list of objects.queryListParam
(String queryStr, Map<String, Object> params) Executes an HQL query with named parameters and returns the result as a list of objects.Executes an HQL query with named parameters and a result limit, returning the result as a list of objects.queryListParamLimitPage
(String queryStr, Map<String, Object> params, Integer limit, Integer pageNumber) Executes an HQL query with named parameters, pagination, and a result limit, returning the result as a list of objects.static Object
querySingle
(String queryStr) Executes an HQL query and returns a single result.static Object
querySingleParam
(String queryStr, Map<String, Object> params) Executes an HQL query with named parameters and returns a single result.
-
Constructor Details
-
QueryUtil
public QueryUtil(jakarta.persistence.EntityManager entityManager, com.ssgllc.fish.service.GenericQueryService genericQueryService)
-
-
Method Details
-
queryList
Executes an HQL query and returns the result as a list of objects.- Parameters:
queryStr
- The HQL query string to execute.- Returns:
- A list of query results.
- Throws:
Exception
- If an error occurs while executing the query.
Groovy example:
return queryUtil.queryList("select f.id from FieldConfig f")
-
queryListLimit
Executes an HQL query with a result limit and returns the result as a list of objects.- Parameters:
queryStr
- The HQL query string to execute.limit
- The maximum number of results to return.- Returns:
- A list of query results, limited to the specified number.
- Throws:
Exception
- If an error occurs while executing the query.
Groovy example:
return queryUtil.queryListLimit("select f.id from FieldConfig f", 5)
-
queryListLimitPage
public static List<Object> queryListLimitPage(String queryStr, Integer limit, Integer pageNumber) throws Exception Executes an HQL query with pagination and a result limit, returning the result as a list of objects.- Parameters:
queryStr
- The HQL query string to execute.limit
- The maximum number of results per page.pageNumber
- The zero-based page number to retrieve.- Returns:
- A list of query results for the specified page, limited to the given number of results.
- Throws:
Exception
- If an error occurs while executing the query.
Groovy example:
return queryUtil.queryListLimitPage("select f.id from FieldConfig f", 5, 1)
-
queryListParam
public static List<Object> queryListParam(String queryStr, Map<String, Object> params) throws ExceptionExecutes an HQL query with named parameters and returns the result as a list of objects.- Parameters:
queryStr
- The HQL query string to execute.params
- A map of named parameters to be set in the query.- Returns:
- A list of query results.
- Throws:
Exception
- If an error occurs while executing the query.
Groovy example:
return queryUtil.queryListParam("select f.id from FieldConfig f where f.name = :name", [name: "title"])
-
queryListParamLimit
public static List<Object> queryListParamLimit(String queryStr, Map<String, Object> params, Integer limit) throws ExceptionExecutes an HQL query with named parameters and a result limit, returning the result as a list of objects.- Parameters:
queryStr
- The HQL query string to execute.params
- A map of named parameters to be set in the query.limit
- The maximum number of results to return.- Returns:
- A list of query results, limited to the specified number.
- Throws:
Exception
- If an error occurs while executing the query.
Groovy example:
return queryUtil.queryListParamLimit("select f.id from FieldConfig f where f.createdDate > :date", [date: dateUtil.startOfToday()], 10)
-
queryListParamLimitPage
public static List<Object> queryListParamLimitPage(String queryStr, Map<String, Object> params, Integer limit, Integer pageNumber) throws ExceptionExecutes an HQL query with named parameters, pagination, and a result limit, returning the result as a list of objects.- Parameters:
queryStr
- The HQL query string to execute.params
- A map of named parameters to be set in the query.limit
- The maximum number of results per page.pageNumber
- The zero-based page number to retrieve.- Returns:
- A list of query results for the specified page, limited to the given number of results.
- Throws:
Exception
- If an error occurs while executing the query.
Groovy example:
return queryUtil.queryListParamLimitPage("select f.id from FieldConfig f where f.createdDate > :date", [date: dateUtil.startOfToday()], 10, 2)
-
querySingle
Executes an HQL query and returns a single result.- Parameters:
queryStr
- The HQL query string to execute.- Returns:
- A single query result, or null if no result is found.
- Throws:
Exception
- If an error occurs while executing the query including finding more than one result.
Groovy example:
return queryUtil.querySingle("select f.id from FieldConfig f where f.name = 'deduplicationEnabled'")
-
querySingleParam
Executes an HQL query with named parameters and returns a single result.- Parameters:
queryStr
- The HQL query string to execute.params
- A map of named parameters to be set in the query.- Returns:
- A single query result, or null if no result is found.
- Throws:
Exception
- If an error occurs while executing the query including finding more than one result.
Groovy example:
return queryUtil.querySingleParam("select f.id from FieldConfig f where f.name = :name", [name: "deduplicationEnabled"])
-
getEntityManager
public static jakarta.persistence.EntityManager getEntityManager()Retrieves the EntityManager instance used for executing queries.- Returns:
- The EntityManager instance.
Groovy example:
return queryUtil.getEntityManager()
-