Class AbstractBackend

  • All Implemented Interfaces:
    Backend
    Direct Known Subclasses:
    AbstractSql92Backend

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

      • AbstractBackend

        public AbstractBackend()
    • Method Detail

      • isMatchingName

        public boolean isMatchingName​(java.lang.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
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • createConnection

        public java.sql.Connection createConnection​(java.lang.String url,
                                                    java.lang.String username,
                                                    char[] password)
                                             throws java.sql.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:
        java.sql.SQLException - if connection could not be established
      • createPassword

        protected java.lang.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
      • getMetaData

        public java.sql.DatabaseMetaData[] getMetaData​(BackendInfo backendInfo)
                                                throws java.sql.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:
        java.sql.SQLException - if failed
      • getTableHeaders

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

        public boolean isTemporaryName​(java.lang.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​(java.lang.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​(java.lang.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 java.lang.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 java.lang.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.
      • sqlRequiresExtraCommit

        public boolean sqlRequiresExtraCommit()
        Description copied from interface: Backend
        According to the JDBC-specs Connection.setAutoCommit(boolean)(true) should commit, but some backends require an extra Connection.commit().
        Specified by:
        sqlRequiresExtraCommit in interface Backend
        Returns:
        true if the database needs an extra commit
      • sqlResultSetIsClosedSupported

        public boolean sqlResultSetIsClosedSupported()
        Description copied from interface: Backend
        Determines whether the jdbc driver supports ResultSet.isClosed().
        Specified by:
        sqlResultSetIsClosedSupported in interface Backend
        Returns:
        true if the driver supports it
      • sqlComment

        public java.lang.String sqlComment​(java.lang.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 java.lang.String sqlJoin​(JoinType type,
                                        java.lang.String joinedTableName,
                                        java.lang.String joinedTableAlias,
                                        java.lang.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 java.lang.String sqlFunction​(java.lang.String functionName,
                                            java.lang.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 java.lang.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​(java.sql.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​(java.sql.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
      • 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 java.lang.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​(java.sql.DatabaseMetaData[] metaData,
                                              java.lang.String[] schemas,
                                              java.lang.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,
                                              java.lang.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,
                                                 java.lang.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 java.lang.String sqlCreateTableIntro​(java.lang.String tableName,
                                                    java.lang.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
      • sqlCreateTableIntroWithoutComment

        protected java.lang.String sqlCreateTableIntroWithoutComment​(java.lang.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
      • sqlCreateTableClosing

        public java.lang.String sqlCreateTableClosing​(java.lang.String tableName,
                                                      java.lang.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 java.lang.String sqlAlterTableComment​(java.lang.String tableName,
                                                     java.lang.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 java.lang.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 java.lang.String columnTypeNullDefaultToString​(java.lang.String columnName,
                                                              SqlType sqlType,
                                                              int size,
                                                              int scale,
                                                              boolean nullable,
                                                              java.lang.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 java.lang.String valueToLiteral​(SqlType sqlType,
                                               java.lang.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 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)
        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,
                                      java.lang.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
      • normalizeDefault

        protected java.lang.String normalizeDefault​(java.lang.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
      • getMigrationStrategy

        public MigrationStrategy[] getMigrationStrategy​(ColumnMetaData column,
                                                        java.lang.String columnName,
                                                        java.lang.String comment,
                                                        SqlType sqlType,
                                                        int size,
                                                        int scale,
                                                        boolean nullable,
                                                        java.lang.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 java.lang.String sqlRenameTable​(java.lang.String tableName,
                                               java.lang.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 java.lang.String sqlRenameColumn​(java.lang.String tableName,
                                                java.lang.String oldColumnName,
                                                java.lang.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 java.lang.String sqlRenameIndex​(java.lang.String tableName,
                                               java.lang.String oldIndexName,
                                               java.lang.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 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)
        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 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)
        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 java.lang.String sqlDropColumn​(java.lang.String tableName,
                                              java.lang.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 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)
        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 java.lang.String sqlUpdateToNotNull​(java.lang.String tableName,
                                                   java.lang.String columnName,
                                                   SqlType sqlType,
                                                   java.lang.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
      • sqlCreateTableAttributeWithoutComment

        protected java.lang.String sqlCreateTableAttributeWithoutComment​(java.lang.String columnName,
                                                                         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
        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
      • sqlTypeToString

        public java.lang.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 java.lang.String sqlCreateIndex​(java.lang.String tableName,
                                               java.lang.String indexName,
                                               boolean unique,
                                               java.lang.String filterCondition,
                                               java.lang.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 java.lang.String sqlDropIndex​(java.lang.String schemaName,
                                             java.lang.String tableNameWithoutSchema,
                                             java.lang.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 java.lang.String sqlDropTable​(java.lang.String schemaName,
                                             java.lang.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,
                                   java.lang.StringBuilder select,
                                   java.lang.String joinSelect,
                                   java.lang.String joinSelectIdAlias,
                                   java.lang.String joinAlias,
                                   java.lang.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
      • extractWhereClause

        protected java.lang.String extractWhereClause​(java.lang.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
      • assertValidName

        public void assertValidName​(SqlNameType nameType,
                                    java.lang.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 java.lang.String toQuotedString​(java.lang.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 java.lang.String optimizeSql​(java.lang.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 java.lang.String buildSelectSql​(java.lang.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 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)
        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
      • 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