Class DAOUtils
java.lang.Object
overit.geocallapp.utilities.core.data.DAOUtils
Utility class providing common operations for
DAO interactions and business object management. - Since:
- 1.0
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends DynO>
voidaddTotalToResponse(DBView result, PageResponse<T> pageResponse) Adds total count information to a paginated response if available.static StringBuilds a SQL count field with the default alias.static StringbuildCountField(String alias) Builds a SQL count expression with a custom alias.static StringbuildInClause(String parameter, String field, Collection<?> values) Builds a SQL IN clause with custom parameter and field names using the provided collection of values.static StringbuildInClause(String parameter, String field, Collection<?> values, boolean manageEmptyCollection) Builds a SQL IN clause with custom parameter and field names using the provided collection of values.static StringbuildInClause(String parameter, String field, CommandContext commandContext) Builds a SQL IN clause with custom parameter and field names using values fromCommandContext.static StringbuildInClause(String field, CommandContext commandContext) Builds a SQL IN clause for the specified field using values fromCommandContext.buildSqlOrder(Order order, DynOCreator<T> creator) Builds SQL ORDER BY clause fromOrdercriteria.static voidChecks if an entity exists with the given primary key and filters.static voidDeletes an entity from the database by its primary key.Deprecated, for removal: This API element is subject to removal in a future version.Retrieves the list of default decisions for search DAOs.static CriteriaDeprecated, for removal: This API element is subject to removal in a future version.static CriteriaRetrieves the default filter criterion for search DAOs.static CriteriagetDefaultFilterCriterion(CommandContext cc, Decision... decisions) Retrieves the default filter criterion for search DAOs with additional custom decisions.static CriteriagetDefaultFilterCriterion(Decision... decisions) Deprecated, for removal: This API element is subject to removal in a future version.Inserts a new business object into the database.static <T extends DynO>
TLoads a business object by its primary key using the specifiedDAOand business object class.static <T extends DynO>
TLoads a business object by its primary key using a customDynOCreator.static <T extends DynO>
Tload(Object id, Map<String, Object> filters, Class<? extends DAO> daoClass, Class<T> boClass, PoolKit poolKit) Loads a business object by its primary key with additional visibility filters.static <T extends DynO>
Tload(Object id, Map<String, Object> filters, Class<? extends DAO> daoClass, DynOCreator<T> creator, PoolKit poolKit) Loads a business object by its primary key with additional filters using a customDynOCreator.static <T extends DynO>
PageResponse<T> search(Map<String, Object> filter, Class<? extends DAO> daoClass, Class<T> boClass, Page page, PoolKit poolKit) Searches for business objects using filters and pagination.static <T extends DynO>
PageResponse<T> search(Map<String, Object> filter, Class<? extends DAO> daoClass, DynOCreator<T> creator, Page page, PoolKit poolKit) Searches for business objects using filters, pagination and a customDynOCreator.static <T extends DynO>
PageResponse<T> search(Map<String, Object> filter, Order order, Class<? extends DAO> daoClass, Class<T> boClass, Page page, PoolKit poolKit) Searches for business objects using filters, ordering and pagination.static <T extends DynO>
PageResponse<T> search(Map<String, Object> filter, Order order, Class<? extends DAO> daoClass, DynOCreator<T> creator, Page page, PoolKit poolKit) Search method with full customization options including filters, ordering, pagination and custom creator.static voidValidates the command type of the currentCommandContext.static <T extends DynO>
voidUpdates an existing business object in the database with field exclusions.static <T extends DynO>
voidUpdates an existing business object in the database.
-
Field Details
-
COUNT_FIELD
- See Also:
-
UPPER
CustomCriterionfor case-insensitive string comparison using UPPER() SQL function.- See Also:
-
-
Method Details
-
load
public static <T extends DynO> T load(Object id, Class<? extends DAO> daoClass, Class<T> boClass, PoolKit poolKit) throws DAValidateException, DAException Loads a business object by its primary key using the specifiedDAOand business object class.- Type Parameters:
T- the type of business object to load- Parameters:
id- the primary key of the business object to loaddaoClass- theDAOclass to use for loadingboClass- theDynOextension class that implements the business objectpoolKit- thePoolKit- Returns:
- the loaded business object instance
- Throws:
DAValidateException- if the item is not foundDAException- if a data access error occursoverit.geocall.asserts.AssertsException- if the givenDAOhas no sequence field configured
-
load
public static <T extends DynO> T load(Object id, Class<? extends DAO> daoClass, DynOCreator<T> creator, PoolKit poolKit) throws DAValidateException, DAException Loads a business object by its primary key using a customDynOCreator.- Type Parameters:
T- the type of business object to load- Parameters:
id- the primary key of the business object to loaddaoClass- theDAOclass to use for loadingcreator- theDynOCreatorto instantiate the business objectpoolKit- thePoolKit- Returns:
- the loaded business object instance
- Throws:
DAValidateException- if the item is not foundDAException- if a data access error occursoverit.geocall.asserts.AssertsException- if the givenDAOhas no sequence field configured
-
load
public static <T extends DynO> T load(Object id, Map<String, Object> filters, Class<? extends DAO> daoClass, Class<T> boClass, PoolKit poolKit) throws DAValidateException, DAExceptionLoads a business object by its primary key with additional visibility filters.- Type Parameters:
T- the type of business object to load- Parameters:
id- the primary key of the business object to loadfilters- the visibility filters to apply to the querydaoClass- theDAOclass to use for loadingboClass- theDynOextension class that implements the business objectpoolKit- thePoolKit- Returns:
- the loaded business object instance
- Throws:
DAValidateException- if the item is not found or more than one record is foundDAException- if a data access error occursoverit.geocall.asserts.AssertsException- if the givenDAOhas no sequence field configured
-
load
public static <T extends DynO> T load(Object id, Map<String, Object> filters, Class<? extends DAO> daoClass, DynOCreator<T> creator, PoolKit poolKit) throws DAValidateException, DAExceptionLoads a business object by its primary key with additional filters using a customDynOCreator.- Type Parameters:
T- the type of business object to load- Parameters:
id- the primary key of the business object to loadfilters- the visibility filters to apply to the querydaoClass- theDAOclass to use for loadingcreator- theDynOCreatorto instantiate the business objectpoolKit- thePoolKit- Returns:
- the loaded business object instance
- Throws:
DAValidateException- if the item is not found or more than one record is foundDAException- if a data access error occursoverit.geocall.asserts.AssertsException- if the givenDAOhas no sequence field configured
-
check
public static void check(Object id, Map<String, Object> filters, Class<? extends DAO> daoClass, PoolKit poolKit) throws DAValidateException, DAExceptionChecks if an entity exists with the given primary key and filters.- Parameters:
id- the primary key of the entity to checkfilters- the visibility filters to apply to the querydaoClass- theDAOclass to use for checkingpoolKit- thePoolKit- Throws:
DAValidateException- if the item is not found or more than one record is foundDAException- if a data access error occurs
-
search
public static <T extends DynO> PageResponse<T> search(Map<String, Object> filter, Class<? extends DAO> daoClass, Class<T> boClass, Page page, PoolKit poolKit) throws DAValidateException, DAExceptionSearches for business objects using filters and pagination.- Type Parameters:
T- the type of business objects to search for- Parameters:
filter- the search filters to applydaoClass- theDAOclass to use for searchingboClass- theDynOextension class that implements the business objectpage- the pagination parameterspoolKit- thePoolKit- Returns:
- a paginated response containing the search results
- Throws:
DAValidateException- if validation failsDAException- if a data access error occurs
-
search
public static <T extends DynO> PageResponse<T> search(Map<String, Object> filter, Class<? extends DAO> daoClass, DynOCreator<T> creator, Page page, PoolKit poolKit) throws DAValidateException, DAExceptionSearches for business objects using filters, pagination and a customDynOCreator.- Type Parameters:
T- the type of business objects to search for- Parameters:
filter- the search filters to applydaoClass- theDAOclass to use for searchingcreator- theDynOCreatorto instantiate business objectspage- the pagination parameterspoolKit- thePoolKit- Returns:
- a paginated response containing the search results
- Throws:
DAValidateException- if validation failsDAException- if a data access error occurs
-
search
public static <T extends DynO> PageResponse<T> search(Map<String, Object> filter, Order order, Class<? extends DAO> daoClass, Class<T> boClass, Page page, PoolKit poolKit) throws DAValidateException, DAExceptionSearches for business objects using filters, ordering and pagination.- Type Parameters:
T- the type of business objects to search for- Parameters:
filter- the search filters to applyorder- the ordering criteria for the resultsdaoClass- theDAOclass to use for searchingboClass- theDynOextension class that implements the business objectpage- the pagination parameterspoolKit- thePoolKit- Returns:
- a paginated response containing the search results
- Throws:
DAValidateException- if validation failsDAException- if a data access error occurs
-
search
public static <T extends DynO> PageResponse<T> search(Map<String, Object> filter, Order order, Class<? extends DAO> daoClass, DynOCreator<T> creator, Page page, PoolKit poolKit) throws DAValidateException, DAExceptionSearch method with full customization options including filters, ordering, pagination and custom creator.- Type Parameters:
T- the type of business objects to search for- Parameters:
filter- the search filters to applyorder- the ordering criteria for the resultsdaoClass- theDAOclass to use for searchingcreator- theDynOCreatorto instantiate business objectspage- the pagination parameterspoolKit- thePoolKit- Returns:
- a paginated response containing the search results
- Throws:
DAValidateException- if validation failsDAException- if a data access error occurs
-
buildSqlOrder
Builds SQL ORDER BY clause fromOrdercriteria.- Type Parameters:
T- the type of business objects- Parameters:
order- the ordering criteriacreator- theDynOCreatorto resolve field mappings- Returns:
- the SQL ORDER BY clause string
-
addTotalToResponse
Adds total count information to a paginated response if available.
This method checks if the query result contains a count field and adds the total count to the page response for pagination purposes.- Type Parameters:
T- the type of business objects in the response- Parameters:
result- the database query resultpageResponse- the paginated response to update
-
insert
public static <T extends DynO> Long insert(T dynO, Class<? extends DAO> daoClass, PoolKit poolKit) throws DAException, DAValidateException Inserts a new business object into the database.- Type Parameters:
T- the type of business object to insert- Parameters:
dynO- the business object to insertdaoClass- theDAOclass to use for insertionpoolKit- thePoolKit- Returns:
- the generated primary key of the inserted record
- Throws:
DAException- if a data access error occursDAValidateException- if validation fails
-
update
public static <T extends DynO> void update(T dynO, Class<? extends DAO> daoClass, PoolKit poolKit) throws DAException, DAValidateException Updates an existing business object in the database.- Type Parameters:
T- the type of business object to update- Parameters:
dynO- the business object to updatedaoClass- theDAOclass to use for updatingpoolKit- thePoolKit- Throws:
DAException- if a data access error occursDAValidateException- if validation fails or the record is not found
-
update
public static <T extends DynO> void update(T dynO, Class<? extends DAO> daoClass, Collection<String> excludedFields, PoolKit poolKit) throws DAException, DAValidateException Updates an existing business object in the database with field exclusions.- Type Parameters:
T- the type of business object to update- Parameters:
dynO- the business object to updatedaoClass- theDAOclass to use for updatingexcludedFields- the collection of field names to exclude from the updatepoolKit- thePoolKit- Throws:
DAException- if a data access error occursDAValidateException- if validation fails or the record is not found
-
delete
public static void delete(Object id, Class<? extends DAO> daoClass, PoolKit poolKit) throws DAValidateException, DAException Deletes an entity from the database by its primary key.- Parameters:
id- the primary key of the entity to deletedaoClass- theDAOclass to use for deletionpoolKit- thePoolKit- Throws:
DAValidateException- if the record is not foundDAException- if a data access error occurs
-
buildCountField
Builds a SQL count field with the default alias.- Returns:
- the SQL count field expression
-
buildCountField
Builds a SQL count expression with a custom alias.- Parameters:
alias- the alias for the count field- Returns:
- the SQL count expression
-
buildInClause
Builds a SQL IN clause for the specified field using values fromCommandContext.- Parameters:
field- the database field name to use in the IN clausecommandContext- the command context containing the parameter values- Returns:
- the SQL IN clause string
-
buildInClause
Builds a SQL IN clause with custom parameter and field names using values fromCommandContext.- Parameters:
parameter- the parameter name to look up in the command contextfield- the database field name to use in the IN clausecommandContext- the command context containing the parameter values- Returns:
- the SQL IN clause string
-
buildInClause
Builds a SQL IN clause with custom parameter and field names using the provided collection of values.- Parameters:
parameter- the parameter name to use in the IN clausefield- the database field name to use in the IN clausevalues- the collection of values to include in the IN clause- Returns:
- the SQL IN clause string
-
buildInClause
public static String buildInClause(String parameter, String field, Collection<?> values, boolean manageEmptyCollection) Builds a SQL IN clause with custom parameter and field names using the provided collection of values.- Parameters:
parameter- the parameter name to use in the IN clausefield- the database field name to use in the IN clausevalues- the collection of values to include in the IN clausemanageEmptyCollection- if true, returns " 1 = 0 " if the collection is empty- Returns:
- the SQL IN clause string
-
searchValidation
Validates the command type of the currentCommandContext. In search DAO only queries are admitted.- Parameters:
cc- theCommandContext- Throws:
DAValidateException
-
getBaseSearchFilterCriterion
@Deprecated(since="1.2", forRemoval=true) protected static List<Decision> getBaseSearchFilterCriterion()Deprecated, for removal: This API element is subject to removal in a future version.Retrieves the list of default decisions for search DAOs.- Returns:
- the list of default decisions
-
getBaseSearchFilterCriterion
Retrieves the list of default decisions for search DAOs.- Parameters:
cc- theCommandContextcontaining the parameters- Returns:
- the list of default decisions
-
getDefaultFilterCriterion
Deprecated, for removal: This API element is subject to removal in a future version.Retrieves the default filter criterion for search DAOs.- Returns:
- the default filter criterion
-
getDefaultFilterCriterion
Retrieves the default filter criterion for search DAOs.- Parameters:
cc- theCommandContextcontaining the parameters- Returns:
- the default filter criterion
-
getDefaultFilterCriterion
@Deprecated(since="1.2", forRemoval=true) public static Criteria getDefaultFilterCriterion(Decision... decisions) Deprecated, for removal: This API element is subject to removal in a future version.Retrieves the default filter criterion for search DAOs with additional custom decisions.- Parameters:
decisions- the custom decisions to add to the default filter criterion- Returns:
- the default filter criterion with custom decisions
-
getDefaultFilterCriterion
Retrieves the default filter criterion for search DAOs with additional custom decisions.- Parameters:
cc- theCommandContextcontaining the parametersdecisions- the custom decisions to add to the default filter criterion- Returns:
- the default filter criterion with custom decisions
-