Class QueryUtil<T>

  • Type Parameters:
    T - The type returned from the result processor

    public class QueryUtil<T>
    extends Object
    Simplifies querying by automatically enclosing queries in a result processing loop.

    This is copied from an older project. IIQ also provides a number of similar utilities in their JdbcUtil class.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  QueryUtil.ResultProcessor<U>
      Callback for processing the result
    • Constructor Summary

      Constructors 
      Constructor Description
      QueryUtil​(org.apache.commons.logging.Log Log)
      Constructor
      QueryUtil​(sailpoint.api.SailPointContext context, org.apache.commons.logging.Log log)
      Constructor
    • Constructor Detail

      • QueryUtil

        public QueryUtil​(org.apache.commons.logging.Log Log)
                  throws sailpoint.tools.GeneralException
        Constructor
        Parameters:
        Log - logger
        Throws:
        sailpoint.tools.GeneralException - if there is an error getting the current thread’s SailPoint context
      • QueryUtil

        public QueryUtil​(sailpoint.api.SailPointContext context,
                         org.apache.commons.logging.Log log)
        Constructor
        Parameters:
        context - The SailPoint context
        log - The logger
    • Method Detail

      • getLongValue

        public static Long getLongValue​(String query,
                                        String resultColumn,
                                        org.apache.commons.logging.Log Log,
                                        Object... parameters)
                                 throws Throwable
        Static helper method to retrieve the first value from the result set as a long
        Parameters:
        query - The query to run
        resultColumn - The column to grab from the results
        Log - logger
        parameters - Any parameters
        Returns:
        A list of result strings
        Throws:
        Throwable - On failures
      • getObjectByQuery

        public static <T extends sailpoint.object.SailPointObject> T getObjectByQuery​(sailpoint.api.SailPointContext context,
                                                                                      Class<T> cls,
                                                                                      String query,
                                                                                      org.apache.commons.logging.Log log,
                                                                                      Object... parameters)
                                                                               throws Throwable
        Retrieves the first string from the result set in the given column, then queries for a sailPoint object of the given type based on that name or ID.

        The column name is assumed to be ‘id’, which is the primary key in most of the SailPoint tables.

        Parameters:
        context - The Sailpoint context to use to query
        cls - The class to query based on the ID being pulled
        query - The query to run
        log - logger
        parameters - Any parameters
        Returns:
        A list of result strings
        Throws:
        Throwable - On failures
      • getObjectByQuery

        public static <T extends sailpoint.object.SailPointObject> T getObjectByQuery​(sailpoint.api.SailPointContext context,
                                                                                      Class<T> cls,
                                                                                      String query,
                                                                                      String idColumn,
                                                                                      org.apache.commons.logging.Log log,
                                                                                      Object... parameters)
                                                                               throws Throwable
        Retrieves the first string from the result set in the given column, then queries for a sailPoint object of the given type based on that name or ID.
        Parameters:
        context - The Sailpoint context to use to query
        cls - The class to query based on the ID being pulled
        query - The query to run
        idColumn - The column to grab from the results
        log - logger
        parameters - Any parameters
        Returns:
        A list of result strings
        Throws:
        Throwable - On failures
      • getStringList

        public static List<StringgetStringList​(String query,
                                                 String resultColumn,
                                                 org.apache.commons.logging.Log Log,
                                                 Object... parameters)
                                          throws Throwable
        Static helper method ot retrieve values from the query as a list of strings
        Parameters:
        query - The query to run
        resultColumn - The column to grab from the results
        Log - logger
        parameters - Any parameters
        Returns:
        A list of result strings
        Throws:
        Throwable - On failures
      • getStringValue

        public static String getStringValue​(String query,
                                            String resultColumn,
                                            org.apache.commons.logging.Log Log,
                                            Object... parameters)
                                     throws Throwable
        Static helper method to retrieve the first string value from the result set
        Parameters:
        query - The query to run
        resultColumn - The column to grab from the results
        Log - logger
        parameters - Any parameters
        Returns:
        A list of result strings
        Throws:
        Throwable - On failures
      • getUniqueObject

        public static <T extends sailpoint.object.SailPointObject> T getUniqueObject​(sailpoint.api.SailPointContext context,
                                                                                     Class<T> cls,
                                                                                     String filterString)
                                                                              throws sailpoint.tools.GeneralException
        Retrieves a unique object with the given Filter string
        Type Parameters:
        T - The type of the object to query
        Parameters:
        context - The Sailpoint Context
        cls - The class to query for
        filterString - The Filter string
        Returns:
        The queried object
        Throws:
        sailpoint.tools.GeneralException - if too many or too few objects are found
      • getUniqueObject

        public static <T extends sailpoint.object.SailPointObject> T getUniqueObject​(sailpoint.api.SailPointContext context,
                                                                                     Class<T> cls,
                                                                                     sailpoint.object.Filter filter)
                                                                              throws sailpoint.tools.GeneralException
        Retrieves a unique object with the given Filter string
        Type Parameters:
        T - The type of the object to query
        Parameters:
        context - The Sailpoint Context
        cls - The class to query for
        filter - a Filter object
        Returns:
        The queried object
        Throws:
        sailpoint.tools.GeneralException - if too many or too few objects are found
      • getUniqueObject

        public static <T extends sailpoint.object.SailPointObject> T getUniqueObject​(sailpoint.api.SailPointContext context,
                                                                                     Class<T> cls,
                                                                                     sailpoint.object.QueryOptions queryOptions)
                                                                              throws sailpoint.tools.ObjectNotFoundException,
                                                                                     sailpoint.tools.GeneralException
        Retrieves a unique object with the given Filter string
        Type Parameters:
        T - The type of the object to query
        Parameters:
        context - The Sailpoint Context
        cls - The class to query for
        queryOptions - a QueryOptions object which will be cloned before querying
        Returns:
        The queried object
        Throws:
        sailpoint.tools.ObjectNotFoundException - if no matches are found
        sailpoint.tools.GeneralException - if too many or too few objects are found
      • getResult

        public T getResult​(String query,
                           QueryUtil.ResultProcessor<? extends T> processor,
                           Object... parameters)
                    throws sailpoint.tools.GeneralException,
                           SQLException
        Parameters:
        query - The query to execute
        processor - The class to call for every iteration of the loop
        parameters - The parameters for the query, if any
        Returns:
        A list of results output by the ResultProcessor
        Throws:
        sailpoint.tools.GeneralException - on any Sailpoint failures
        SQLException - on any database failures
      • getResults

        public List<TgetResults​(String query,
                                  QueryUtil.ResultProcessor<? extends T> processor,
                                  Object... parameters)
                           throws sailpoint.tools.GeneralException,
                                  SQLException
        Parameters:
        query - The query to execute
        processor - The class to call for every iteration of the loop
        parameters - The parameters for the query, if any
        Returns:
        A list of results output by the ResultProcessor
        Throws:
        sailpoint.tools.GeneralException - on any Sailpoint failures
        SQLException - on any database failures
      • iterateQuery

        public void iterateQuery​(IterateQueryOptions inputs)
                          throws sailpoint.tools.GeneralException
        Iterates a query by invoking a Beanshell callback for each method
        Parameters:
        inputs - The inputs
        Throws:
        sailpoint.tools.GeneralException - if anything goes wrong
      • parallelIterateQuery

        public PooledWorkerResults<Map<String,​Object>> parallelIterateQuery​(IterateQueryOptions inputs,
                                                                                  int threads)
                                                                           throws sailpoint.tools.GeneralException
        Iterates over a query in parallel, making a call to the defined callback in the input options.

        (NOTE: Beanshell is explicitly thread-safe, but you should use the thread context provided and you should not access shared resources without doing your own thread-safety stuff.)

        Parameters:
        inputs - The input options
        threads - The number of threads to use
        Throws:
        sailpoint.tools.GeneralException - if anything fails
      • update

        public int update​(String query,
                          Object... parameters)
                   throws Exception
        Run an update statement against the database directly (use sparingly)
        Parameters:
        query - The query to execute
        parameters - The parameters to include in the query
        Returns:
        The return from executeUpdate()
        Throws:
        Exception - On failures