com.ibm.tivoli.maximo.dbmanage

Class SQLUtility

  • java.lang.Object
    • com.ibm.tivoli.maximo.dbmanage.SQLUtility


  • public class SQLUtility
    extends java.lang.Object
    Helper methods for working with connections.
    • Constructor Summary

      Constructors 
      Constructor and Description
      SQLUtility() 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static void doCall(java.sql.Connection con, java.lang.String call)
      Perform a call.
      static void doSql(java.sql.Connection con, java.util.List sqlList)
      Execute SQL
      static void doSql(java.sql.Connection con, java.util.List sqlList, boolean ignoreError)
      Execute a number of lines of SQL, with option of suppressing an error thrown.
      static int doSql(java.sql.Connection dc, SQLSpecificTransform transform, java.lang.String sql)
      Transform the SQL and then perform it.
      static void doSql(java.sql.Connection dc, SQLSpecificTransform sqlTransform, java.lang.String[] sql)
      Execute a group of SQL statements.
      static int doSql(java.sql.Connection con, java.lang.String sql)
      Execute SQL
      static int doSql(java.sql.Connection con, java.lang.String sql, boolean ignoreError)
      Execute a single line of SQL, with option of suppressing an error thrown.
      static int doSql(java.sql.Connection con, java.lang.String sql, java.lang.String[] params)
      Execute SQL with string parameters.
      static boolean exists(java.sql.Connection dc, java.lang.String query)
      Returns if any rows were selected by the query.
      static boolean existsPs(java.sql.Connection dc, java.lang.String query, java.lang.String[] params)
      Returns if any rows were selected by the query.
      static java.util.List listAllStrings(java.sql.Connection dc, java.lang.String query)
      Returns all strings for the first column value returned.
      static java.lang.String printQuery(java.sql.Connection dc, java.lang.String query) 
      static java.util.List selectAll(java.sql.Connection dc, java.lang.String query, AttributeStorageDefinition retStoreDef)
      Select data from all rows.
      static AttributeStorage selectFirst(java.sql.Connection con, java.lang.String query, AttributeStorageDefinition asd)
      Get data for the first row only.
      static java.lang.Boolean selectFirstBoolean(java.sql.Connection con, java.lang.String query)
      Select the value as a Boolean, using the Maximo YORN definition, where 1 is true and 0 is false.
      static java.lang.Double selectFirstDouble(java.sql.Connection con, java.lang.String query)
      Select the value as a Double.
      static java.lang.Integer selectFirstInteger(java.sql.Connection con, java.lang.String query)
      Select the value as an Integer.
      static java.lang.Long selectFirstLong(java.sql.Connection con, java.lang.String query)
      Select the value as a Long.
      static java.lang.String selectFirstString(java.sql.Connection dc, java.lang.String query)
      Select the value as a string.
      static java.lang.String selectFirstStringPs(java.sql.Connection dc, java.lang.String query, java.lang.String[] params)
      Select the value as a string.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SQLUtility

        public SQLUtility()
    • Method Detail

      • selectFirstString

        public static java.lang.String selectFirstString(java.sql.Connection dc,
                                                         java.lang.String query)
                                                  throws java.sql.SQLException
        Select the value as a string.
        Parameters:
        dc - The connection to query.
        query - The query
        Returns:
        The first column as a string, or null if no rows found.
        Throws:
        java.sql.SQLException
      • selectFirstStringPs

        public static java.lang.String selectFirstStringPs(java.sql.Connection dc,
                                                           java.lang.String query,
                                                           java.lang.String[] params)
                                                    throws java.sql.SQLException
        Select the value as a string.
        Parameters:
        dc - The connection to query.
        query - The query
        params - Optional string parameters
        Returns:
        The first column as a string, or null if no rows found.
        Throws:
        java.sql.SQLException
      • listAllStrings

        public static java.util.List listAllStrings(java.sql.Connection dc,
                                                    java.lang.String query)
                                             throws java.sql.SQLException
        Returns all strings for the first column value returned.
        Parameters:
        dc - The connection to query.
        query - The query
        Returns:
        Always returns a list, but it may be empty.
        Throws:
        java.sql.SQLException
      • doSql

        public static int doSql(java.sql.Connection con,
                                java.lang.String sql,
                                boolean ignoreError)
                         throws java.sql.SQLException
        Execute a single line of SQL, with option of suppressing an error thrown.
        Parameters:
        con - The connection to use.
        sql - The SQL statement to execute.
        ignoreError - If true, any SQL exception will be caught and ignored.
        Returns:
        the current result as an update count; -1 if the current result is a ResultSet object or there are no more results
        Throws:
        java.sql.SQLException
      • selectFirstInteger

        public static java.lang.Integer selectFirstInteger(java.sql.Connection con,
                                                           java.lang.String query)
                                                    throws java.sql.SQLException
        Select the value as an Integer.
        Parameters:
        dc - The connection to query.
        query - The query
        Returns:
        The first column as an Integer, or null if no rows found.
        Throws:
        java.sql.SQLException
      • exists

        public static boolean exists(java.sql.Connection dc,
                                     java.lang.String query)
                              throws java.sql.SQLException
        Returns if any rows were selected by the query.
        Parameters:
        dc - The connection
        query - The SQL query
        Returns:
        true if any rows are returned.
        Throws:
        java.sql.SQLException
      • existsPs

        public static boolean existsPs(java.sql.Connection dc,
                                       java.lang.String query,
                                       java.lang.String[] params)
                                throws java.sql.SQLException
        Returns if any rows were selected by the query.
        Parameters:
        dc - The connection
        query - The SQL query
        params - Values for replacement, optional, note that they are Strings.
        Returns:
        true if any rows are returned.
        Throws:
        java.sql.SQLException
      • selectAll

        public static java.util.List selectAll(java.sql.Connection dc,
                                               java.lang.String query,
                                               AttributeStorageDefinition retStoreDef)
                                        throws java.sql.SQLException
        Select data from all rows.
        Parameters:
        dc -
        query -
        retStoreDef -
        Returns:
        A list is always returned, although it may be empty.
        Throws:
        java.sql.SQLException
      • doSql

        public static void doSql(java.sql.Connection con,
                                 java.util.List sqlList,
                                 boolean ignoreError)
                          throws java.sql.SQLException
        Execute a number of lines of SQL, with option of suppressing an error thrown.
        Parameters:
        con - The connection to use.
        sqlList - The SQL statements to execute.
        ignoreError - If true, any SQL exception will be caught and ignored.
        Throws:
        java.sql.SQLException
      • doSql

        public static void doSql(java.sql.Connection con,
                                 java.util.List sqlList)
                          throws java.sql.SQLException
        Execute SQL
        Parameters:
        con -
        sqlList -
        Throws:
        java.lang.Exception
        java.sql.SQLException
      • doSql

        public static int doSql(java.sql.Connection con,
                                java.lang.String sql)
                         throws java.sql.SQLException
        Execute SQL
        Parameters:
        con -
        sqlList -
        Returns:
        the current result as an update count; -1 if the current result is a ResultSet object or there are no more results
        Throws:
        java.sql.SQLException
      • doSql

        public static int doSql(java.sql.Connection con,
                                java.lang.String sql,
                                java.lang.String[] params)
                         throws java.sql.SQLException
        Execute SQL with string parameters.
        Parameters:
        con -
        sql -
        params -
        Throws:
        java.sql.SQLException
      • selectFirst

        public static AttributeStorage selectFirst(java.sql.Connection con,
                                                   java.lang.String query,
                                                   AttributeStorageDefinition asd)
                                            throws java.sql.SQLException
        Get data for the first row only.
        Parameters:
        con -
        query -
        asd -
        Returns:
        Throws:
        java.sql.SQLException
      • selectFirstBoolean

        public static java.lang.Boolean selectFirstBoolean(java.sql.Connection con,
                                                           java.lang.String query)
                                                    throws java.sql.SQLException
        Select the value as a Boolean, using the Maximo YORN definition, where 1 is true and 0 is false.
        Parameters:
        dc - The connection to query.
        query - The query
        Returns:
        The first column as a Boolean, or null if no rows found.
        Throws:
        java.sql.SQLException
      • doSql

        public static int doSql(java.sql.Connection dc,
                                SQLSpecificTransform transform,
                                java.lang.String sql)
                         throws java.sql.SQLException
        Transform the SQL and then perform it.
        Parameters:
        dc -
        sqlTransform -
        string -
        Throws:
        java.sql.SQLException
      • selectFirstLong

        public static java.lang.Long selectFirstLong(java.sql.Connection con,
                                                     java.lang.String query)
                                              throws java.sql.SQLException
        Select the value as a Long.
        Parameters:
        con - The connection to query.
        query - The query
        Returns:
        The first column as a Long, or null if no rows found.
        Throws:
        java.sql.SQLException
      • doSql

        public static void doSql(java.sql.Connection dc,
                                 SQLSpecificTransform sqlTransform,
                                 java.lang.String[] sql)
                          throws java.sql.SQLException
        Execute a group of SQL statements.
        Parameters:
        dc -
        sqlTransform -
        sql -
        Throws:
        java.lang.Exception
        java.sql.SQLException
      • doCall

        public static void doCall(java.sql.Connection con,
                                  java.lang.String call)
                           throws java.sql.SQLException
        Perform a call.
        Parameters:
        con - Connection
        call - Call statement
        Throws:
        java.sql.SQLException
      • selectFirstDouble

        public static java.lang.Double selectFirstDouble(java.sql.Connection con,
                                                         java.lang.String query)
                                                  throws java.sql.SQLException
        Select the value as a Double.
        Parameters:
        con - The connection to query.
        query - The query
        Returns:
        The first column, in the first row returned, as a Double, or null if no rows found.
        Throws:
        java.sql.SQLException
      • printQuery

        public static java.lang.String printQuery(java.sql.Connection dc,
                                                  java.lang.String query)
                                           throws java.sql.SQLException
        Throws:
        java.sql.SQLException