Class DAOUtils

java.lang.Object
overit.geocallapp.utilities.core.data.DAOUtils

public class DAOUtils extends Object
Utility class providing common operations for DAO interactions and business object management.
Since:
1.0
  • Field Details

  • 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 specified DAO and business object class.
      Type Parameters:
      T - the type of business object to load
      Parameters:
      id - the primary key of the business object to load
      daoClass - the DAO class to use for loading
      boClass - the DynO extension class that implements the business object
      poolKit - the PoolKit
      Returns:
      the loaded business object instance
      Throws:
      DAValidateException - if the item is not found
      DAException - if a data access error occurs
      overit.geocall.asserts.AssertsException - if the given DAO has 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 custom DynOCreator.
      Type Parameters:
      T - the type of business object to load
      Parameters:
      id - the primary key of the business object to load
      daoClass - the DAO class to use for loading
      creator - the DynOCreator to instantiate the business object
      poolKit - the PoolKit
      Returns:
      the loaded business object instance
      Throws:
      DAValidateException - if the item is not found
      DAException - if a data access error occurs
      overit.geocall.asserts.AssertsException - if the given DAO has 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, DAException
      Loads 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 load
      filters - the visibility filters to apply to the query
      daoClass - the DAO class to use for loading
      boClass - the DynO extension class that implements the business object
      poolKit - the PoolKit
      Returns:
      the loaded business object instance
      Throws:
      DAValidateException - if the item is not found or more than one record is found
      DAException - if a data access error occurs
      overit.geocall.asserts.AssertsException - if the given DAO has 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, DAException
      Loads a business object by its primary key with additional filters using a custom DynOCreator.
      Type Parameters:
      T - the type of business object to load
      Parameters:
      id - the primary key of the business object to load
      filters - the visibility filters to apply to the query
      daoClass - the DAO class to use for loading
      creator - the DynOCreator to instantiate the business object
      poolKit - the PoolKit
      Returns:
      the loaded business object instance
      Throws:
      DAValidateException - if the item is not found or more than one record is found
      DAException - if a data access error occurs
      overit.geocall.asserts.AssertsException - if the given DAO has no sequence field configured
    • check

      public static void check(Object id, Map<String,Object> filters, Class<? extends DAO> daoClass, PoolKit poolKit) throws DAValidateException, DAException
      Checks if an entity exists with the given primary key and filters.
      Parameters:
      id - the primary key of the entity to check
      filters - the visibility filters to apply to the query
      daoClass - the DAO class to use for checking
      poolKit - the PoolKit
      Throws:
      DAValidateException - if the item is not found or more than one record is found
      DAException - 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, DAException
      Searches for business objects using filters and pagination.
      Type Parameters:
      T - the type of business objects to search for
      Parameters:
      filter - the search filters to apply
      daoClass - the DAO class to use for searching
      boClass - the DynO extension class that implements the business object
      page - the pagination parameters
      poolKit - the PoolKit
      Returns:
      a paginated response containing the search results
      Throws:
      DAValidateException - if validation fails
      DAException - 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, DAException
      Searches for business objects using filters, pagination and a custom DynOCreator.
      Type Parameters:
      T - the type of business objects to search for
      Parameters:
      filter - the search filters to apply
      daoClass - the DAO class to use for searching
      creator - the DynOCreator to instantiate business objects
      page - the pagination parameters
      poolKit - the PoolKit
      Returns:
      a paginated response containing the search results
      Throws:
      DAValidateException - if validation fails
      DAException - 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, DAException
      Searches 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 apply
      order - the ordering criteria for the results
      daoClass - the DAO class to use for searching
      boClass - the DynO extension class that implements the business object
      page - the pagination parameters
      poolKit - the PoolKit
      Returns:
      a paginated response containing the search results
      Throws:
      DAValidateException - if validation fails
      DAException - 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, DAException
      Search 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 apply
      order - the ordering criteria for the results
      daoClass - the DAO class to use for searching
      creator - the DynOCreator to instantiate business objects
      page - the pagination parameters
      poolKit - the PoolKit
      Returns:
      a paginated response containing the search results
      Throws:
      DAValidateException - if validation fails
      DAException - if a data access error occurs
    • buildSqlOrder

      public static <T extends DynO> String buildSqlOrder(Order order, DynOCreator<T> creator)
      Builds SQL ORDER BY clause from Order criteria.
      Type Parameters:
      T - the type of business objects
      Parameters:
      order - the ordering criteria
      creator - the DynOCreator to resolve field mappings
      Returns:
      the SQL ORDER BY clause string
    • addTotalToResponse

      public static <T extends DynO> void addTotalToResponse(DBView result, PageResponse<T> pageResponse)
      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 result
      pageResponse - 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 insert
      daoClass - the DAO class to use for insertion
      poolKit - the PoolKit
      Returns:
      the generated primary key of the inserted record
      Throws:
      DAException - if a data access error occurs
      DAValidateException - 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 update
      daoClass - the DAO class to use for updating
      poolKit - the PoolKit
      Throws:
      DAException - if a data access error occurs
      DAValidateException - 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 update
      daoClass - the DAO class to use for updating
      excludedFields - the collection of field names to exclude from the update
      poolKit - the PoolKit
      Throws:
      DAException - if a data access error occurs
      DAValidateException - 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 delete
      daoClass - the DAO class to use for deletion
      poolKit - the PoolKit
      Throws:
      DAValidateException - if the record is not found
      DAException - if a data access error occurs
    • buildCountField

      public static String buildCountField()
      Builds a SQL count field with the default alias.
      Returns:
      the SQL count field expression
    • buildCountField

      public static String buildCountField(String alias)
      Builds a SQL count expression with a custom alias.
      Parameters:
      alias - the alias for the count field
      Returns:
      the SQL count expression
    • buildInClause

      public static String buildInClause(String field, CommandContext commandContext)
      Builds a SQL IN clause for the specified field using values from CommandContext.
      Parameters:
      field - the database field name to use in the IN clause
      commandContext - the command context containing the parameter values
      Returns:
      the SQL IN clause string
    • buildInClause

      public static String buildInClause(String parameter, String field, CommandContext commandContext)
      Builds a SQL IN clause with custom parameter and field names using values from CommandContext.
      Parameters:
      parameter - the parameter name to look up in the command context
      field - the database field name to use in the IN clause
      commandContext - the command context containing the parameter values
      Returns:
      the SQL IN clause string
    • buildInClause

      public static String buildInClause(String parameter, String field, Collection<?> values)
      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 clause
      field - the database field name to use in the IN clause
      values - 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 clause
      field - the database field name to use in the IN clause
      values - the collection of values to include in the IN clause
      manageEmptyCollection - if true, returns " 1 = 0 " if the collection is empty
      Returns:
      the SQL IN clause string
    • searchValidation

      public static void searchValidation(CommandContext cc) throws DAValidateException
      Validates the command type of the current CommandContext. In search DAO only queries are admitted.
      Parameters:
      cc - the CommandContext
      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

      protected static List<Decision> getBaseSearchFilterCriterion(CommandContext cc)
      Retrieves the list of default decisions for search DAOs.
      Parameters:
      cc - the CommandContext containing the parameters
      Returns:
      the list of default decisions
    • getDefaultFilterCriterion

      @Deprecated(since="1.2", forRemoval=true) public static Criteria 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

      public static Criteria getDefaultFilterCriterion(CommandContext cc)
      Retrieves the default filter criterion for search DAOs.
      Parameters:
      cc - the CommandContext containing 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

      public static Criteria getDefaultFilterCriterion(CommandContext cc, Decision... decisions)
      Retrieves the default filter criterion for search DAOs with additional custom decisions.
      Parameters:
      cc - the CommandContext containing the parameters
      decisions - the custom decisions to add to the default filter criterion
      Returns:
      the default filter criterion with custom decisions