Interface DatabaseDialect

All Known Implementing Classes:
Db2DatabaseDialect, GeneralDatabaseDialect, MySqlDatabaseDialect, OracleDatabaseDialect, PostgresDatabaseDialect, SqlServerDatabaseDialect

public interface DatabaseDialect
Represents a dialect of SQL implemented by a particular RDBMS. Subclasses of this contract implement database-specific behavior, should be immutable, and is capable of registering overrides to default behavior where applicable.
Author:
Chris Cranford
  • Method Details

    • getVersion

      org.hibernate.dialect.DatabaseVersion getVersion()
      Gets the dialect's database version.
      Returns:
      database version details
    • getTableIdFromTopic

      TableId getTableIdFromTopic(org.apache.kafka.connect.sink.SinkRecord record)
      Resolves the table id for seink record.
      Parameters:
      record - the sink record.
      Returns:
      the parsed table identifier, never null.
    • tableExists

      boolean tableExists(Connection connection, TableId tableId) throws SQLException
      Check whether the specified table exists.
      Parameters:
      connection - the database connection to be used, should not be null.
      tableId - the table identifier, should not be null.
      Returns:
      true if the table exists, false otherwise
      Throws:
      SQLException - if a database exception occurs
    • readTable

      TableDescriptor readTable(Connection connection, TableId tableId) throws SQLException
      Read the table structure data from the database.
      Parameters:
      connection - the database connection to be used, should not be null.
      tableId - the table identifier, should not be null.
      Returns:
      the table relational model if it exists
      Throws:
      SQLException - if the table does not exist or a database exception occurs
    • resolveMissingFields

      Set<String> resolveMissingFields(SinkRecordDescriptor record, TableDescriptor table)
      Resolves what fields are missing from the provided table compared against the incoming record.
      Parameters:
      record - the current sink record being processed, should not be null
      table - the relational table model, should not be null
      Returns:
      a collection of field names that are missing from the database table, can be empty.
    • getCreateTableStatement

      String getCreateTableStatement(SinkRecordDescriptor record, TableId tableId)
      Construct a CREATE TABLE statement specific for this dialect based on the provided record.
      Parameters:
      record - the current sink record being processed, should not be null
      tableId - the tableidentifier to be used, should not be null
      Returns:
      the create table SQL statement to be executed, never null
    • getAlterTableStatement

      String getAlterTableStatement(TableDescriptor table, SinkRecordDescriptor record, Set<String> missingFields)
      Construct a ALTER TABLE statement specific for this dialect.
      Parameters:
      table - the current relational table model, should not be null
      record - the current sink record being processed, should not be null
      missingFields - the fields that have been determined as missing from the relational model, should not be null
      Returns:
      the alter table SQL statement to be executed, never null
      Throws:
      IllegalArgumentException - if called with an empty set of missing fields
    • getAlterTableStatementFieldDelimiter

      default String getAlterTableStatementFieldDelimiter()
      Gets the field delimeter used when contructing ALTER TABLE statements.
      Returns:
      the field delimeter for alter table SQL statement
    • getInsertStatement

      String getInsertStatement(TableDescriptor table, SinkRecordDescriptor record)
      Construct a INSERT INTO statement specific for this dialect.
      Parameters:
      table - the current relational table model, should not be null
      record - the current sink record being processed, should not be null
      Returns:
      the insert SQL statement to be executed, never null
    • getUpsertStatement

      String getUpsertStatement(TableDescriptor table, SinkRecordDescriptor record)
      Construct a UPSERT statement specific for this dialect.
      Parameters:
      table - the current relational table model, should not be null
      record - the current sink record being processed, should not be null
      Returns:
      the upsert SQL statement to be executed, never null
    • getUpdateStatement

      String getUpdateStatement(TableDescriptor table, SinkRecordDescriptor record)
      Construct a UPDATE statement specific for this dialect.
      Parameters:
      table - the current relational table model, should not be null
      record - the current sink record being processed, should not be null
      Returns:
      the update SQL statement to be executed, never null
    • getDeleteStatement

      String getDeleteStatement(TableDescriptor table, SinkRecordDescriptor record)
      Construct a DELETE statement specific for this dialect.
      Parameters:
      table - the current relational table model, should not be null
      record - the current sink record being processed, should not be null
      Returns:
      the delete SQL statement to be executed, never null
    • getMaxVarcharLengthInKey

      int getMaxVarcharLengthInKey()
      Gets the maximum length of a VARCHAR field in a primary key column.
      Returns:
      maximum varchar field length when participating in the primary key
    • getMaxNVarcharLengthInKey

      int getMaxNVarcharLengthInKey()
      Gets the maximum length of a nationalized VARCHAR field in a primary key column.
      Returns:
      maximum varchar field length when participating in the primary key
    • getMaxVarbinaryLength

      int getMaxVarbinaryLength()
      Gets the maximum length of a variable binary field in a primary key column.
      Returns:
      maximum field length when participating in the primary key
    • isTimeZoneSet

      boolean isTimeZoneSet()
      Returns whether the user has specified a time zone JDBC property or whether the connector configuration property database.time_zone has been specified.
      Returns:
      true if the properties have been specified; false otherwise.
    • shouldBindTimeWithTimeZoneAsDatabaseTimeZone

      boolean shouldBindTimeWithTimeZoneAsDatabaseTimeZone()
      Returns whether a time with time zone details be bound using the database time zone.
      Returns:
      true if the value should be shifted; false otherwise (the default).
    • getMaxTimePrecision

      default int getMaxTimePrecision()
      Gets the maximum precision allowed for a dialect's time data type.
      Returns:
      maximum time precision
    • getMaxTimestampPrecision

      default int getMaxTimestampPrecision()
      Gets the maximum precision allowed for a dialect's timestamp data type.
      Returns:
      maximum timestamp precision
    • getDefaultDecimalPrecision

      int getDefaultDecimalPrecision()
      Get the default decimal data type precision for the dialect.
      Returns:
      default decimal precision
    • getDefaultTimestampPrecision

      int getDefaultTimestampPrecision()
      Get the default timestamp precision for the dialect.
      Returns:
      default timestamp precision
    • isNegativeScaleAllowed

      boolean isNegativeScaleAllowed()
      Returns whether the dialect permits negative scale.
      Returns:
      true if the dialect permits using negative scale values
    • getTimeQueryBinding

      default String getTimeQueryBinding()
    • getByteArrayFormat

      String getByteArrayFormat()
      Returns the default format for binding a byte array
      Returns:
      the format for binding a byte array
    • getFormattedBoolean

      String getFormattedBoolean(boolean value)
      Format a boolean.
      Parameters:
      value - the boolean value
      Returns:
      the formatted string value
    • getFormattedDate

      String getFormattedDate(TemporalAccessor value)
      Format a date.
      Parameters:
      value - the value to tbe formatted, never null
      Returns:
      the formatted string value
    • getFormattedTime

      String getFormattedTime(TemporalAccessor value)
      Format a time.
      Parameters:
      value - the value to be formatted, never null
      Returns:
      the formatted string value
    • getFormattedTimeWithTimeZone

      String getFormattedTimeWithTimeZone(String value)
      Format a time with time zone.
      Parameters:
      value - the value to be formatted, never null
      Returns:
      the formatted string value
    • getFormattedDateTime

      String getFormattedDateTime(TemporalAccessor value)
      Format a date and time.
      Parameters:
      value - the value to be formatted, never null
      Returns:
      the formatted string value
    • getFormattedDateTimeWithNanos

      String getFormattedDateTimeWithNanos(TemporalAccessor value)
      Format a date and time with nonoseconds.
      Parameters:
      value - the value to be formatted, never null
      Returns:
      the formatted string value
    • getFormattedTimestamp

      String getFormattedTimestamp(TemporalAccessor value)
      Format a timestamp.
      Parameters:
      value - the value to be formatted, never null
      Returns:
      the formatted string value
    • getFormattedTimestampWithTimeZone

      String getFormattedTimestampWithTimeZone(String value)
      Format a timestamp with time zone.
      Parameters:
      value - the value to be formatted, never null
      Returns:
      the formatted string value.
    • getSchemaType

      Type getSchemaType(org.apache.kafka.connect.data.Schema schema)
      Resolve the type for a given connect schema.
      Parameters:
      schema - connect schema, never null
      Returns:
      resolved type to use
    • getTypeName

      String getTypeName(int jdbcType)
      Resolves a JDBC type to a given SQL type name.
      Parameters:
      jdbcType - the JDBC type
      Returns:
      the resolved type name
    • getTypeName

      String getTypeName(int jdbcType, org.hibernate.engine.jdbc.Size size)
      Resolves a JDBC type with optional size parameters to a given SQL type name.
      Parameters:
      jdbcType - the JDBC type
      size - the optional size parameters, should not be null
      Returns:
      the resolved type name
    • bindValue

      int bindValue(SinkRecordDescriptor.FieldDescriptor field, org.hibernate.query.NativeQuery<?> query, int startIndex, Object value)
      Bind the specified value to the query.
      Parameters:
      field - the field being bound, should never be null
      query - the query the value is to be bound, should never be null
      startIndex - the starting index of the parameter binding
      value - the value to be bound, may be null
      Returns:
      the next bind offset that should be used when binding multiple values