Interface QueryManagerService


  • public interface QueryManagerService
    This interface represents query manager services. A query manager service implements generic query execution methods for ease of development only.

    Note: The QueryResult instances that some of this class's methods return load the complete query result in memory. These methods should thus not be used for queries that potentially return large result sets because that might cause an OutOfMemoryException.

    Author:
    ivol
    • Method Detail

      • getDataSourceById

        DataSource getDataSourceById​(String dbId)
                              throws SQLException
        Returns the datasource by the given database id. It will retrieve the datasource name from the configuration management service and the database id provided should equal the name of the parameter under which the full datasource name is stored. It is recommended to use the predefined database ids in this interface. For example: getDataSourceById(QueryManagerService.WEBADMIN_DBID);
        Parameters:
        dbId - Database id of which the datasource should be retrieved
        Returns:
        The datasource for the given database id
        Throws:
        SQLException - in case an error occurred while retrieving the datasource
      • getDataSourceByName

        DataSource getDataSourceByName​(String fullDataSourceName)
                                throws SQLException
        Returns the datasource by the given full datasource name.
        Parameters:
        fullDataSourceName - Datasource name of the datasource to retrieve
        Returns:
        Datasource for the given DataSource name
        Throws:
        SQLException - in case an error occurred while retrieving the datasource
      • executeSelect

        QueryResult executeSelect​(DataSource datasource,
                                  String statement,
                                  Object[] args)
                           throws SQLException
        Performs a select query and returns the result.
        Parameters:
        datasource - Datasource to execute the query on
        statement - Statement to execute. Recommended is to use prepared statements.
        args - Input arguments of the statement in case of prepared statements.
        Returns:
        The results of the query QueryResult object.
        Throws:
        SQLException - If a SQL exception occurred
      • executeUpdate

        int executeUpdate​(DataSource datasource,
                          String statement,
                          Object[] args)
                   throws SQLException
        Executes a SQL statement that must be either a INSERT, UPDATE or DELETE statement
        Parameters:
        datasource - Datasource to execute the stored procedure on
        procedure - Stored procedure to execute.
        args - Input arguments of the stored procedure.
        Returns:
        either (1) the row count for INSERT, UPDATE, or DELETE statements or (2) 0 for SQL statements that return nothing
        Throws:
        SQLException - If a SQL exception occurred
      • executeStoredProcedure

        boolean executeStoredProcedure​(DataSource datasource,
                                       String procedure,
                                       Object[] args)
                                throws SQLException
        Execute any stored procedure
        Parameters:
        datasource - Datasource to execute the stored procedure on
        procedure - Stored procedure to execute.
        args - Input arguments of the stored procedure.
        Returns:
        The execute method returns a boolean to indicate the form of the first result.
        Throws:
        SQLException - If a SQL exception occurred
      • callStoredProcedure

        QueryResult callStoredProcedure​(DataSource datasource,
                                        String procedure,
                                        Object[] args)
                                 throws SQLException
        Performs a stored procedure and returns the result.
        Parameters:
        datasource - Datasource to execute the stored procedure on
        procedure - Stored procedure to execute.
        args - Input arguments of the stored procedure.
        Returns:
        The results of the query QueryResult object.
        Throws:
        SQLException - If a SQL exception occurred
      • getAsInt

        int getAsInt​(Object object)
        Returns an object that was returned as result of a query as an Integer. This is necessary for the generic executeSelect since a getObject on a number result in oracle does not return an Integer but a BigDecimal
        Parameters:
        object - Object of the result query to be converted to an Integer
        Returns:
        Value of the object as Integer
        Throws:
        IllegalArgumentException - if the object is not an Integer, BigInteger or BigDecimal