Class H2

All Implemented Interfaces:
Backend

Backend for the H2 Database.
  • Field Details

  • Constructor Details

    • H2

      public H2()
      Creates the H2 backend.
  • Method Details

    • getReservedWords

      public Set<String> getReservedWords()
      Description copied from interface: Backend
      Gets the list of reserved words for this backend.
      Specified by:
      getReservedWords in interface Backend
      Overrides:
      getReservedWords in class AbstractSql92Backend
      Returns:
      the set of reserved words
    • 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
    • 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
    • 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
      Overrides:
      isReleaseSavepointSupported in class AbstractBackend
      Returns:
      true if release is supported, else false
    • 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
      Overrides:
      isReservedSchemaName in class AbstractBackend
      Parameters:
      name - the schema name
      Returns:
      true if reserved by backend
    • 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
    • isUUIDSupported

      public boolean isUUIDSupported()
      Description copied from interface: Backend
      Returns whether the backend supports the UUID natively via JDBC setObject/getObject.
      Specified by:
      isUUIDSupported in interface Backend
      Overrides:
      isUUIDSupported in class AbstractBackend
      Returns:
      true if supported, false if mapped to VARCHAR(36)
    • isAliasRequiredForSubSelect

      public boolean isAliasRequiredForSubSelect()
      Description copied from interface: Backend
      Returns whether backend requires an alias for a sub-select.
      Specified by:
      isAliasRequiredForSubSelect in interface Backend
      Overrides:
      isAliasRequiredForSubSelect in class AbstractBackend
      Returns:
      true if sub-select needs an alias.
    • buildSelectSql

      public void buildSelectSql(StringBuilder sqlBuilder, 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 [SELECT] FROM... WHERE... ORDER BY....
      It is decorated with a leading SELECT, if missing, plus optional clauses like for the given parameters.

      Specified by:
      buildSelectSql in interface Backend
      Overrides:
      buildSelectSql in class AbstractSql92Backend
      Parameters:
      sqlBuilder - the sql builder, initially containing the inner sql without leading SELECT.
      writeLock - true select should write lock
      limit - the limit value, ≤ 0 if no limit clause
      offset - the offset value, ≤ 0 if no offset clause
    • setLeadingSelectParameters

      public int setLeadingSelectParameters(BackendPreparedStatement stmt, int limit, int offset)
      Description copied from interface: Backend
      Sets optional parameters before applying the original parameters.
      Specified by:
      setLeadingSelectParameters in interface Backend
      Overrides:
      setLeadingSelectParameters in class AbstractSql92Backend
      Parameters:
      stmt - the prepared statement
      limit - the limit value, ≤ 0 if no limit clause
      offset - the offset value, ≤ 0 if no offset clause
      Returns:
      the next parameter index
    • setTrailingSelectParameters

      public int setTrailingSelectParameters(BackendPreparedStatement stmt, int index, int limit, int offset)
      Description copied from interface: Backend
      Sets optional parameters after applying the original parameters.
      Specified by:
      setTrailingSelectParameters in interface Backend
      Overrides:
      setTrailingSelectParameters in class AbstractSql92Backend
      Parameters:
      stmt - the prepared statement
      index - the first parameter index
      limit - the limit value, ≤ 0 if no limit clause
      offset - the offset value, ≤ 0 if no offset clause
      Returns:
      the next parameter index
    • 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
    • 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
      Overrides:
      getDefaultSchema in class AbstractBackend
      Returns:
      the default schema, null if none
    • 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:
    • 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
    • isSequenceSupported

      public boolean isSequenceSupported()
      Description copied from interface: Backend
      True if backend provides locking-free sequences.
      Sequences must not take part in transactions, i.e. no read- or write-locks!
      Specified by:
      isSequenceSupported in interface Backend
      Overrides:
      isSequenceSupported in class AbstractSql92Backend
      Returns:
      true if database supports sequences
    • sqlNextFromSequence

      public String sqlNextFromSequence(String name)
      Description copied from interface: Backend
      Creates the SQL string to retrieve the next id from a sequence.
      Specified by:
      sqlNextFromSequence in interface Backend
      Overrides:
      sqlNextFromSequence in class AbstractSql92Backend
      Parameters:
      name - the name of the sequence
      Returns:
      the SQL code
    • sqlCreateSequence

      public String sqlCreateSequence(String name, Long start, Long increment)
      Description copied from interface: Backend
      Creates the SQL string to create a sequence.
      Specified by:
      sqlCreateSequence in interface Backend
      Overrides:
      sqlCreateSequence in class AbstractSql92Backend
      Parameters:
      name - the sequence name
      start - the optional start value, defaults to 1
      increment - the optional increment, defaults to 1
      Returns:
      the SQL code
    • sqlCreateSequenceComment

      public String sqlCreateSequenceComment(String name, String comment)
      Description copied from interface: Backend
      Creates the SQL string to comment a sequence.
      Specified by:
      sqlCreateSequenceComment in interface Backend
      Overrides:
      sqlCreateSequenceComment in class AbstractSql92Backend
      Parameters:
      name - the sequence name
      comment - the comment
      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)
    • 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
    • sqlAlterColumnNullConstraint

      public String sqlAlterColumnNullConstraint(String tableName, String columnName, boolean nullable)
      Description copied from interface: Backend
      Generates sql code to change the null-constraint of a column.
      Specified by:
      sqlAlterColumnNullConstraint in interface Backend
      Overrides:
      sqlAlterColumnNullConstraint in class AbstractBackend
      Parameters:
      tableName - the tablename
      columnName - the new column name
      nullable - true if NULL, else NOT NULL
      Returns:
      the SQL code, null if need Backend.sqlAlterColumnType(java.lang.String, java.lang.String, java.lang.String, org.tentackle.sql.SqlType, int, int, boolean, java.lang.Object)
    • 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
      Overrides:
      isArrayOperatorSupported in class AbstractBackend
      Parameters:
      operator - the array operator
      Returns:
      true if supported
    • 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
      Overrides:
      getMigrationStrategy in class AbstractBackend
      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
    • isDatabaseInMemory

      public boolean isDatabaseInMemory(String url)
      Description copied from interface: Backend
      Returns whether the URL denotes an in-memory database.
      Used by test suites to decide whether to populate the database before running the tests.
      Specified by:
      isDatabaseInMemory in interface Backend
      Overrides:
      isDatabaseInMemory in class AbstractBackend
      Parameters:
      url - the JDBC url
      Returns:
      true if in-memory
    • extractWhereClause

      protected String extractWhereClause(String sql, int whereOffset)
      Description copied from class: AbstractBackend
      Extracts the where clause from a given sql.
      Overrides:
      extractWhereClause in class AbstractBackend
      Parameters:
      sql - the sql statement
      whereOffset - the location of WHERE in sql
      Returns:
      the where clause without the keyword WHERE
    • 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