Class AbstractBackend

  • All Implemented Interfaces:
    Backend
    Direct Known Subclasses:
    AbstractSql92Backend

    public abstract class AbstractBackend
    extends Object
    implements Backend
    Abstract parent class for backends.
    Author:
    harald
    • Constructor Detail

      • AbstractBackend

        public AbstractBackend()
    • Method Detail

      • isMatchingName

        public boolean isMatchingName​(String name)
        Description copied from interface: Backend
        Checks whether the backend belongs to the given name.
        Specified by:
        isMatchingName in interface Backend
        Parameters:
        name - the backend's name
        Returns:
        true if matches
      • createConnection

        public Connection createConnection​(String url,
                                           String username,
                                           char[] password)
                                    throws SQLException
        Description copied from interface: Backend
        Creates a jdbc connection.
        Specified by:
        createConnection in interface Backend
        Parameters:
        url - the jdbc url
        username - the username
        password - the password
        Returns:
        the created connection
        Throws:
        SQLException - if connection could not be established
      • getMetaData

        public DatabaseMetaData[] getMetaData​(BackendInfo backendInfo)
                                       throws SQLException
        Description copied from interface: Backend
        Gets the metadata from the backend.

        Important: the connection of the metadata is open!

        Specified by:
        getMetaData in interface Backend
        Parameters:
        backendInfo - the backend info
        Returns:
        the metadata, may be more than one if schemas set in backendInfo
        Throws:
        SQLException - if failed
      • isTemporaryName

        public boolean isTemporaryName​(String name)
        Description copied from interface: Backend
        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.
        Specified by:
        isTemporaryName in interface Backend
        Parameters:
        name - the name
        Returns:
        true temporary (invalid) name
      • isReservedTableName

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

        public boolean isReservedSchemaName​(String name)
        Description copied from interface: Backend
        Checks whether this is a reserved schema name for this backend.
        Specified by:
        isReservedSchemaName in interface Backend
        Parameters:
        name - the schema name
        Returns:
        true if reserved by backend
      • getEmptyString

        public String getEmptyString()
        Description copied from interface: Backend
        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.

        Specified by:
        getEmptyString in interface Backend
        Returns:
        the empty string (never null)
      • sqlAsBeforeTableAlias

        public String sqlAsBeforeTableAlias()
        Description copied from interface: Backend
        Gets the string before the table alias.
        In most databases the " AS " is optional and some don't accept it all.
        Specified by:
        sqlAsBeforeTableAlias in interface Backend
        Returns:
        the as-string
      • needAliasForSubselect

        public boolean needAliasForSubselect()
        Description copied from interface: Backend
        Returns whether backend needs an alias for a subselect.
        Specified by:
        needAliasForSubselect in interface Backend
        Returns:
        true if subselect needs an alias.
      • sqlComment

        public String sqlComment​(String text)
        Description copied from interface: Backend
        Create comment sql code that is interpreted as a comment by the backend.
        Specified by:
        sqlComment in interface Backend
        Parameters:
        text - any text, single or multiline
        Returns:
        the comment, null if text was null
      • sqlJoin

        public String sqlJoin​(JoinType type,
                              String joinedTableName,
                              String joinedTableAlias,
                              String join)
        Description copied from interface: Backend
        Creates a join clause.
        Specified by:
        sqlJoin in interface Backend
        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

        public String sqlFunction​(String functionName,
                                  String expression)
        Description copied from interface: Backend
        Creates an sql function expression.

        Example:

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

        public String getCoalesceKeyword()
        Description copied from interface: Backend
        Gets the keyword for the COALESCE function.
        Specified by:
        getCoalesceKeyword in interface Backend
        Returns:
        the keyword
      • allowsExpressionsReferringToTablesBeingUpdated

        public boolean allowsExpressionsReferringToTablesBeingUpdated()
        Description copied from interface: Backend
        Determines whether backend allows expressions referring to tables being updated.
        Specified by:
        allowsExpressionsReferringToTablesBeingUpdated in interface Backend
        Returns:
        true if allowed
      • needSetLongWorkaround

        public boolean needSetLongWorkaround()
        Description copied from interface: Backend
        Checks whether we need a workaround for the (Ingres) setLong-Bug.
        Specified by:
        needSetLongWorkaround in interface Backend
        Returns:
        true if workaround needed
      • needTxForFetchsize

        public boolean needTxForFetchsize()
        Description copied from interface: Backend
        Checks for the (postgres) bug that fetchsize is ignored if not within a new transaction.
        Specified by:
        needTxForFetchsize in interface Backend
        Returns:
        true if start tx
      • isConstraintException

        public boolean isConstraintException​(SQLException ex)
        Description copied from interface: Backend
        Determines whether exception is a constraint violation.
        Specified by:
        isConstraintException in interface Backend
        Parameters:
        ex - the exception
        Returns:
        true if constraint violation
      • isCommunicationLinkException

        public boolean isCommunicationLinkException​(SQLException ex)
        Description copied from interface: Backend
        Determines whether exception is a communication error.
        Specified by:
        isCommunicationLinkException in interface Backend
        Parameters:
        ex - the exception
        Returns:
        true if comlink down or alike
      • isTransientTransactionException

        public boolean isTransientTransactionException​(SQLException ex)
        Description copied from interface: Backend
        Determines whether exception is transient and retrying the transaction may succeed.
        Typical transient exceptions are thrown when a deadlock is detected or when serialized transaction isolation is used.

        Other transient errors are not covered by this method (e.g. connection timeouts, etc...).

        Specified by:
        isTransientTransactionException in interface Backend
        Parameters:
        ex - the exception
        Returns:
        true if retrying the transaction may succeed
      • getMaxSize

        public int getMaxSize​(SqlType sqlType)
        Description copied from interface: Backend
        Returns the maximum size for a given SQL-type.
        Specified by:
        getMaxSize in interface Backend
        Parameters:
        sqlType - the SQL-type
        Returns:
        the maximum size, 0 if unlimited, -1 if type without size
      • getMaxScale

        public int getMaxScale​(SqlType sqlType,
                               int size)
        Description copied from interface: Backend
        Returns the maximum scale for a given SQL-type and size.
        Specified by:
        getMaxScale in interface Backend
        Parameters:
        sqlType - the SQL-type
        size - the size, 0 if unlimited
        Returns:
        the maximum scale, 0 if unlimited
      • getDefaultSize

        public int getDefaultSize​(SqlType sqlType)
        Description copied from interface: Backend
        Gets the default size if no size given in model.
        Specified by:
        getDefaultSize in interface Backend
        Parameters:
        sqlType - the SQL-type
        Returns:
        the default size, 0 if no default size
      • getDefaultSchema

        public String getDefaultSchema()
        Description copied from interface: Backend
        Gets the default schema name.
        Some backends store the objects in a default schema, if no explicit schema is given.
        Specified by:
        getDefaultSchema in interface Backend
        Returns:
        the defailt schema, null if none
      • getModelMetaData

        public ModelMetaData getModelMetaData​(DatabaseMetaData[] metaData,
                                              String[] schemas,
                                              String... tableNames)
        Description copied from interface: Backend
        Retrieves the metadata.
        Specified by:
        getModelMetaData in interface Backend
        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
      • getTableMetaData

        public TableMetaData getTableMetaData​(ModelMetaData modelMetaData,
                                              String tableName)
        Description copied from interface: Backend
        Gets the table meta data for a given table name.
        Specified by:
        getTableMetaData in interface Backend
        Parameters:
        modelMetaData - the model the table belongs to
        tableName - the model's table name
        Returns:
        the table data
      • createTableMetaData

        public TableMetaData createTableMetaData​(ModelMetaData modelMetaData,
                                                 String tableName)
        Description copied from interface: Backend
        Creates a meta data instance.
        Specified by:
        createTableMetaData in interface Backend
        Parameters:
        modelMetaData - the whole meta data
        tableName - the model's table name
        Returns:
        the meta data
      • createColumnMetaData

        public ColumnMetaData createColumnMetaData​(TableMetaData tableMetaData)
        Description copied from interface: Backend
        Creates a column meta data instance.
        Specified by:
        createColumnMetaData in interface Backend
        Parameters:
        tableMetaData - the table meta data this column belongs to
        Returns:
        the meta data
      • createIndexMetaData

        public IndexMetaData createIndexMetaData​(TableMetaData tableMetaData)
        Description copied from interface: Backend
        Creates an index meta data instance.
        Specified by:
        createIndexMetaData in interface Backend
        Parameters:
        tableMetaData - the table meta data this index belongs to
        Returns:
        the meta data
      • createIndexColumnMetaData

        public IndexColumnMetaData createIndexColumnMetaData​(IndexMetaData indexMetaData)
        Description copied from interface: Backend
        Creates an index column meta data instance.
        Specified by:
        createIndexColumnMetaData in interface Backend
        Parameters:
        indexMetaData - the meta meta data this column belongs to
        Returns:
        the meta data
      • sqlCreateTableIntro

        public String sqlCreateTableIntro​(String tableName,
                                          String comment)
        Description copied from interface: Backend
        Generates the first line of a CREATE TABLE statement.
        Specified by:
        sqlCreateTableIntro in interface Backend
        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

        public String sqlCreateTableClosing​(String tableName,
                                            String comment)
        Description copied from interface: Backend
        Generates the last line of a CREATE TABLE statement.
        Specified by:
        sqlCreateTableClosing in interface Backend
        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

        public String sqlAlterTableComment​(String tableName,
                                           String comment)
        Description copied from interface: Backend
        Generates SQL code to alter the comment for a table.
        Specified by:
        sqlAlterTableComment in interface Backend
        Parameters:
        tableName - the table name
        comment - optional comment, null to clear
        Returns:
        the SQL code
      • columnTypeToString

        public String columnTypeToString​(SqlType sqlType,
                                         int size,
                                         int scale)
        Description copied from interface: Backend
        Converts an sqltype, size and scale to a database type declaration.
        Specified by:
        columnTypeToString in interface Backend
        Parameters:
        sqlType - the SQL type
        size - the size
        scale - the scale
        Returns:
        the type definition
      • columnTypeNullDefaultToString

        public String columnTypeNullDefaultToString​(String columnName,
                                                    SqlType sqlType,
                                                    int size,
                                                    int scale,
                                                    boolean nullable,
                                                    Object defaultValue)
        Description copied from interface: Backend
        Converts an sqltype, size, scale, nullable and default value to a database type declaration.
        Specified by:
        columnTypeNullDefaultToString in interface Backend
        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

        public String valueToLiteral​(SqlType sqlType,
                                     Object value)
        Description copied from interface: Backend
        Conberts a type and value to a literal string.
        Specified by:
        valueToLiteral in interface Backend
        Parameters:
        sqlType - the sql type
        value - the value
        Returns:
        the constant
      • sqlCreateColumn

        public String sqlCreateColumn​(String columnName,
                                      String comment,
                                      SqlType sqlType,
                                      int size,
                                      int scale,
                                      boolean nullable,
                                      Object defaultValue,
                                      boolean primaryKey,
                                      boolean withTrailingComma)
        Description copied from interface: Backend
        Generates the attribute definition of a CREATE TABLE statement.
        Specified by:
        sqlCreateColumn in interface Backend
        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

        public boolean isDefaultEqual​(ColumnMetaData column,
                                      SqlType sqlType,
                                      Object defaultValue)
        Description copied from interface: Backend
        Checks whether the column's default corresponds to the model's default value.
        Specified by:
        isDefaultEqual in interface Backend
        Parameters:
        column - the column to inspect
        sqlType - the sql type
        defaultValue - the model's default value
        Returns:
        true if same
      • getMigrationStrategy

        public MigrationStrategy[] getMigrationStrategy​(ColumnMetaData column,
                                                        String columnName,
                                                        String comment,
                                                        SqlType sqlType,
                                                        int size,
                                                        int scale,
                                                        boolean nullable,
                                                        Object defaultValue)
        Description copied from interface: Backend
        Determines the best migration strategy.
        Specified by:
        getMigrationStrategy in interface Backend
        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

        public String sqlRenameTable​(String tableName,
                                     String newTableName)
        Description copied from interface: Backend
        Generate sql code to rename a table.
        Specified by:
        sqlRenameTable in interface Backend
        Parameters:
        tableName - the old tablename (with leading schema, if any)
        newTableName - the new tablename (without schema)
        Returns:
        the SQL code
      • sqlRenameColumn

        public String sqlRenameColumn​(String tableName,
                                      String oldColumnName,
                                      String newColumnName)
        Description copied from interface: Backend
        Generates sql code to rename a column.
        Specified by:
        sqlRenameColumn in interface Backend
        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

        public String sqlRenameIndex​(String tableName,
                                     String oldIndexName,
                                     String newIndexName)
        Description copied from interface: Backend
        Generates sql code to rename an index.
        Specified by:
        sqlRenameIndex in interface Backend
        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

        public String sqlRenameAndAlterColumnType​(String tableName,
                                                  String oldColumnName,
                                                  String newColumnName,
                                                  String comment,
                                                  SqlType sqlType,
                                                  int size,
                                                  int scale,
                                                  boolean nullable,
                                                  Object defaultValue)
        Description copied from interface: Backend
        Generates sql code to rename a column.
        Specified by:
        sqlRenameAndAlterColumnType in interface Backend
        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

        public String sqlAddColumn​(String tableName,
                                   String columnName,
                                   String comment,
                                   SqlType sqlType,
                                   int size,
                                   int scale,
                                   boolean nullable,
                                   Object defaultValue)
        Description copied from interface: Backend
        Generates sql code to add a column.
        Specified by:
        sqlAddColumn in interface Backend
        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

        public String sqlDropColumn​(String tableName,
                                    String columnName)
        Description copied from interface: Backend
        Generates sql code to drop a column.
        Specified by:
        sqlDropColumn in interface Backend
        Parameters:
        tableName - the tablename
        columnName - the new column name
        Returns:
        the SQL code
      • sqlAlterColumnType

        public String sqlAlterColumnType​(String tableName,
                                         String columnName,
                                         String comment,
                                         SqlType sqlType,
                                         int size,
                                         int scale,
                                         boolean nullable,
                                         Object defaultValue)
        Description copied from interface: Backend
        Generates sql code to change the datatype of a column.
        Specified by:
        sqlAlterColumnType in interface Backend
        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

        public String sqlUpdateToNotNull​(String tableName,
                                         String columnName,
                                         SqlType sqlType,
                                         Object defaultValue)
        Description copied from interface: Backend
        Generates code to update a column to a non-null value.
        Specified by:
        sqlUpdateToNotNull in interface Backend
        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
      • sqlTypeToString

        public String sqlTypeToString​(SqlType sqlType,
                                      int size)
        Description copied from interface: Backend
        Converts the java SQL-type to the database type name.
        Specified by:
        sqlTypeToString in interface Backend
        Parameters:
        sqlType - the java sql type
        size - the column's size
        Returns:
        the corresponding type string
      • sqlCreateIndex

        public String sqlCreateIndex​(String tableName,
                                     String indexName,
                                     boolean unique,
                                     String filterCondition,
                                     String... columnNames)
        Description copied from interface: Backend
        Generates the CREATE INDEX statement.
        Specified by:
        sqlCreateIndex in interface Backend
        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

        public String sqlDropIndex​(String schemaName,
                                   String tableNameWithoutSchema,
                                   String indexName)
        Description copied from interface: Backend
        Generates the DROP INDEX statement.
        Specified by:
        sqlDropIndex in interface Backend
        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

        public String sqlDropTable​(String schemaName,
                                   String tableNameWithoutSchema)
        Description copied from interface: Backend
        Generates the DROP TABLE statement.
        Specified by:
        sqlDropTable in interface Backend
        Parameters:
        schemaName - the optional schema, null if none
        tableNameWithoutSchema - the table name without the schema
        Returns:
        the SQL code
      • sqlJoinSelects

        public void sqlJoinSelects​(JoinType type,
                                   boolean addColumns,
                                   StringBuilder select,
                                   String joinSelect,
                                   String joinSelectIdAlias,
                                   String joinAlias,
                                   String join)
        Description copied from interface: Backend
        Generate SQL code for joining a table to an existing select.
        Specified by:
        sqlJoinSelects in interface Backend
        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
      • assertValidName

        public void assertValidName​(SqlNameType nameType,
                                    String name)
        Description copied from interface: Backend
        Asserts that given string is a valid name and usage.
        Specified by:
        assertValidName in interface Backend
        Parameters:
        nameType - the type/usage of the name
        name - the name
      • jdbcTypeToSqlType

        public SqlType[] jdbcTypeToSqlType​(int jdbcType,
                                           int size,
                                           int scale)
        Description copied from interface: Backend
        Converts the JDBC data type integer to a tentackle backend SqlTypes.

        There may be more than one sqltype returned!

        Specified by:
        jdbcTypeToSqlType in interface Backend
        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
      • toQuotedString

        public String toQuotedString​(String str)
        Description copied from interface: Backend
        Converts a string to a string enclosed in single quotes.
        Specified by:
        toQuotedString in interface Backend
        Parameters:
        str - the string
        Returns:
        the quoted string
      • optimizeSql

        public String optimizeSql​(String sql)
        Description copied from interface: Backend
        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.
        Specified by:
        optimizeSql in interface Backend
        Parameters:
        sql - the original sql code
        Returns:
        the optimized sql code
      • buildSelectSql

        public String buildSelectSql​(String sql,
                                     boolean writeLock,
                                     int limit,
                                     int offset)
        Description copied from interface: Backend
        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.

        Specified by:
        buildSelectSql in interface Backend
        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
      • sqlJoinSelects

        public String sqlJoinSelects​(JoinType type,
                                     boolean addColumns,
                                     String select,
                                     String joinSelect,
                                     String joinSelectIdAlias,
                                     String joinAlias,
                                     String join)
        Description copied from interface: Backend
        Generate SQL code for joining a table to an existing select.
        Specified by:
        sqlJoinSelects in interface Backend
        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
      • isReleaseSavepointSupported

        public boolean isReleaseSavepointSupported()
        Description copied from interface: Backend
        Returns whether the backend supports releasing savepoints explicitly. If not, the savepoints are released when the transaction finishs.
        Specified by:
        isReleaseSavepointSupported in interface Backend
        Returns:
        true if release is supported, else false
      • isClobSupported

        public boolean isClobSupported()
        Description copied from interface: Backend
        Returns whether the backend support CLOB types.
        If not, it will be emulated as VARCHAR with the maximum possible size.
        Specified by:
        isClobSupported in interface Backend
        Returns:
        true if supported, false if treat as varchar
      • isFunctionBasedIndexSupported

        public boolean isFunctionBasedIndexSupported()
        Description copied from interface: Backend
        Returns whether function based indexes are supported.
        Specified by:
        isFunctionBasedIndexSupported in interface Backend
        Returns:
        true if supported
      • isFilteredIndexSupported

        public boolean isFilteredIndexSupported()
        Description copied from interface: Backend
        Returns whether backend supports filtered indexes.
        Specified by:
        isFilteredIndexSupported in interface Backend
        Returns:
        true if supported, false if model will raise an error if filtered index is used
      • setDropIfExistsEnabled

        public void setDropIfExistsEnabled​(boolean dropIfExistsEnabled)
        Description copied from interface: Backend
        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 Backend.isTemporaryName(String) in order to be ignored by the migrator.
        Specified by:
        setDropIfExistsEnabled in interface Backend
        Parameters:
        dropIfExistsEnabled - true if use IF EXISTS if the backend supports it
      • isDropIfExistsEnabled

        public boolean isDropIfExistsEnabled()
        Description copied from interface: Backend
        Returns whether backend should add IF EXISTS for generated DROPs.
        Specified by:
        isDropIfExistsEnabled in interface Backend
        Returns:
        true if IF EXISTS is turned on and supported, false if not supported or turned off
      • toInternalType

        public String toInternalType​(String sqlTypeName)
        Description copied from interface: Backend
        Converts a backend specific type name to an internal name used by driver specific methods.
        Specified by:
        toInternalType in interface Backend
        Parameters:
        sqlTypeName - the original type used in SQL scripts
        Returns:
        the JDBC internal name
      • isArrayOperatorSupported

        public boolean isArrayOperatorSupported​(String operator)
        Description copied from interface: Backend
        Returns whether the backend supports given array operator.
        Specified by:
        isArrayOperatorSupported in interface Backend
        Parameters:
        operator - the array operator
        Returns:
        true if supported
      • setArray

        public void setArray​(PreparedStatement statement,
                             int pos,
                             SqlType type,
                             Collection<?> elements,
                             String operator)
                      throws SQLException
        Description copied from interface: Backend
        Sets an array parameter in a prepared statement.
        Specified by:
        setArray in interface Backend
        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:
        SQLException
      • sqlCreateTableIntroWithoutComment

        protected String sqlCreateTableIntroWithoutComment​(String tableName)
        Generates the first line of a CREATE TABLE statement.
        Parameters:
        tableName - the tablename with optional schema separated by a dot
        Returns:
        the SQL code including the opening bracket
      • createPassword

        protected String createPassword​(char[] password)
        Creates a password string from a password char array.
        Unfortunately, DriverManager.getConnection(String, String, String) requires the password as a string. This method creates a string from a char array and optionally decrypts it. Encrypted passwords are detected by a leading ~. If an unencrypted password must begin with a ~, a double ~~ must be used.
        Parameters:
        password - the probably encrypted password
        Returns:
        the cleartext password
      • normalizeDefault

        protected String normalizeDefault​(String str)
        Normalize the default string to compare.
        Parameters:
        str - the default value as a string, may be null
        Returns:
        the normalized value, never null
      • sqlCreateTableAttributeWithoutComment

        protected String sqlCreateTableAttributeWithoutComment​(String columnName,
                                                               SqlType sqlType,
                                                               int size,
                                                               int scale,
                                                               boolean nullable,
                                                               Object defaultValue,
                                                               boolean primaryKey,
                                                               boolean withTrailingComma)
        Generates the attribute definition of a CREATE TABLE statement.
        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
        primaryKey - true if this is a primary key
        withTrailingComma - true if append a comma
        Returns:
        the SQL code
      • extractWhereClause

        protected String extractWhereClause​(String sql,
                                            int whereOffset)
        Extracts the where clause from a given sql.
        Parameters:
        sql - the sql statement
        whereOffset - the location of WHERE in sql
        Returns:
        the where clause without the keyword WHERE
      • isDropIfExistsSupported

        protected boolean isDropIfExistsSupported()
        Adds "IF EXISTS" to drop clauses, if supported by the backend.
        Makes migration a little more robust in case the same SQL scripts are applied to different databases than those used to generate the migration scripts for.
        Returns:
        true if supported
      • isExceptionStateStartingWith

        protected boolean isExceptionStateStartingWith​(SQLException ex,
                                                       String... prefixes)
        Checks if the exception's state starts with a given string(s).
        Parameters:
        ex - the exception
        prefixes - the prefixes the state starts with
        Returns:
        true if so
      • isExceptionStateMatching

        protected boolean isExceptionStateMatching​(SQLException ex,
                                                   String... states)
        Checks if the exception's state equals given string(s).
        Parameters:
        ex - the exception
        states - the states to check for
        Returns:
        true if matches
      • isExceptionErrorCodeMatching

        protected boolean isExceptionErrorCodeMatching​(SQLException ex,
                                                       int... codes)
        Checks if the exception's error code equals given number(s).
        Parameters:
        ex - the exception
        codes - the error codes to check for
        Returns:
        true if matches