Class QueryUtil<T>
- java.lang.Object
-
- com.identityworksllc.iiq.common.query.QueryUtil<T>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
QueryUtil.ResultProcessor<U>
Callback for processing the result
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Long
getLongValue(String query, String resultColumn, org.apache.commons.logging.Log Log, Object... parameters)
Static helper method to retrieve the first value from the result set as a longstatic <T extends sailpoint.object.SailPointObject>
TgetObjectByQuery(sailpoint.api.SailPointContext context, Class<T> cls, String query, String idColumn, org.apache.commons.logging.Log log, Object... parameters)
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.static <T extends sailpoint.object.SailPointObject>
TgetObjectByQuery(sailpoint.api.SailPointContext context, Class<T> cls, String query, org.apache.commons.logging.Log log, Object... parameters)
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.T
getResult(String query, QueryUtil.ResultProcessor<? extends T> processor, Object... parameters)
List<T>
getResults(String query, QueryUtil.ResultProcessor<? extends T> processor, Object... parameters)
static List<String>
getStringList(String query, String resultColumn, org.apache.commons.logging.Log Log, Object... parameters)
Static helper method ot retrieve values from the query as a list of stringsstatic String
getStringValue(String query, String resultColumn, org.apache.commons.logging.Log Log, Object... parameters)
Static helper method to retrieve the first string value from the result setstatic <T extends sailpoint.object.SailPointObject>
TgetUniqueObject(sailpoint.api.SailPointContext context, Class<T> cls, String filterString)
Retrieves a unique object with the given Filter stringstatic <T extends sailpoint.object.SailPointObject>
TgetUniqueObject(sailpoint.api.SailPointContext context, Class<T> cls, sailpoint.object.Filter filter)
Retrieves a unique object with the given Filter stringstatic <T extends sailpoint.object.SailPointObject>
TgetUniqueObject(sailpoint.api.SailPointContext context, Class<T> cls, sailpoint.object.QueryOptions queryOptions)
Retrieves a unique object with the given Filter stringvoid
iterateQuery(IterateQueryOptions inputs)
Iterates a query by invoking a Beanshell callback for each methodPooledWorkerResults<Map<String,Object>>
parallelIterateQuery(IterateQueryOptions inputs, int threads)
Iterates over a query in parallel, making a call to the defined callback in the input options.static void
setupParameters(PreparedStatement stmt, Object[] parameters)
Set up the given parameters in the prepared statmeentint
update(String query, Object... parameters)
Run an update statement against the database directly (use sparingly)
-
-
-
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 contextlog
- 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 runresultColumn
- The column to grab from the resultsLog
- loggerparameters
- 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 querycls
- The class to query based on the ID being pulledquery
- The query to runlog
- loggerparameters
- 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 querycls
- The class to query based on the ID being pulledquery
- The query to runidColumn
- The column to grab from the resultslog
- loggerparameters
- Any parameters- Returns:
- A list of result strings
- Throws:
Throwable
- On failures
-
getStringList
public static List<String> getStringList(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 runresultColumn
- The column to grab from the resultsLog
- loggerparameters
- 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 runresultColumn
- The column to grab from the resultsLog
- loggerparameters
- 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 Contextcls
- The class to query forfilterString
- 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 Contextcls
- The class to query forfilter
- 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 Contextcls
- The class to query forqueryOptions
- a QueryOptions object which will be cloned before querying- Returns:
- The queried object
- Throws:
sailpoint.tools.ObjectNotFoundException
- if no matches are foundsailpoint.tools.GeneralException
- if too many or too few objects are found
-
setupParameters
public static void setupParameters(PreparedStatement stmt, Object[] parameters) throws SQLException
Set up the given parameters in the prepared statmeent- Parameters:
stmt
- The statementparameters
- The parameters- Throws:
SQLException
- if any failures occur setting parameters
-
getResult
public T getResult(String query, QueryUtil.ResultProcessor<? extends T> processor, Object... parameters) throws sailpoint.tools.GeneralException, SQLException
- Parameters:
query
- The query to executeprocessor
- The class to call for every iteration of the loopparameters
- The parameters for the query, if any- Returns:
- A list of results output by the ResultProcessor
- Throws:
sailpoint.tools.GeneralException
- on any Sailpoint failuresSQLException
- on any database failures
-
getResults
public List<T> getResults(String query, QueryUtil.ResultProcessor<? extends T> processor, Object... parameters) throws sailpoint.tools.GeneralException, SQLException
- Parameters:
query
- The query to executeprocessor
- The class to call for every iteration of the loopparameters
- The parameters for the query, if any- Returns:
- A list of results output by the ResultProcessor
- Throws:
sailpoint.tools.GeneralException
- on any Sailpoint failuresSQLException
- 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 optionsthreads
- 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 executeparameters
- The parameters to include in the query- Returns:
- The return from executeUpdate()
- Throws:
Exception
- On failures
-
-