Class Db2

All Implemented Interfaces:
Backend

Backend for DB2.
Author:
harald
  • Constructor Details

    • Db2

      public Db2()
      Creates the DB2 backend.
  • Method Details

    • isMatchingUrl

      public boolean isMatchingUrl(String url)
      Description copied from interface: Backend
      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
    • getName

      public String getName()
      Description copied from interface: Backend
      Gets the name of the backend.
      Returns:
      the name
    • getDriverClassName

      public String getDriverClassName()
      Description copied from interface: Backend
      Gets the JDBC driver class name.
      Returns:
      the class name
    • 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
      Overrides:
      getMaxSize in class AbstractBackend
      Parameters:
      sqlType - the SQL-type
      Returns:
      the maximum size, 0 if unlimited, -1 if type without size
    • getBackendId

      public String getBackendId(Connection connection)
      Description copied from interface: Backend
      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
    • 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
      Overrides:
      isTransientTransactionException in class AbstractBackend
      Parameters:
      ex - the exception
      Returns:
      true if retrying the transaction may succeed
    • isFunctionBasedIndexSupported

      public boolean isFunctionBasedIndexSupported()
      Description copied from interface: Backend
      Returns whether function based indexes are supported.
      Specified by:
      isFunctionBasedIndexSupported in interface Backend
      Overrides:
      isFunctionBasedIndexSupported in class AbstractBackend
      Returns:
      true if supported
    • 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
      Overrides:
      sqlCreateTableIntro in class AbstractBackend
      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
    • 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
      Overrides:
      sqlTypeToString in class AbstractBackend
      Parameters:
      sqlType - the java sql type
      size - the column's size
      Returns:
      the corresponding type string
    • 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
      Overrides:
      jdbcTypeToSqlType in class AbstractBackend
      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:
    • 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
      Overrides:
      sqlCreateColumn in class AbstractBackend
      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
    • sqlCreateTableComment

      public String sqlCreateTableComment(String tableName, String comment)
      Description copied from interface: Backend
      Generates SQL code to create the comment for a table.
      Specified by:
      sqlCreateTableComment in interface Backend
      Overrides:
      sqlCreateTableComment in class AbstractBackend
      Parameters:
      tableName - the table name
      comment - optional comment, null if none
      Returns:
      the SQL code, empty string if comment is created via Backend.sqlCreateTableIntro(java.lang.String, java.lang.String) or Backend.sqlCreateTableClosing(java.lang.String, java.lang.String)
    • sqlCreateColumnComment

      public String sqlCreateColumnComment(String tableName, String columnName, String comment)
      Description copied from interface: Backend
      Generates SQL code to create the comment for an attribute.
      Specified by:
      sqlCreateColumnComment in interface Backend
      Overrides:
      sqlCreateColumnComment in class AbstractBackend
      Parameters:
      tableName - the table name
      columnName - the column name
      comment - optional comment, null if none
      Returns:
      the SQL code, empty string if comment is created via Backend.sqlCreateColumn(java.lang.String, java.lang.String, org.tentackle.sql.SqlType, int, int, boolean, java.lang.Object, boolean, boolean)
    • 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
      Overrides:
      sqlAddColumn in class AbstractBackend
      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
    • 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
      Overrides:
      sqlAlterColumnType in class AbstractBackend
      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
    • 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
      Overrides:
      sqlRenameIndex in class AbstractBackend
      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
    • isDropIfExistsSupported

      protected boolean isDropIfExistsSupported()
      Description copied from class: AbstractBackend
      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.
      Overrides:
      isDropIfExistsSupported in class AbstractBackend
      Returns:
      true if supported