Interface Backend

    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      boolean allowsExpressionsReferringToTablesBeingUpdated()
      Determines whether backend allows expressions referring to tables being updated.
      void assertValidName​(SqlNameType nameType, java.lang.String name)
      Asserts that given string is a valid name and usage.
      void buildSelectSql​(java.lang.StringBuilder sqlBuilder, boolean writeLock, int limit, int offset)
      Creates a select statement string from an inner sql string.
      java.lang.String buildSelectSql​(java.lang.String sql, boolean writeLock, int limit, int offset)
      Creates a select statement string from an inner sql string.
      java.lang.String columnTypeNullDefaultToString​(java.lang.String columnName, SqlType sqlType, int size, int scale, boolean nullable, java.lang.Object defaultValue)
      Converts an sqltype, size, scale, nullable and default value to a database type declaration.
      java.lang.String columnTypeToString​(SqlType sqlType, int size, int scale)
      Converts an sqltype, size and scale to a database type declaration.
      ColumnMetaData createColumnMetaData​(TableMetaData tableMetaData)
      Creates a column meta data instance.
      java.sql.Connection createConnection​(java.lang.String url, java.lang.String username, char[] password)
      Creates a jdbc connection.
      IndexColumnMetaData createIndexColumnMetaData​(IndexMetaData indexMetaData)
      Creates an index column meta data instance.
      IndexMetaData createIndexMetaData​(TableMetaData tableMetaData)
      Creates an index meta data instance.
      TableMetaData createTableMetaData​(ModelMetaData metaData, java.lang.String tableName)
      Creates a meta data instance.
      java.lang.String getBackendId​(java.sql.Connection connection)
      Determines the unique id or name used by the backend for a given connection.
      java.lang.String getCoalesceKeyword()
      Gets the keyword for the COALESCE function.
      java.lang.String getDefaultSchema()
      Gets the default schema name.
      Some backends store the objects in a default schema, if no explicit schema is given.
      int getDefaultSize​(SqlType sqlType)
      Gets the default size if no size given in model.
      java.lang.String getDriverClassName()
      Gets the JDBC driver class name.
      java.lang.String getEmptyString()
      Gets the empty string.
      int getMaxScale​(SqlType sqlType, int size)
      Returns the maximum scale for a given SQL-type and size.
      int getMaxSize​(SqlType sqlType)
      Returns the maximum size for a given SQL-type.
      java.sql.DatabaseMetaData[] getMetaData​(BackendInfo backendInfo)
      Gets the metadata from the backend.
      MigrationStrategy[] getMigrationStrategy​(ColumnMetaData column, java.lang.String columnName, java.lang.String comment, SqlType sqlType, int size, int scale, boolean nullable, java.lang.Object defaultValue)
      Determines the best migration strategy.
      ModelMetaData getModelMetaData​(java.sql.DatabaseMetaData[] metaData, java.lang.String[] schemas, java.lang.String... tableNames)
      Retrieves the metadata.
      java.lang.String getName()
      Gets the name of the backend.
      java.util.Set<java.lang.String> getReservedWords()
      Gets the list of reserved words for this backend.
      java.util.List<DatabaseMetaDataTableHeader> getTableHeaders​(java.sql.DatabaseMetaData metaData)
      Gets all table headers for a given metadata.
      TableMetaData getTableMetaData​(ModelMetaData modelMetaData, java.lang.String tableName)
      Gets the table meta data for a given table name.
      boolean isArrayOperatorSupported​(java.lang.String operator)
      Returns whether the backend supports given array operator.
      boolean isClobSupported()
      Returns whether the backend support CLOB types.
      If not, it will be emulated as VARCHAR with the maximum possible size.
      boolean isCommunicationLinkException​(java.sql.SQLException ex)
      Determines whether exception is a communication error.
      boolean isConstraintException​(java.sql.SQLException ex)
      Determines whether exception is a constraint violation.
      boolean isDefaultEqual​(ColumnMetaData column, SqlType sqlType, java.lang.Object defaultValue)
      Checks whether the column's default corresponds to the model's default value.
      boolean isDropIfExistsEnabled()
      Returns whether backend should add IF EXISTS for generated DROPs.
      boolean isFilteredIndexSupported()
      Returns whether backend supports filtered indexes.
      boolean isFunctionBasedIndexSupported()
      Returns whether function based indexes are supported.
      boolean isMatchingName​(java.lang.String name)
      Checks whether the backend belongs to the given name.
      boolean isMatchingUrl​(java.lang.String url)
      Checks whether the backend belongs to the given jdbc url.
      If multiple backend implementations are provided for the same database type, only one backend should match the URL.
      boolean isReleaseSavepointSupported()
      Returns whether the backend supports releasing savepoints explicitly.
      boolean isReservedSchemaName​(java.lang.String name)
      Checks whether this is a reserved schema name for this backend.
      boolean isReservedTableName​(java.lang.String name)
      Checks whether this a reserved table name for this backend.
      Applies only to tables.
      boolean isTemporaryName​(java.lang.String name)
      Checks whether this is a temporary name.
      Returns whether an entity-, attribute- or index-name is temporary and should not be taken into account for migration or even used in the model.
      Depending on the backend, temporary names start with an underscore or some other lead string.
      SqlType[] jdbcTypeToSqlType​(int jdbcType, int size, int scale)
      Converts the JDBC data type integer to a tentackle backend SqlTypes.
      boolean needAliasForSubselect()
      Returns whether backend needs an alias for a subselect.
      boolean needSetLongWorkaround()
      Checks whether we need a workaround for the (Ingres) setLong-Bug.
      boolean needTxForFetchsize()
      Checks for the (postgres) bug that fetchsize is ignored if not within a new transaction.
      java.lang.String optimizeSql​(java.lang.String sql)
      Optimize SQL code.
      Replace WHERE 1=1 AND/OR to WHERE.
      void setArray​(java.sql.PreparedStatement statement, int pos, SqlType type, java.util.Collection<?> elements, java.lang.String operator)
      Sets an array parameter in a prepared statement.
      void setDropIfExistsEnabled​(boolean dropIfExists)
      Some database support drop index/constraint/column IF EXISTS.
      This may be useful if migration scripts are generated against non-production databases that contain test indexes etc...
      Notice, that those temporary DDL changes should better use the temporary prefix (see isTemporaryName(String) in order to be ignored by the migrator.
      int setLeadingSelectParameters​(BackendPreparedStatement stmt, int limit, int offset)
      Sets optional parameters before applying the original parameters.
      int setTrailingSelectParameters​(BackendPreparedStatement stmt, int index, int limit, int offset)
      Sets optional parameters after applying the original parameters.
      java.lang.String sqlAddColumn​(java.lang.String tableName, java.lang.String columnName, java.lang.String comment, SqlType sqlType, int size, int scale, boolean nullable, java.lang.Object defaultValue)
      Generates sql code to add a column.
      java.lang.String sqlAlterColumnComment​(java.lang.String tableName, java.lang.String columnName, java.lang.String comment)
      Generates SQL code to alter the comment for an attribute.
      java.lang.String sqlAlterColumnDefault​(java.lang.String tableName, java.lang.String columnName, SqlType sqlType, java.lang.Object defaultValue)
      Generates sql code to change the default value a column.
      java.lang.String sqlAlterColumnNullConstraint​(java.lang.String tableName, java.lang.String columnName, boolean nullable)
      Generates sql code to change the null-constraint of a column.
      java.lang.String sqlAlterColumnType​(java.lang.String tableName, java.lang.String columnName, java.lang.String comment, SqlType sqlType, int size, int scale, boolean nullable, java.lang.Object defaultValue)
      Generates sql code to change the datatype of a column.
      java.lang.String sqlAlterTableComment​(java.lang.String tableName, java.lang.String comment)
      Generates SQL code to alter the comment for a table.
      java.lang.String sqlAsBeforeTableAlias()
      Gets the string before the table alias.
      In most databases the " AS " is optional and some don't accept it all.
      java.lang.String sqlComment​(java.lang.String text)
      Create comment sql code that is interpreted as a comment by the backend.
      java.lang.String sqlCreateColumn​(java.lang.String columnName, java.lang.String comment, SqlType sqlType, int size, int scale, boolean nullable, java.lang.Object defaultValue, boolean primaryKey, boolean withTrailingComma)
      Generates the attribute definition of a CREATE TABLE statement.
      java.lang.String sqlCreateColumnComment​(java.lang.String tableName, java.lang.String columnName, java.lang.String comment)
      Generates SQL code to create the comment for an attribute.
      java.lang.String sqlCreateForeignKey​(java.lang.String referencingTableName, java.lang.String referencingColumnName, java.lang.String referencedTableName, java.lang.String referencedColumnName, java.lang.String foreignKeyName, boolean composite)
      Generates the ALTER TABLE statement to add a foreign key constraint.
      java.lang.String sqlCreateIndex​(java.lang.String tableName, java.lang.String indexName, boolean unique, java.lang.String filterCondition, java.lang.String... columnNames)
      Generates the CREATE INDEX statement.
      java.lang.String sqlCreateTableClosing​(java.lang.String tableName, java.lang.String comment)
      Generates the last line of a CREATE TABLE statement.
      java.lang.String sqlCreateTableComment​(java.lang.String tableName, java.lang.String comment)
      Generates SQL code to create the comment for a table.
      java.lang.String sqlCreateTableIntro​(java.lang.String tableName, java.lang.String comment)
      Generates the first line of a CREATE TABLE statement.
      java.lang.String sqlDropColumn​(java.lang.String tableName, java.lang.String columnName)
      Generates sql code to drop a column.
      java.lang.String sqlDropForeignKey​(java.lang.String referencingTableName, java.lang.String foreignKeyName)
      Generates the sql statement to drop a foreign key constraint.
      java.lang.String sqlDropIndex​(java.lang.String schemaName, java.lang.String tableNameWithoutSchema, java.lang.String indexName)
      Generates the DROP INDEX statement.
      java.lang.String sqlDropTable​(java.lang.String schemaName, java.lang.String tableNameWithoutSchema)
      Generates the DROP TABLE statement.
      java.lang.String sqlFunction​(java.lang.String functionName, java.lang.String expression)
      Creates an sql function expression.
      java.lang.String sqlJoin​(JoinType type, java.lang.String joinedTableName, java.lang.String joinedTableAlias, java.lang.String join)
      Creates a join clause.
      void sqlJoinSelects​(JoinType type, boolean addColumns, java.lang.StringBuilder select, java.lang.String joinSelect, java.lang.String joinSelectIdAlias, java.lang.String joinAlias, java.lang.String join)
      Generate SQL code for joining a table to an existing select.
      java.lang.String sqlJoinSelects​(JoinType type, boolean addColumns, java.lang.String select, java.lang.String joinSelect, java.lang.String joinSelectIdAlias, java.lang.String joinAlias, java.lang.String join)
      Generate SQL code for joining a table to an existing select.
      java.lang.String sqlNextFromSequene​(java.lang.String name)
      Creates the SQL string to retrieve the next id from a sequence.
      java.lang.String sqlRenameAndAlterColumnType​(java.lang.String tableName, java.lang.String oldColumnName, java.lang.String newColumnName, java.lang.String comment, SqlType sqlType, int size, int scale, boolean nullable, java.lang.Object defaultValue)
      Generates sql code to rename a column.
      java.lang.String sqlRenameColumn​(java.lang.String tableName, java.lang.String oldColumnName, java.lang.String newColumnName)
      Generates sql code to rename a column.
      java.lang.String sqlRenameIndex​(java.lang.String tableName, java.lang.String oldIndexName, java.lang.String newIndexName)
      Generates sql code to rename an index.
      java.lang.String sqlRenameTable​(java.lang.String tableName, java.lang.String newTableName)
      Generate sql code to rename a table.
      boolean sqlRequiresExtraCommit()
      According to the JDBC-specs Connection.setAutoCommit(boolean)(true) should commit, but some backends require an extra Connection.commit().
      boolean sqlResultSetIsClosedSupported()
      Determines whether the jdbc driver supports ResultSet.isClosed().
      java.lang.String sqlTypeToString​(SqlType sqlType, int size)
      Converts the java SQL-type to the database type name.
      java.lang.String sqlUpdateToNotNull​(java.lang.String tableName, java.lang.String columnName, SqlType sqlType, java.lang.Object defaultValue)
      Generates code to update a column to a non-null value.
      boolean supportsSequences()
      True if backend provides transactionless sequences.
      java.lang.String toInternalType​(java.lang.String sqlTypeName)
      Converts a backend specific type name to an internal name used by driver specific methods.
      java.lang.String toQuotedString​(java.lang.String str)
      Converts a string to a string enclosed in single quotes.
      java.lang.String valueToLiteral​(SqlType sqlType, java.lang.Object value)
      Conberts a type and value to a literal string.
    • Field Detail

      • SQL_SELECT_ALL_FROM

        static final java.lang.String SQL_SELECT_ALL_FROM
        SELECT * FROM string.
        See Also:
        Constant Field Values
      • SQL_INSERT_INTO

        static final java.lang.String SQL_INSERT_INTO
        INSERT INTO string.
        See Also:
        Constant Field Values
      • SQL_LEFT_PARENTHESIS

        static final java.lang.String SQL_LEFT_PARENTHESIS
        opening bracket.
        See Also:
        Constant Field Values
      • SQL_RIGHT_PARENTHESIS

        static final java.lang.String SQL_RIGHT_PARENTHESIS
        closing bracket.
        See Also:
        Constant Field Values
      • SQL_INSERT_VALUES

        static final java.lang.String SQL_INSERT_VALUES
        (VALUES) string for insert.
        See Also:
        Constant Field Values
      • SQL_ARRAY_PAR

        static final java.lang.String SQL_ARRAY_PAR
        Array parameter (?).
        See Also:
        Constant Field Values
      • SQL_NOTEQUAL

        static final java.lang.String SQL_NOTEQUAL
        <> operator string.
        See Also:
        Constant Field Values
      • SQL_GREATER

        static final java.lang.String SQL_GREATER
        > operator string.
        See Also:
        Constant Field Values
      • SQL_LESSOREQUAL

        static final java.lang.String SQL_LESSOREQUAL
        <= operator string.
        See Also:
        Constant Field Values
      • SQL_GREATEROREQUAL

        static final java.lang.String SQL_GREATEROREQUAL
        >= operator string.
        See Also:
        Constant Field Values
      • SQL_NOTLIKE

        static final java.lang.String SQL_NOTLIKE
        NOT LIKE operator string.
        See Also:
        Constant Field Values
      • SQL_ARRAY_IN

        static final java.lang.String SQL_ARRAY_IN
        IN array operator string.
        See Also:
        Constant Field Values
      • SQL_ARRAY_NOT_IN

        static final java.lang.String SQL_ARRAY_NOT_IN
        NOT IN array operator string.
        See Also:
        Constant Field Values
      • SQL_ARRAY_ANY

        static final java.lang.String SQL_ARRAY_ANY
        ANY array operator string.
        See Also:
        Constant Field Values
      • SQL_ARRAY_ALL

        static final java.lang.String SQL_ARRAY_ALL
        ALL array operator string.
        See Also:
        Constant Field Values
      • SQL_EQUAL_ZERO

        static final java.lang.String SQL_EQUAL_ZERO
        =0 string.
        See Also:
        Constant Field Values
      • SQL_NOTEQUAL_ZERO

        static final java.lang.String SQL_NOTEQUAL_ZERO
        <>0 string.
        See Also:
        Constant Field Values
      • SQL_COMMA_PAR

        static final java.lang.String SQL_COMMA_PAR
        Parameter ,? string.
        See Also:
        Constant Field Values
      • SQL_PAR_COMMA

        static final java.lang.String SQL_PAR_COMMA
        Parameter ?, string.
        See Also:
        Constant Field Values
      • SQL_EQUAL_PAR

        static final java.lang.String SQL_EQUAL_PAR
        Parameter =? string.
        See Also:
        Constant Field Values
      • SQL_EQUAL_PAR_COMMA

        static final java.lang.String SQL_EQUAL_PAR_COMMA
        Parameter =?, string.
        See Also:
        Constant Field Values
      • SQL_NOTEQUAL_PAR

        static final java.lang.String SQL_NOTEQUAL_PAR
        Parameter <>? string.
        See Also:
        Constant Field Values
      • SQL_GREATER_PAR

        static final java.lang.String SQL_GREATER_PAR
        Parameter >? string.
        See Also:
        Constant Field Values
      • SQL_GREATEROREQUAL_PAR

        static final java.lang.String SQL_GREATEROREQUAL_PAR
        Parameter ≥? string.
        See Also:
        Constant Field Values
      • SQL_LESS_PAR

        static final java.lang.String SQL_LESS_PAR
        Parameter <? string.
        See Also:
        Constant Field Values
      • SQL_LESSOREQUAL_PAR

        static final java.lang.String SQL_LESSOREQUAL_PAR
        Parameter <=? string.
        See Also:
        Constant Field Values
      • SQL_LIKE_PAR

        static final java.lang.String SQL_LIKE_PAR
        Parameter LIKE ? string.
        See Also:
        Constant Field Values
      • SQL_NOTLIKE_PAR

        static final java.lang.String SQL_NOTLIKE_PAR
        Parameter NOT LIKE ? string.
        See Also:
        Constant Field Values
      • SQL_ARRAY_IN_PAR

        static final java.lang.String SQL_ARRAY_IN_PAR
        Parameter IN array operator string.
        See Also:
        Constant Field Values
      • SQL_ARRAY_NOT_IN_PAR

        static final java.lang.String SQL_ARRAY_NOT_IN_PAR
        Parameter NOT IN array operator string.
        See Also:
        Constant Field Values
      • SQL_ARRAY_ANY_PAR

        static final java.lang.String SQL_ARRAY_ANY_PAR
        Parameter ANY array operator string.
        See Also:
        Constant Field Values
      • SQL_ARRAY_ALL_PAR

        static final java.lang.String SQL_ARRAY_ALL_PAR
        Parameter ALL array operator string.
        See Also:
        Constant Field Values
      • SQL_WHEREALL

        static final java.lang.String SQL_WHEREALL
        "WHERE 1=1" allows AND to be added.
        See Also:
        Constant Field Values
      • SQL_WHERENOTHING

        static final java.lang.String SQL_WHERENOTHING
        "WHERE 1=0" to select nothing.
        See Also:
        Constant Field Values
      • SQL_WHEREAND

        static final java.lang.String SQL_WHEREAND
        SQL_WHEREALL + AND will be replaced by... SQL_WHERE.
        See Also:
        Constant Field Values
      • SQL_WHEREOR

        static final java.lang.String SQL_WHEREOR
        SQL_WHEREALL + OR will be replaced by... SQL_WHERE.
        See Also:
        Constant Field Values
      • SQL_ISNOTNULL

        static final java.lang.String SQL_ISNOTNULL
        IS NOT NULL string.
        See Also:
        Constant Field Values
      • SQL_ORDERBY

        static final java.lang.String SQL_ORDERBY
        ORDER BY string.
        See Also:
        Constant Field Values
      • SQL_SORTASC

        static final java.lang.String SQL_SORTASC
        sort ASC string.
        See Also:
        Constant Field Values
      • SQL_SORTDESC

        static final java.lang.String SQL_SORTDESC
        sort DESC string.
        See Also:
        Constant Field Values
      • SQL_GROUPBY

        static final java.lang.String SQL_GROUPBY
        GROUP BY string.
        See Also:
        Constant Field Values
      • SQL_EXISTS

        static final java.lang.String SQL_EXISTS
        SQL EXISTS clause with SELECT 1 and opening left parenthesis.
        See Also:
        Constant Field Values
      • SQL_ALTER_TABLE

        static final java.lang.String SQL_ALTER_TABLE
        SQL ALTER TABLE intro.
        See Also:
        Constant Field Values
      • SQL_ALTER_INDEX

        static final java.lang.String SQL_ALTER_INDEX
        SQL ALTER INDEX intro.
        See Also:
        Constant Field Values
      • SQL_ALTER_COLUMN

        static final java.lang.String SQL_ALTER_COLUMN
        SQL ALTER COLUMN fragment.
        See Also:
        Constant Field Values
      • SQL_IF_EXISTS

        static final java.lang.String SQL_IF_EXISTS
        SQL IF EXISTS fragment.
        See Also:
        Constant Field Values
    • Method Detail

      • isMatchingUrl

        boolean isMatchingUrl​(java.lang.String url)
        Checks whether the backend belongs to the given jdbc url.
        If multiple backend implementations are provided for the same database type, only one backend should match the URL. The others must be selected via name.
        Parameters:
        url - the jdbc url
        Returns:
        true if matches
      • isMatchingName

        boolean isMatchingName​(java.lang.String name)
        Checks whether the backend belongs to the given name.
        Parameters:
        name - the backend's name
        Returns:
        true if matches
      • getName

        java.lang.String getName()
        Gets the name of the backend.
        Returns:
        the name
      • getDriverClassName

        java.lang.String getDriverClassName()
        Gets the JDBC driver class name.
        Returns:
        the class name
      • createConnection

        java.sql.Connection createConnection​(java.lang.String url,
                                             java.lang.String username,
                                             char[] password)
                                      throws java.sql.SQLException
        Creates a jdbc connection.
        Parameters:
        url - the jdbc url
        username - the username
        password - the password
        Returns:
        the created connection
        Throws:
        java.sql.SQLException - if connection could not be established
      • getMetaData

        java.sql.DatabaseMetaData[] getMetaData​(BackendInfo backendInfo)
                                         throws java.sql.SQLException
        Gets the metadata from the backend.

        Important: the connection of the metadata is open!

        Parameters:
        backendInfo - the backend info
        Returns:
        the metadata, may be more than one if schemas set in backendInfo
        Throws:
        java.sql.SQLException - if failed
      • getTableHeaders

        java.util.List<DatabaseMetaDataTableHeader> getTableHeaders​(java.sql.DatabaseMetaData metaData)
                                                             throws java.sql.SQLException
        Gets all table headers for a given metadata.
        Parameters:
        metaData - the database metadata
        Returns:
        the list of table headers
        Throws:
        java.sql.SQLException - if failed
      • isTemporaryName

        boolean isTemporaryName​(java.lang.String name)
        Checks whether this is a temporary name.
        Returns whether an entity-, attribute- or index-name is temporary and should not be taken into account for migration or even used in the model.
        Depending on the backend, temporary names start with an underscore or some other lead string.
        Parameters:
        name - the name
        Returns:
        true temporary (invalid) name
      • isReservedTableName

        boolean isReservedTableName​(java.lang.String name)
        Checks whether this a reserved table name for this backend.
        Applies only to tables. Not to be mixed up with getReservedWords().
        Useful to avoid conflicts with naming conventions for backend specific things, such as snapshots.
        Parameters:
        name - the table name
        Returns:
        true if reserved by backend
      • isReservedSchemaName

        boolean isReservedSchemaName​(java.lang.String name)
        Checks whether this is a reserved schema name for this backend.
        Parameters:
        name - the schema name
        Returns:
        true if reserved by backend
      • buildSelectSql

        void buildSelectSql​(java.lang.StringBuilder sqlBuilder,
                            boolean writeLock,
                            int limit,
                            int offset)
        Creates a select statement string from an inner sql string.

        sqlBuilder is anything as FROM... WHERE... ORDER BY....
        It is decorated with a leading SELECT plus optional clauses like for the given parameters.

        Parameters:
        sqlBuilder - the sql builder, initially containing the inner sql without leading SELECT.
        writeLock - true select should write lock
        limit - the limit value, ≤ 0 if no limit clause
        offset - the offset value, ≤ 0 if no offset clause
      • buildSelectSql

        java.lang.String buildSelectSql​(java.lang.String sql,
                                        boolean writeLock,
                                        int limit,
                                        int offset)
        Creates a select statement string from an inner sql string.

        sqlBuilder is anything as FROM... WHERE... ORDER BY....
        It is decorated with a leading SELECT plus optional clauses like for the given parameters.

        Parameters:
        sql - the sql without leading SELECT.
        writeLock - true select should write lock
        limit - the limit value, ≤ 0 if no limit clause
        offset - the offset value, ≤ 0 if no offset clause
        Returns:
        the select statement
      • setLeadingSelectParameters

        int setLeadingSelectParameters​(BackendPreparedStatement stmt,
                                       int limit,
                                       int offset)
        Sets optional parameters before applying the original parameters.
        Parameters:
        stmt - the prepared statement
        limit - the limit value, ≤ 0 if no limit clause
        offset - the offset value, ≤ 0 if no offset clause
        Returns:
        the next parameter index
      • setTrailingSelectParameters

        int setTrailingSelectParameters​(BackendPreparedStatement stmt,
                                        int index,
                                        int limit,
                                        int offset)
        Sets optional parameters after applying the original parameters.
        Parameters:
        stmt - the prepared statement
        index - the first parameter index
        limit - the limit value, ≤ 0 if no limit clause
        offset - the offset value, ≤ 0 if no offset clause
        Returns:
        the next parameter index
      • getEmptyString

        java.lang.String getEmptyString()
        Gets the empty string.

        Some dbms (most famous: Oracle) handle empty strings as null. In such cases the empty string (e.g. Oracle) may consist of a single blank or whatever.

        Returns:
        the empty string (never null)
      • sqlRequiresExtraCommit

        boolean sqlRequiresExtraCommit()
        According to the JDBC-specs Connection.setAutoCommit(boolean)(true) should commit, but some backends require an extra Connection.commit().
        Returns:
        true if the database needs an extra commit
      • sqlResultSetIsClosedSupported

        boolean sqlResultSetIsClosedSupported()
        Determines whether the jdbc driver supports ResultSet.isClosed().
        Returns:
        true if the driver supports it
      • getCoalesceKeyword

        java.lang.String getCoalesceKeyword()
        Gets the keyword for the COALESCE function.
        Returns:
        the keyword
      • allowsExpressionsReferringToTablesBeingUpdated

        boolean allowsExpressionsReferringToTablesBeingUpdated()
        Determines whether backend allows expressions referring to tables being updated.
        Returns:
        true if allowed
      • supportsSequences

        boolean supportsSequences()
        True if backend provides transactionless sequences.
        Returns:
        true if database supports sequences
      • sqlAsBeforeTableAlias

        java.lang.String sqlAsBeforeTableAlias()
        Gets the string before the table alias.
        In most databases the " AS " is optional and some don't accept it all.
        Returns:
        the as-string
      • needAliasForSubselect

        boolean needAliasForSubselect()
        Returns whether backend needs an alias for a subselect.
        Returns:
        true if subselect needs an alias.
      • sqlNextFromSequene

        java.lang.String sqlNextFromSequene​(java.lang.String name)
        Creates the SQL string to retrieve the next id from a sequence.
        Parameters:
        name - the name of the sequence
        Returns:
        the SQL code
      • sqlComment

        java.lang.String sqlComment​(java.lang.String text)
        Create comment sql code that is interpreted as a comment by the backend.
        Parameters:
        text - any text, single or multiline
        Returns:
        the comment, null if text was null
      • sqlJoin

        java.lang.String sqlJoin​(JoinType type,
                                 java.lang.String joinedTableName,
                                 java.lang.String joinedTableAlias,
                                 java.lang.String join)
        Creates a join clause.
        Parameters:
        type - the join type
        joinedTableName - the joined tablename
        joinedTableAlias - the joined table alias, null if none
        join - the join expression
        Returns:
        the sql code
      • sqlFunction

        java.lang.String sqlFunction​(java.lang.String functionName,
                                     java.lang.String expression)
        Creates an sql function expression.

        Example:

          sqlFunction("max", CN_ID) --> "MAX(id)"
         
        Parameters:
        functionName - the function name, will be translated to uppercase
        expression - the expression, may be null
        Returns:
        the sql code
      • needSetLongWorkaround

        boolean needSetLongWorkaround()
        Checks whether we need a workaround for the (Ingres) setLong-Bug.
        Returns:
        true if workaround needed
      • needTxForFetchsize

        boolean needTxForFetchsize()
        Checks for the (postgres) bug that fetchsize is ignored if not within a new transaction.
        Returns:
        true if start tx
      • isConstraintException

        boolean isConstraintException​(java.sql.SQLException ex)
        Determines whether exception is a constraint violation.
        Parameters:
        ex - the exception
        Returns:
        true if constraint violation
      • isCommunicationLinkException

        boolean isCommunicationLinkException​(java.sql.SQLException ex)
        Determines whether exception is a communication error.
        Parameters:
        ex - the exception
        Returns:
        true if comlink down or alike
      • getMaxSize

        int getMaxSize​(SqlType sqlType)
        Returns the maximum size for a given SQL-type.
        Parameters:
        sqlType - the SQL-type
        Returns:
        the maximum size, 0 if unlimited, -1 if type without size
      • getMaxScale

        int getMaxScale​(SqlType sqlType,
                        int size)
        Returns the maximum scale for a given SQL-type and size.
        Parameters:
        sqlType - the SQL-type
        size - the size, 0 if unlimited
        Returns:
        the maximum scale, 0 if unlimited
      • getDefaultSize

        int getDefaultSize​(SqlType sqlType)
        Gets the default size if no size given in model.
        Parameters:
        sqlType - the SQL-type
        Returns:
        the default size, 0 if no default size
      • getDefaultSchema

        java.lang.String getDefaultSchema()
        Gets the default schema name.
        Some backends store the objects in a default schema, if no explicit schema is given.
        Returns:
        the defailt schema, null if none
      • getReservedWords

        java.util.Set<java.lang.String> getReservedWords()
        Gets the list of reserved words for this backend.
        Returns:
        the list of reserved words
      • assertValidName

        void assertValidName​(SqlNameType nameType,
                             java.lang.String name)
        Asserts that given string is a valid name and usage.
        Parameters:
        nameType - the type/usage of the name
        name - the name
        Throws:
        BackendException - if invalid name
      • getBackendId

        java.lang.String getBackendId​(java.sql.Connection connection)
        Determines the unique id or name used by the backend for a given connection.

        Useful to figure out the corresponding ManagedConnection from the backend's logfiles.

        Parameters:
        connection - the jdbc connection
        Returns:
        the backend id, null if none
      • getModelMetaData

        ModelMetaData getModelMetaData​(java.sql.DatabaseMetaData[] metaData,
                                       java.lang.String[] schemas,
                                       java.lang.String... tableNames)
        Retrieves the metadata.
        Parameters:
        metaData - the meta data for the whole database
        schemas - the optional schemas to filter tables, null if no filter
        tableNames - the tables of the model
        Returns:
        the meta data, null if no such table
      • createColumnMetaData

        ColumnMetaData createColumnMetaData​(TableMetaData tableMetaData)
        Creates a column meta data instance.
        Parameters:
        tableMetaData - the table meta data this column belongs to
        Returns:
        the meta data
      • createTableMetaData

        TableMetaData createTableMetaData​(ModelMetaData metaData,
                                          java.lang.String tableName)
        Creates a meta data instance.
        Parameters:
        metaData - the whole meta data
        tableName - the model's table name
        Returns:
        the meta data
      • createIndexMetaData

        IndexMetaData createIndexMetaData​(TableMetaData tableMetaData)
        Creates an index meta data instance.
        Parameters:
        tableMetaData - the table meta data this index belongs to
        Returns:
        the meta data
      • createIndexColumnMetaData

        IndexColumnMetaData createIndexColumnMetaData​(IndexMetaData indexMetaData)
        Creates an index column meta data instance.
        Parameters:
        indexMetaData - the meta meta data this column belongs to
        Returns:
        the meta data
      • sqlTypeToString

        java.lang.String sqlTypeToString​(SqlType sqlType,
                                         int size)
        Converts the java SQL-type to the database type name.
        Parameters:
        sqlType - the java sql type
        size - the column's size
        Returns:
        the corresponding type string
      • columnTypeToString

        java.lang.String columnTypeToString​(SqlType sqlType,
                                            int size,
                                            int scale)
        Converts an sqltype, size and scale to a database type declaration.
        Parameters:
        sqlType - the SQL type
        size - the size
        scale - the scale
        Returns:
        the type definition
      • columnTypeNullDefaultToString

        java.lang.String columnTypeNullDefaultToString​(java.lang.String columnName,
                                                       SqlType sqlType,
                                                       int size,
                                                       int scale,
                                                       boolean nullable,
                                                       java.lang.Object defaultValue)
        Converts an sqltype, size, scale, nullable and default value to a database type declaration.
        Parameters:
        columnName - the database column name
        sqlType - the JDBC sql type
        size - the optional size
        scale - the optional scale
        nullable - true if NULL, else NOT NULL
        defaultValue - the optional default value
        Returns:
        the SQL code
      • valueToLiteral

        java.lang.String valueToLiteral​(SqlType sqlType,
                                        java.lang.Object value)
        Conberts a type and value to a literal string.
        Parameters:
        sqlType - the sql type
        value - the value
        Returns:
        the constant
      • sqlCreateTableIntro

        java.lang.String sqlCreateTableIntro​(java.lang.String tableName,
                                             java.lang.String comment)
        Generates the first line of a CREATE TABLE statement.
        Parameters:
        tableName - the tablename with optional schema separated by a dot
        comment - optional comment, null if none
        Returns:
        the SQL code including the opening bracket
      • sqlCreateTableClosing

        java.lang.String sqlCreateTableClosing​(java.lang.String tableName,
                                               java.lang.String comment)
        Generates the last line of a CREATE TABLE statement.
        Parameters:
        tableName - the tablename with optional schema separated by a dot
        comment - optional comment, null if none
        Returns:
        the SQL code including the closing bracket
      • sqlAlterTableComment

        java.lang.String sqlAlterTableComment​(java.lang.String tableName,
                                              java.lang.String comment)
        Generates SQL code to alter the comment for a table.
        Parameters:
        tableName - the table name
        comment - optional comment, null to clear
        Returns:
        the SQL code
      • sqlCreateColumn

        java.lang.String sqlCreateColumn​(java.lang.String columnName,
                                         java.lang.String comment,
                                         SqlType sqlType,
                                         int size,
                                         int scale,
                                         boolean nullable,
                                         java.lang.Object defaultValue,
                                         boolean primaryKey,
                                         boolean withTrailingComma)
        Generates the attribute definition of a CREATE TABLE statement.
        Parameters:
        columnName - the database column name
        comment - optional comment, null if none
        sqlType - the JDBC sql type
        size - the optional size
        scale - the optional scale
        nullable - true if NULL, else NOT NULL
        defaultValue - the optional default value
        primaryKey - true if this is a primary key
        withTrailingComma - true if append a comma
        Returns:
        the SQL code
      • isDefaultEqual

        boolean isDefaultEqual​(ColumnMetaData column,
                               SqlType sqlType,
                               java.lang.Object defaultValue)
        Checks whether the column's default corresponds to the model's default value.
        Parameters:
        column - the column to inspect
        sqlType - the sql type
        defaultValue - the model's default value
        Returns:
        true if same
      • getMigrationStrategy

        MigrationStrategy[] getMigrationStrategy​(ColumnMetaData column,
                                                 java.lang.String columnName,
                                                 java.lang.String comment,
                                                 SqlType sqlType,
                                                 int size,
                                                 int scale,
                                                 boolean nullable,
                                                 java.lang.Object defaultValue)
        Determines the best migration strategy.
        Parameters:
        column - old column meta data
        columnName - new column name
        comment - new comment
        sqlType - new sql type
        size - new size
        scale - new scale
        nullable - new nullable
        defaultValue - new default
        Returns:
        the strategies in order to achieve the migration
      • sqlRenameTable

        java.lang.String sqlRenameTable​(java.lang.String tableName,
                                        java.lang.String newTableName)
        Generate sql code to rename a table.
        Parameters:
        tableName - the old tablename (with leading schema, if any)
        newTableName - the new tablename (without schema)
        Returns:
        the SQL code
      • sqlRenameColumn

        java.lang.String sqlRenameColumn​(java.lang.String tableName,
                                         java.lang.String oldColumnName,
                                         java.lang.String newColumnName)
        Generates sql code to rename a column.
        Parameters:
        tableName - the tablename
        oldColumnName - the old column name
        newColumnName - the new column name
        Returns:
        the SQL code, null if need full spec sqlRenameAndAlterColumnType below
      • sqlRenameIndex

        java.lang.String sqlRenameIndex​(java.lang.String tableName,
                                        java.lang.String oldIndexName,
                                        java.lang.String newIndexName)
        Generates sql code to rename an index.
        Parameters:
        tableName - the tablename
        oldIndexName - the old column name
        newIndexName - the new column name
        Returns:
        the SQL code, null if not supported by the backend and we need to drop and create
      • sqlRenameAndAlterColumnType

        java.lang.String sqlRenameAndAlterColumnType​(java.lang.String tableName,
                                                     java.lang.String oldColumnName,
                                                     java.lang.String newColumnName,
                                                     java.lang.String comment,
                                                     SqlType sqlType,
                                                     int size,
                                                     int scale,
                                                     boolean nullable,
                                                     java.lang.Object defaultValue)
        Generates sql code to rename a column.
        Parameters:
        tableName - the tablename
        oldColumnName - the old column name
        newColumnName - the new column name
        comment - optional comment, null if none
        sqlType - the JDBC sql type
        size - the optional size
        scale - the optional scale
        nullable - true if NULL, else NOT NULL
        defaultValue - the optional default value
        Returns:
        the SQL code
      • sqlAddColumn

        java.lang.String sqlAddColumn​(java.lang.String tableName,
                                      java.lang.String columnName,
                                      java.lang.String comment,
                                      SqlType sqlType,
                                      int size,
                                      int scale,
                                      boolean nullable,
                                      java.lang.Object defaultValue)
        Generates sql code to add a column.
        Parameters:
        tableName - the tablename
        columnName - the new column name
        comment - optional comment, null if none
        sqlType - the JDBC sql type
        size - the optional size
        scale - the optional scale
        nullable - true if NULL, else NOT NULL
        defaultValue - the optional default value
        Returns:
        the SQL code
      • sqlDropColumn

        java.lang.String sqlDropColumn​(java.lang.String tableName,
                                       java.lang.String columnName)
        Generates sql code to drop a column.
        Parameters:
        tableName - the tablename
        columnName - the new column name
        Returns:
        the SQL code
      • sqlAlterColumnType

        java.lang.String sqlAlterColumnType​(java.lang.String tableName,
                                            java.lang.String columnName,
                                            java.lang.String comment,
                                            SqlType sqlType,
                                            int size,
                                            int scale,
                                            boolean nullable,
                                            java.lang.Object defaultValue)
        Generates sql code to change the datatype of a column.
        Parameters:
        tableName - the tablename
        columnName - the new column name
        comment - optional comment, null if none
        sqlType - the JDBC sql type
        size - the optional size
        scale - the optional scale
        nullable - true if NULL, else NOT NULL
        defaultValue - the optional default value
        Returns:
        the SQL code
      • sqlUpdateToNotNull

        java.lang.String sqlUpdateToNotNull​(java.lang.String tableName,
                                            java.lang.String columnName,
                                            SqlType sqlType,
                                            java.lang.Object defaultValue)
        Generates code to update a column to a non-null value.
        Parameters:
        tableName - the tablename
        columnName - the column name
        sqlType - the sql type
        defaultValue - the optional default value if defined in the model
        Returns:
        the SQL code
      • sqlCreateIndex

        java.lang.String sqlCreateIndex​(java.lang.String tableName,
                                        java.lang.String indexName,
                                        boolean unique,
                                        java.lang.String filterCondition,
                                        java.lang.String... columnNames)
        Generates the CREATE INDEX statement.
        Parameters:
        tableName - the table name
        indexName - the name of the index
        unique - true if index is unique
        filterCondition - the filter condition (null if none)
        columnNames - the column names (with a leading '-' if descending). Simple function-based indexes are also supported.
        Returns:
        the SQL code
      • sqlDropIndex

        java.lang.String sqlDropIndex​(java.lang.String schemaName,
                                      java.lang.String tableNameWithoutSchema,
                                      java.lang.String indexName)
        Generates the DROP INDEX statement.
        Parameters:
        schemaName - the optional schema, null if none
        tableNameWithoutSchema - the table name without the schema
        indexName - the name of the index
        Returns:
        the SQL code
      • sqlDropTable

        java.lang.String sqlDropTable​(java.lang.String schemaName,
                                      java.lang.String tableNameWithoutSchema)
        Generates the DROP TABLE statement.
        Parameters:
        schemaName - the optional schema, null if none
        tableNameWithoutSchema - the table name without the schema
        Returns:
        the SQL code
      • sqlCreateForeignKey

        java.lang.String sqlCreateForeignKey​(java.lang.String referencingTableName,
                                             java.lang.String referencingColumnName,
                                             java.lang.String referencedTableName,
                                             java.lang.String referencedColumnName,
                                             java.lang.String foreignKeyName,
                                             boolean composite)
        Generates the ALTER TABLE statement to add a foreign key constraint.
        Parameters:
        referencingTableName - the referencing foreign table name
        referencingColumnName - the referencing foreign column name
        referencedTableName - the referenced primary table name
        referencedColumnName - the referenced primary column name
        foreignKeyName - the name of the foreign key
        composite - true if referencing table is a component of the referenced table
        Returns:
        the SQL code
      • sqlDropForeignKey

        java.lang.String sqlDropForeignKey​(java.lang.String referencingTableName,
                                           java.lang.String foreignKeyName)
        Generates the sql statement to drop a foreign key constraint.
        Parameters:
        referencingTableName - the referencing foreign table name
        foreignKeyName - the name of the foreign key
        Returns:
        the SQL code
      • sqlJoinSelects

        void sqlJoinSelects​(JoinType type,
                            boolean addColumns,
                            java.lang.StringBuilder select,
                            java.lang.String joinSelect,
                            java.lang.String joinSelectIdAlias,
                            java.lang.String joinAlias,
                            java.lang.String join)
        Generate SQL code for joining a table to an existing select.
        Parameters:
        type - the join type
        addColumns - true if columns of joined table should be added to the result set
        select - the original select statement
        joinSelect - the select to join with the original sql or just a tablename
        joinSelectIdAlias - extra id alias to add to the joined select, null if none
        joinAlias - the alias of the joined select
        join - the join clause
      • sqlJoinSelects

        java.lang.String sqlJoinSelects​(JoinType type,
                                        boolean addColumns,
                                        java.lang.String select,
                                        java.lang.String joinSelect,
                                        java.lang.String joinSelectIdAlias,
                                        java.lang.String joinAlias,
                                        java.lang.String join)
        Generate SQL code for joining a table to an existing select.
        Parameters:
        type - the join type
        addColumns - true if columns of joined table should be added to the result set
        select - the original select statement
        joinSelect - the select to join with the original sql or just a tablename
        joinSelectIdAlias - extra id alias to add to the joined select, null if none
        joinAlias - the alias of the joined select
        join - the join clause
        Returns:
        the select statement
      • jdbcTypeToSqlType

        SqlType[] jdbcTypeToSqlType​(int jdbcType,
                                    int size,
                                    int scale)
        Converts the JDBC data type integer to a tentackle backend SqlTypes.

        There may be more than one sqltype returned!

        Parameters:
        jdbcType - the jdbc data type
        size - the column size
        scale - the column's scale
        Returns:
        the SqlTypes, empty array if no mapping available or no exact match (not generated by TT)
        See Also:
        Types
      • getTableMetaData

        TableMetaData getTableMetaData​(ModelMetaData modelMetaData,
                                       java.lang.String tableName)
        Gets the table meta data for a given table name.
        Parameters:
        modelMetaData - the model the table belongs to
        tableName - the model's table name
        Returns:
        the table data
      • toQuotedString

        java.lang.String toQuotedString​(java.lang.String str)
        Converts a string to a string enclosed in single quotes.
        Parameters:
        str - the string
        Returns:
        the quoted string
      • optimizeSql

        java.lang.String optimizeSql​(java.lang.String sql)
        Optimize SQL code.
        Replace WHERE 1=1 AND/OR to WHERE. Any remaining WHERE 1=1 will be removed too. If you don't want your statements getting optimized, use lowercase for those keywords.
        Parameters:
        sql - the original sql code
        Returns:
        the optimized sql code
      • isReleaseSavepointSupported

        boolean isReleaseSavepointSupported()
        Returns whether the backend supports releasing savepoints explicitly. If not, the savepoints are released when the transaction finishs.
        Returns:
        true if release is supported, else false
      • isClobSupported

        boolean isClobSupported()
        Returns whether the backend support CLOB types.
        If not, it will be emulated as VARCHAR with the maximum possible size.
        Returns:
        true if supported, false if treat as varchar
      • isFunctionBasedIndexSupported

        boolean isFunctionBasedIndexSupported()
        Returns whether function based indexes are supported.
        Returns:
        true if supported
      • isFilteredIndexSupported

        boolean isFilteredIndexSupported()
        Returns whether backend supports filtered indexes.
        Returns:
        true if supported, false if model will raise an error if filtered index is used
      • setDropIfExistsEnabled

        void setDropIfExistsEnabled​(boolean dropIfExists)
        Some database support drop index/constraint/column IF EXISTS.
        This may be useful if migration scripts are generated against non-production databases that contain test indexes etc...
        Notice, that those temporary DDL changes should better use the temporary prefix (see isTemporaryName(String) in order to be ignored by the migrator.
        Parameters:
        dropIfExists - true if use IF EXISTS if the backend supports it
      • isDropIfExistsEnabled

        boolean isDropIfExistsEnabled()
        Returns whether backend should add IF EXISTS for generated DROPs.
        Returns:
        true if IF EXISTS is turned on and supported, false if not supported or turned off
      • toInternalType

        java.lang.String toInternalType​(java.lang.String sqlTypeName)
        Converts a backend specific type name to an internal name used by driver specific methods.
        Parameters:
        sqlTypeName - the original type used in SQL scripts
        Returns:
        the JDBC internal name
      • isArrayOperatorSupported

        boolean isArrayOperatorSupported​(java.lang.String operator)
        Returns whether the backend supports given array operator.
        Parameters:
        operator - the array operator
        Returns:
        true if supported
      • setArray

        void setArray​(java.sql.PreparedStatement statement,
                      int pos,
                      SqlType type,
                      java.util.Collection<?> elements,
                      java.lang.String operator)
               throws java.sql.SQLException
        Sets an array parameter in a prepared statement.
        Parameters:
        statement - the prepared statement
        pos - the parameter position (starting at 1)
        type - the element's SQL type
        elements - the elements to be converted to an array parameter
        operator - the array operator
        Throws:
        java.sql.SQLException