Class RDBJDBCTools


  • public class RDBJDBCTools
    extends java.lang.Object
    Convenience methods dealing with JDBC specifics.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  RDBJDBCTools.PreparedStatementComponent
      Provides a component for a PreparedStatement and a method for setting the parameters within this component
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int MAX_IN_CLAUSE  
    • Constructor Summary

      Constructors 
      Constructor Description
      RDBJDBCTools()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      protected static void appendInCondition​(java.lang.StringBuilder builder, java.lang.String field, int placeholdersCount, int maxListLength)
      Appends following SQL condition to the builder: ID in (?,?,?).
      static DocumentStoreException asDocumentStoreException​(@NotNull java.lang.Exception cause, @NotNull java.lang.String message)  
      protected static java.sql.ResultSet closeResultSet​(@Nullable java.sql.ResultSet rs)
      Closes a ResultSet, logging potential problems.
      protected static <T extends java.sql.Statement>
      T
      closeStatement​(T stmt)
      Closes a Statement, logging potential problems.
      static RDBJDBCTools.PreparedStatementComponent createInStatement​(java.lang.String fieldName, java.util.Collection<java.lang.String> values, boolean binary)  
      protected static @NotNull java.lang.String createTableName​(@NotNull java.lang.String prefix, @NotNull java.lang.String basename)
      Creates a table name based on an optional prefix and a base name.
      protected static java.lang.String driverForDBType​(java.lang.String type)  
      protected static java.lang.String dumpResultSetMeta​(java.sql.ResultSetMetaData met)
      Return approximated string representation of table DDL.
      protected static @NotNull java.lang.String getAdditionalMessages​(java.sql.SQLException ex)
      Return a string containing additional messages from chained exceptions.
      protected static @NotNull java.lang.String isolationLevelToString​(int isolationLevel)
      Return string representation of transaction isolation level.
      protected static java.lang.String jdbctype​(java.lang.String jdbcurl)  
      protected static boolean matchesSQLState​(java.sql.SQLException ex, java.lang.String... statePrefix)
      Check whether the exception matches one of the given states.
      protected static java.lang.String versionCheck​(java.sql.DatabaseMetaData md, int dbmax, int dbmin, int drmax, int drmin, java.lang.String dbname)
      Generate database + driver version diagnostics.
      protected static java.lang.String versionCheck​(java.sql.DatabaseMetaData md, int dbmax, int dbmin, java.lang.String dbname)
      Generate database version diagnostics.
      • Methods inherited from class java.lang.Object

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

      • MAX_IN_CLAUSE

        public static final int MAX_IN_CLAUSE
    • Constructor Detail

      • RDBJDBCTools

        public RDBJDBCTools()
    • Method Detail

      • jdbctype

        protected static java.lang.String jdbctype​(java.lang.String jdbcurl)
      • driverForDBType

        protected static java.lang.String driverForDBType​(java.lang.String type)
      • createTableName

        @NotNull
        protected static @NotNull java.lang.String createTableName​(@NotNull
                                                                   @NotNull java.lang.String prefix,
                                                                   @NotNull
                                                                   @NotNull java.lang.String basename)
                                                            throws java.lang.IllegalArgumentException
        Creates a table name based on an optional prefix and a base name.
        Throws:
        java.lang.IllegalArgumentException - upon illegal characters in name
      • isolationLevelToString

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

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

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

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

        protected static java.lang.String versionCheck​(java.sql.DatabaseMetaData md,
                                                       int dbmax,
                                                       int dbmin,
                                                       int drmax,
                                                       int drmin,
                                                       java.lang.String dbname)
                                                throws java.sql.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:
        java.sql.SQLException
      • versionCheck

        protected static java.lang.String versionCheck​(java.sql.DatabaseMetaData md,
                                                       int dbmax,
                                                       int dbmin,
                                                       java.lang.String dbname)
                                                throws java.sql.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:
        java.sql.SQLException
      • closeStatement

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

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

        protected static void appendInCondition​(java.lang.StringBuilder builder,
                                                java.lang.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
      • asDocumentStoreException

        public static DocumentStoreException asDocumentStoreException​(@NotNull
                                                                      @NotNull java.lang.Exception cause,
                                                                      @NotNull
                                                                      @NotNull java.lang.String message)