Class DBUtils


  • public final class DBUtils
    extends java.lang.Object
    Class collecting a few generic static utility methods mostly related to SQL generation.
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static int compareTwoStringVersions​(java.lang.String versionA, java.lang.String versionB)
      Compares two version strings, ie.
      static org.springframework.jdbc.core.PreparedStatementCreator createPreparedStatementCreator​(java.lang.String sql, int fetchSize)
      Creates a PreparedStatementCreator for a SQL statement and a fetch size.
      static org.springframework.jdbc.core.PreparedStatementCreator createPreparedStatementCreator​(java.lang.String sql, DBType dbType)
      Creates a PreparedStatementCreator for a SQL statement and a database type.
      static java.lang.String findStringNotPresent​(java.util.List<java.lang.String> values)
      Gets a character that is not contained in any of the values.
      static java.lang.String getIdentifierQuoteString​(javax.sql.DataSource ds)  
      static java.util.List<java.util.UUID> getUUIDsFromParams​(java.lang.Object[] params)
      Used for getting usrOpId UUID from JChemSearchOptions string representation.
      static java.lang.String join​(java.lang.Object[] values, java.lang.String separator)
      Deprecated.
      5.12 Use Joiner instead.
      static void join​(java.lang.StringBuilder buf, java.lang.Object[] values, java.lang.String separator)
      Deprecated.
      5.12 Use Joiner instead.
      static java.lang.String join​(java.util.Collection<?> values, java.lang.String separator)
      Deprecated.
      5.12 Use Joiner instead.
      static java.lang.String repeat​(java.lang.String val, java.lang.String sep, int count)  
      static java.lang.String stripParenthesis​(java.lang.String txt)
      Strips the parenthesis "()" from a string.
      static java.lang.String stripQuotes​(java.lang.String txt)
      Strips the quotes (' or ") from a string.
      • Methods inherited from class java.lang.Object

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

      • repeat

        public static java.lang.String repeat​(java.lang.String val,
                                              java.lang.String sep,
                                              int count)
      • join

        @Deprecated
        public static java.lang.String join​(java.util.Collection<?> values,
                                            java.lang.String separator)
        Deprecated.
        5.12 Use Joiner instead.
        Concatenates a collection of values into a string.
        Parameters:
        values - Values to concatenate.
        separator - The separator to use.
        Returns:
        A String with all values concatenated and separated by the separator.
      • join

        @Deprecated
        public static void join​(java.lang.StringBuilder buf,
                                java.lang.Object[] values,
                                java.lang.String separator)
        Deprecated.
        5.12 Use Joiner instead.
        Concatenates an array of values into a StringBuilder.
        Parameters:
        buf - The StringBuilder to receive the concatenated values.
        values - Values to concatenate.
        separator - The separator to use.
      • join

        @Deprecated
        public static java.lang.String join​(java.lang.Object[] values,
                                            java.lang.String separator)
        Deprecated.
        5.12 Use Joiner instead.
        Concatenates an array of values into a string.
        Parameters:
        values - Values to concatenate.
        separator - The separator to use.
        Returns:
        A String with all values concatenated and separated by the separator.
      • stripQuotes

        public static java.lang.String stripQuotes​(java.lang.String txt)
        Strips the quotes (' or ") from a string. For example converts 'hello' to hello. The string consisting from only two quote characters (eg. '' or "") is left untouched. Empty or null} strings are left untouched too.
        Parameters:
        txt - The string to remove quotes from. Can be null or empty.
        Returns:
        The string with the starting and ending quote removed.
      • stripParenthesis

        public static java.lang.String stripParenthesis​(java.lang.String txt)
        Strips the parenthesis "()" from a string. For example converts ((hello)) to hello.
        Parameters:
        txt - The string to remove parenthesis from.
        Returns:
        The string with the starting and ending parenthesis removed. The string containing just "()" is left untouched.
      • findStringNotPresent

        public static java.lang.String findStringNotPresent​(java.util.List<java.lang.String> values)
        Gets a character that is not contained in any of the values.
        Parameters:
        values - The list of string to check.
        Returns:
        One of the ,!#^*%@~`_£\\/?$¬;|&.
      • createPreparedStatementCreator

        public static org.springframework.jdbc.core.PreparedStatementCreator createPreparedStatementCreator​(java.lang.String sql,
                                                                                                            int fetchSize)
        Creates a PreparedStatementCreator for a SQL statement and a fetch size.
        Parameters:
        sql - The sql statement to use.
        fetchSize - The JDBC fetch size. See Statement.setFetchSize(int)
        Returns:
        The PreparedStatementCreator instance.
      • createPreparedStatementCreator

        public static org.springframework.jdbc.core.PreparedStatementCreator createPreparedStatementCreator​(java.lang.String sql,
                                                                                                            DBType dbType)
        Creates a PreparedStatementCreator for a SQL statement and a database type. It determines the optimal fetchsize from DBType.getPreferedFetchSize().
        Parameters:
        sql - The sql statement to use.
        dbType - The database type.
        Returns:
        The PreparedStatementCreator instance.
      • compareTwoStringVersions

        public static int compareTwoStringVersions​(java.lang.String versionA,
                                                   java.lang.String versionB)
        Compares two version strings, ie. 5.5.0 and 5.7.1.
        Parameters:
        versionA - first version to compare
        versionB - second version to compare
        Returns:
        1 if versionA is greater than versionB, -1 if opposite, 0 if equal.
      • getUUIDsFromParams

        public static java.util.List<java.util.UUID> getUUIDsFromParams​(java.lang.Object[] params)
        Used for getting usrOpId UUID from JChemSearchOptions string representation.
        Parameters:
        params - takes an Object array as input
        Returns:
        list of UUIDs if found between params
      • getIdentifierQuoteString

        public static java.lang.String getIdentifierQuoteString​(javax.sql.DataSource ds)
                                                         throws org.springframework.jdbc.support.MetaDataAccessException
        Parameters:
        ds - dataSaurce to get db-specific quote string from
        Returns:
        valid identifier quote string suitable for escaping DB tables, schemas etc.
        Throws:
        org.springframework.jdbc.support.MetaDataAccessException - if metadata access failed, no likely