Interface IDatabaseTranslator

  • All Known Implementing Classes:
    Db2Translator, DerbyNetworkTranslator, DerbyTranslator, PostgresTranslator

    public interface IDatabaseTranslator
    Lets us adjust DDL/DML/SQL statements to match the target database. This is needed because DB2 and Derby have a few differences, and we need to tweak the SQL in order to support all the unit tests we want/need
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      java.lang.String addForUpdate​(java.lang.String sql)
      Append FOR UPDATE/FOR UPDATE WITH RS depending on the target DB type
      boolean clobSupportsInline()
      Does the database support inlining for clobs
      java.lang.String createGlobalTempTable​(java.lang.String ddl)  
      java.lang.String createSequence​(java.lang.String name, int cache)
      Craft the DDL for a CREATE SEQUENCE statement
      java.lang.String currentTimestampString()
      Get the "CURRENT TIMESTAMP" string for the database type
      java.lang.String dropForeignKeyConstraint​(java.lang.String qualifiedTableName, java.lang.String constraintName)
      Generate the DDL for dropping the named FK constraint from the given table
      java.lang.String dualTableName()
      The name of the "DUAL" table...that special table giving us one row/column.
      void fillProperties​(java.util.Properties p, ConnectionDetails cd)
      Configure the properties using information from the ConnectionDetails
      java.lang.String getDriverClassName()
      Get the driver class to use for connections
      DbType getType()
      The main type of the database
      java.lang.String getUrl​(java.util.Properties connectionProperties)
      Get the JDBC connection URL based on the properties
      java.lang.String globalTempTableName​(java.lang.String tableName)
      Get the proper table name based on the type of database we are connected to.
      boolean isAlreadyExists​(java.sql.SQLException x)
      Check the exception to see if it is reporting that THE NAME OF THE OBJECT TO BE CREATED OR THE TARGET OF A RENAME STATEMENT IS IDENTICAL TO THE EXISTING NAME OF THE OBJECT TYPE
      boolean isConnectionError​(java.sql.SQLException x)
      Returns true if the exception represents a connection error
      boolean isDeadlock​(java.sql.SQLException x)
      Was this statement the victim of a deadlock
      boolean isDerby()
      Are we working with a Derby database
      boolean isDuplicate​(java.sql.SQLException x)
      Check the exception to see if it is reporting a duplicate value constraint violation
      default boolean isIndexUseSchemaPrefix()
      Does this database use the schema prefix when defining indexes
      boolean isLockTimeout​(java.sql.SQLException x)
      Database timed out waiting to get a lock.
      boolean isUndefinedName​(java.sql.SQLException x)
      Returns true if the SQLException is indicating an object is undefined (e.g.
      java.lang.String limit​(java.lang.String arg)
      Get the correct LIMIT/FETCH NEXT ROWS clause for the database
      default java.util.Optional<java.lang.Integer> maximumQueryParameters()  
      java.lang.String nextValue​(java.lang.String schemaName, java.lang.String sequenceName)
      Statement for getting the next value (for use in a select list or insert values)
      java.lang.String pagination​(int offset, int rowsPerPage)
      Construct a pagination clause specific to the type of database
      java.lang.String reorgTableCommand​(java.lang.String tableName)
      Return the REORG TABLE command if supported, or null otherwise
      java.lang.String selectSequenceNextValue​(java.lang.String schemaName, java.lang.String sequenceName)
      Compose a select statement to obtain the next value from the named sequence
      java.lang.String timestampDiff​(java.lang.String left, java.lang.String right, java.lang.String alias)
      Returns an expression which computes the timestamp difference between left and right in seconds
      DataAccessException translate​(java.sql.SQLException x)
      Get an appropriate instance of ReplicatorException to throw depending on the details of SQLException
    • Method Detail

      • isDerby

        boolean isDerby()
        Are we working with a Derby database
        Returns:
      • addForUpdate

        java.lang.String addForUpdate​(java.lang.String sql)
        Append FOR UPDATE/FOR UPDATE WITH RS depending on the target DB type
        Parameters:
        sql -
        Returns:
      • globalTempTableName

        java.lang.String globalTempTableName​(java.lang.String tableName)
        Get the proper table name based on the type of database we are connected to. Derby has its own handling of temp tables
        Parameters:
        tableName -
        Returns:
      • createGlobalTempTable

        java.lang.String createGlobalTempTable​(java.lang.String ddl)
        Parameters:
        ddl -
        Returns:
      • selectSequenceNextValue

        java.lang.String selectSequenceNextValue​(java.lang.String schemaName,
                                                 java.lang.String sequenceName)
        Compose a select statement to obtain the next value from the named sequence
        Parameters:
        schemaName -
        sequenceName -
        Returns:
      • nextValue

        java.lang.String nextValue​(java.lang.String schemaName,
                                   java.lang.String sequenceName)
        Statement for getting the next value (for use in a select list or insert values)
        Parameters:
        schemaName -
        sequenceName -
        Returns:
      • isDuplicate

        boolean isDuplicate​(java.sql.SQLException x)
        Check the exception to see if it is reporting a duplicate value constraint violation
        Parameters:
        x -
        Returns:
      • isAlreadyExists

        boolean isAlreadyExists​(java.sql.SQLException x)
        Check the exception to see if it is reporting that THE NAME OF THE OBJECT TO BE CREATED OR THE TARGET OF A RENAME STATEMENT IS IDENTICAL TO THE EXISTING NAME OF THE OBJECT TYPE
        Parameters:
        x -
        Returns:
      • isLockTimeout

        boolean isLockTimeout​(java.sql.SQLException x)
        Database timed out waiting to get a lock. This is not the same as a deadlock, of course
        Parameters:
        x -
        Returns:
      • isDeadlock

        boolean isDeadlock​(java.sql.SQLException x)
        Was this statement the victim of a deadlock
        Parameters:
        x -
        Returns:
      • isConnectionError

        boolean isConnectionError​(java.sql.SQLException x)
        Returns true if the exception represents a connection error
        Parameters:
        x -
        Returns:
      • translate

        DataAccessException translate​(java.sql.SQLException x)
        Get an appropriate instance of ReplicatorException to throw depending on the details of SQLException
        Parameters:
        x -
        Returns:
      • isUndefinedName

        boolean isUndefinedName​(java.sql.SQLException x)
        Returns true if the SQLException is indicating an object is undefined (e.g. "DROP TABLE foo.bar", where table "foo.bar" doesn't exist)
        Parameters:
        x -
        Returns:
      • fillProperties

        void fillProperties​(java.util.Properties p,
                            ConnectionDetails cd)
        Configure the properties using information from the ConnectionDetails
        Parameters:
        p -
        cd -
      • timestampDiff

        java.lang.String timestampDiff​(java.lang.String left,
                                       java.lang.String right,
                                       java.lang.String alias)
        Returns an expression which computes the timestamp difference between left and right in seconds
        Parameters:
        left -
        right -
        alias - adds " AS alias " if alias is not null
        Returns:
      • currentTimestampString

        java.lang.String currentTimestampString()
        Get the "CURRENT TIMESTAMP" string for the database type
        Returns:
      • createSequence

        java.lang.String createSequence​(java.lang.String name,
                                        int cache)
        Craft the DDL for a CREATE SEQUENCE statement
        Parameters:
        name -
        cache - the number of sequence values to cache, if supported by the database
        Returns:
      • reorgTableCommand

        java.lang.String reorgTableCommand​(java.lang.String tableName)
        Return the REORG TABLE command if supported, or null otherwise
        Parameters:
        tableName -
        Returns:
      • getDriverClassName

        java.lang.String getDriverClassName()
        Get the driver class to use for connections
        Returns:
      • limit

        java.lang.String limit​(java.lang.String arg)
        Get the correct LIMIT/FETCH NEXT ROWS clause for the database
        Parameters:
        arg - a literal int or ? bind-variable marker
        Returns:
      • pagination

        java.lang.String pagination​(int offset,
                                    int rowsPerPage)
        Construct a pagination clause specific to the type of database
        Parameters:
        offset - the row offset
        rowsPerPage - limit the number of rows returned (from the offset)
        Returns:
      • getUrl

        java.lang.String getUrl​(java.util.Properties connectionProperties)
        Get the JDBC connection URL based on the properties
        Parameters:
        connectionProperties -
        Returns:
      • clobSupportsInline

        boolean clobSupportsInline()
        Does the database support inlining for clobs
        Returns:
      • getType

        DbType getType()
        The main type of the database
        Returns:
      • dualTableName

        java.lang.String dualTableName()
        The name of the "DUAL" table...that special table giving us one row/column.
        Returns:
        the name of the "DUAL" table for the database, or null if not supported
      • dropForeignKeyConstraint

        java.lang.String dropForeignKeyConstraint​(java.lang.String qualifiedTableName,
                                                  java.lang.String constraintName)
        Generate the DDL for dropping the named FK constraint from the given table
        Parameters:
        qualifiedTableName - such as schema.foo_tab
        constraintName - the constraint name of the FK
        Returns:
      • isIndexUseSchemaPrefix

        default boolean isIndexUseSchemaPrefix()
        Does this database use the schema prefix when defining indexes
        Returns:
      • maximumQueryParameters

        default java.util.Optional<java.lang.Integer> maximumQueryParameters()
        Returns:
        the total number of parameters supported by the data store during a query. An empty optional indicates no maximum is set.