Class RDBJDBCTools


  • public class RDBJDBCTools
    extends Object
    Convenience methods dealing with JDBC specifics.
    • Field Detail

      • MAX_IN_CLAUSE

        public static final int MAX_IN_CLAUSE
    • Constructor Detail

      • RDBJDBCTools

        public RDBJDBCTools()
    • Method Detail

      • jdbctype

        protected static String jdbctype​(String jdbcurl)
      • driverForDBType

        protected static String driverForDBType​(String type)
      • isolationLevelToString

        @NotNull
        protected static @NotNull String isolationLevelToString​(int isolationLevel)
        Return string representation of transaction isolation level.
      • dumpResultSetMeta

        protected static String dumpResultSetMeta​(ResultSetMetaData met)
        Return approximated string representation of table DDL.
      • getAdditionalMessages

        @NotNull
        protected static @NotNull String getAdditionalMessages​(SQLException ex)
        Return a string containing additional messages from chained exceptions.
      • matchesSQLState

        protected static boolean matchesSQLState​(SQLException ex,
                                                 String... statePrefix)
        Check whether the exception matches one of the given states.
      • versionCheck

        protected static String versionCheck​(DatabaseMetaData md,
                                             int dbmax,
                                             int dbmin,
                                             int drmax,
                                             int drmin,
                                             String dbname)
                                      throws SQLException
        Generate database + driver version diagnostics.
        Parameters:
        md - metadata object
        dbmax - minimal DB major version number (where -1 disables the check)
        dbmin - minimal DB minor version number
        drmax - minimal driver major version number (where -1 disables the check)
        drmin - minimal driver minor version number
        dbname - database type
        Returns:
        diagnostics (empty when there's nothing to complain about)
        Throws:
        SQLException
      • versionCheck

        protected static String versionCheck​(DatabaseMetaData md,
                                             int dbmax,
                                             int dbmin,
                                             String dbname)
                                      throws SQLException
        Generate database version diagnostics.
        Parameters:
        md - metadata object
        dbmax - minimal DB major version number (where -1 disables the check)
        dbmin - minimal DB minor version number
        dbname - database type
        Returns:
        diagnostics (empty when there's nothing to complain about)
        Throws:
        SQLException
      • closeStatement

        protected static <T extends Statement> T closeStatement​(@Nullable
                                                                T stmt)
        Closes a Statement, logging potential problems.
        Returns:
        null
      • closeResultSet

        protected static ResultSet closeResultSet​(@Nullable
                                                  @Nullable ResultSet rs)
        Closes a ResultSet, logging potential problems.
        Returns:
        null
      • appendInCondition

        protected static void appendInCondition​(StringBuilder builder,
                                                String field,
                                                int placeholdersCount,
                                                int maxListLength)
        Appends following SQL condition to the builder: ID in (?,?,?). The field name ID and the number of place holders is configurable. If the number of place holders is greater than maxListLength, then the condition will have following form: (ID in (?,?,?) or ID in (?,?,?) or ID in (?,?))
        Parameters:
        builder - the condition will be appended here
        field - name of the field
        placeholdersCount - how many ? should be included
        maxListLength - what's the max number of ? in one list