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 Summary
Modifier and TypeMethodDescriptionintbindValue(SinkRecordDescriptor.FieldDescriptor field, org.hibernate.query.NativeQuery<?> query, int startIndex, Object value) Bind the specified value to the query.getAlterTableStatement(TableDescriptor table, SinkRecordDescriptor record, Set<String> missingFields) Construct aALTER TABLEstatement specific for this dialect.default StringGets the field delimeter used when contructingALTER TABLEstatements.Returns the default format for binding a byte arraygetCreateTableStatement(SinkRecordDescriptor record, TableId tableId) Construct aCREATE TABLEstatement specific for this dialect based on the provided record.intGet the default decimal data type precision for the dialect.intGet the default timestamp precision for the dialect.getDeleteStatement(TableDescriptor table, SinkRecordDescriptor record) Construct aDELETEstatement specific for this dialect.getFormattedBoolean(boolean value) Format a boolean.getFormattedDate(TemporalAccessor value) Format a date.Format a date and time.Format a date and time with nonoseconds.getFormattedTime(TemporalAccessor value) Format a time.Format a timestamp.Format a timestamp with time zone.Format a time with time zone.getInsertStatement(TableDescriptor table, SinkRecordDescriptor record) Construct aINSERT INTOstatement specific for this dialect.intGets the maximum length of a nationalized VARCHAR field in a primary key column.default intGets the maximum precision allowed for a dialect's time data type.default intGets the maximum precision allowed for a dialect's timestamp data type.intGets the maximum length of a variable binary field in a primary key column.intGets the maximum length of a VARCHAR field in a primary key column.getQueryBindingWithValueCast(ColumnDescriptor column, org.apache.kafka.connect.data.Schema schema, Type type) Returns the SQL binding fragment for a column, schema, and type mapping.getSchemaType(org.apache.kafka.connect.data.Schema schema) Resolve the type for a given connect schema.getTableId(String tableName) Resolves the table id for table name.default StringgetTypeName(int jdbcType) Resolves a JDBC type to a given SQL type name.getTypeName(int jdbcType, org.hibernate.engine.jdbc.Size size) Resolves a JDBC type with optional size parameters to a given SQL type name.getUpdateStatement(TableDescriptor table, SinkRecordDescriptor record) Construct aUPDATEstatement specific for this dialect.getUpsertStatement(TableDescriptor table, SinkRecordDescriptor record) Construct aUPSERTstatement specific for this dialect.org.hibernate.dialect.DatabaseVersionGets the dialect's database version.booleanReturns whether the dialect permits negative scale.booleanReturns whether the user has specified a time zone JDBC property or whether the connector configuration propertydatabase.time_zonehas been specified.readTable(Connection connection, TableId tableId) Read the table structure data from the database.resolveMissingFields(SinkRecordDescriptor record, TableDescriptor table) Resolves what fields are missing from the provided table compared against the incoming record.booleanReturns whether a time with time zone details be bound using the database time zone.booleantableExists(Connection connection, TableId tableId) Check whether the specified table exists.
-
Method Details
-
getVersion
org.hibernate.dialect.DatabaseVersion getVersion()Gets the dialect's database version.- Returns:
- database version details
-
getTableId
Resolves the table id for table name.- Parameters:
tableName- the table name.- Returns:
- the parsed table identifier, never
null.
-
tableExists
Check whether the specified table exists.- Parameters:
connection- the database connection to be used, should not benull.tableId- the table identifier, should not benull.- Returns:
- true if the table exists, false otherwise
- Throws:
SQLException- if a database exception occurs
-
readTable
Read the table structure data from the database.- Parameters:
connection- the database connection to be used, should not benull.tableId- the table identifier, should not benull.- Returns:
- the table relational model if it exists
- Throws:
SQLException- if the table does not exist or a database exception occurs
-
resolveMissingFields
Resolves what fields are missing from the provided table compared against the incoming record.- Parameters:
record- the current sink record being processed, should not benulltable- the relational table model, should not benull- Returns:
- a collection of field names that are missing from the database table, can be
empty.
-
getCreateTableStatement
Construct aCREATE TABLEstatement specific for this dialect based on the provided record.- Parameters:
record- the current sink record being processed, should not benulltableId- the tableidentifier to be used, should not benull- Returns:
- the create table SQL statement to be executed, never
null
-
getAlterTableStatement
String getAlterTableStatement(TableDescriptor table, SinkRecordDescriptor record, Set<String> missingFields) Construct aALTER TABLEstatement specific for this dialect.- Parameters:
table- the current relational table model, should not benullrecord- the current sink record being processed, should not benullmissingFields- the fields that have been determined as missing from the relational model, should not benull- Returns:
- the alter table SQL statement to be executed, never
null - Throws:
IllegalArgumentException- if called with an empty set of missing fields
-
getAlterTableStatementFieldDelimiter
Gets the field delimeter used when contructingALTER TABLEstatements.- Returns:
- the field delimeter for alter table SQL statement
-
getInsertStatement
Construct aINSERT INTOstatement specific for this dialect.- Parameters:
table- the current relational table model, should not benullrecord- the current sink record being processed, should not benull- Returns:
- the insert SQL statement to be executed, never
null
-
getUpsertStatement
Construct aUPSERTstatement specific for this dialect.- Parameters:
table- the current relational table model, should not benullrecord- the current sink record being processed, should not benull- Returns:
- the upsert SQL statement to be executed, never
null
-
getUpdateStatement
Construct aUPDATEstatement specific for this dialect.- Parameters:
table- the current relational table model, should not benullrecord- the current sink record being processed, should not benull- Returns:
- the update SQL statement to be executed, never
null
-
getDeleteStatement
Construct aDELETEstatement specific for this dialect.- Parameters:
table- the current relational table model, should not benullrecord- the current sink record being processed, should not benull- Returns:
- the delete SQL statement to be executed, never
null
-
getQueryBindingWithValueCast
String getQueryBindingWithValueCast(ColumnDescriptor column, org.apache.kafka.connect.data.Schema schema, Type type) Returns the SQL binding fragment for a column, schema, and type mapping.- Parameters:
column- the relational column type, nevernullschema- the field schema type, nevernulltype- the resolved field type, nevernull- Returns:
- the query binding SQL fragment
-
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 propertydatabase.time_zonehas 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
-
getByteArrayFormat
String getByteArrayFormat()Returns the default format for binding a byte array- Returns:
- the format for binding a byte array
-
getFormattedBoolean
Format a boolean.- Parameters:
value- the boolean value- Returns:
- the formatted string value
-
getFormattedDate
Format a date.- Parameters:
value- the value to tbe formatted, nevernull- Returns:
- the formatted string value
-
getFormattedTime
Format a time.- Parameters:
value- the value to be formatted, nevernull- Returns:
- the formatted string value
-
getFormattedTimeWithTimeZone
Format a time with time zone.- Parameters:
value- the value to be formatted, nevernull- Returns:
- the formatted string value
-
getFormattedDateTime
Format a date and time.- Parameters:
value- the value to be formatted, nevernull- Returns:
- the formatted string value
-
getFormattedDateTimeWithNanos
Format a date and time with nonoseconds.- Parameters:
value- the value to be formatted, nevernull- Returns:
- the formatted string value
-
getFormattedTimestamp
Format a timestamp.- Parameters:
value- the value to be formatted, nevernull- Returns:
- the formatted string value
-
getFormattedTimestampWithTimeZone
Format a timestamp with time zone.- Parameters:
value- the value to be formatted, nevernull- Returns:
- the formatted string value.
-
getSchemaType
Resolve the type for a given connect schema.- Parameters:
schema- connect schema, nevernull- Returns:
- resolved type to use
-
getTypeName
Resolves a JDBC type to a given SQL type name.- Parameters:
jdbcType- the JDBC type- Returns:
- the resolved type name
-
getTypeName
Resolves a JDBC type with optional size parameters to a given SQL type name.- Parameters:
jdbcType- the JDBC typesize- the optional size parameters, should not benull- 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 benullquery- the query the value is to be bound, should never benullstartIndex- the starting index of the parameter bindingvalue- the value to be bound, may benull- Returns:
- the next bind offset that should be used when binding multiple values
-