Class GeneralDatabaseDialect
java.lang.Object
io.debezium.connector.jdbc.dialect.GeneralDatabaseDialect
- All Implemented Interfaces:
DatabaseDialect
- Direct Known Subclasses:
Db2DatabaseDialect,MySqlDatabaseDialect,OracleDatabaseDialect,PostgresDatabaseDialect,SqlServerDatabaseDialect
A generalized ANSI92 compliant
DatabaseDialect implementation.- Author:
- Chris Cranford
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ColumnNamingStrategyprivate final JdbcSinkConnectorConfigprivate static final DateTimeFormatterprivate final org.hibernate.type.descriptor.sql.spi.DdlTypeRegistryprivate final org.hibernate.dialect.Dialectprivate final org.hibernate.engine.jdbc.env.spi.IdentifierHelperprivate final booleanprivate static final org.slf4j.Loggerprivate final TableNamingStrategy -
Constructor Summary
ConstructorsConstructorDescriptionGeneralDatabaseDialect(JdbcSinkConnectorConfig config, org.hibernate.SessionFactory sessionFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddColumnDefaultValue(SinkRecordDescriptor.FieldDescriptor field, StringBuilder columnSpec) intbindValue(SinkRecordDescriptor.FieldDescriptor field, org.hibernate.query.NativeQuery<?> query, int startIndex, Object value) Bind the specified value to the query.private StringcolumnNameEqualsBinding(String fieldName, SinkRecordDescriptor record) protected StringcolumnNameFromField(String fieldName, SinkRecordDescriptor record) protected StringcolumnNameFromField(String fieldName, String prefix, SinkRecordDescriptor record) protected StringcolumnQueryBindingFromField(String fieldName, SinkRecordDescriptor record) getAlterTableStatement(TableDescriptor table, SinkRecordDescriptor record, Set<String> missingFields) Construct aALTER TABLEstatement specific for this dialect.Returns the default format for binding a byte arrayprotected ColumnNamingStrategyprotected JdbcSinkConnectorConfiggetCreateTableStatement(SinkRecordDescriptor record, TableId tableId) Construct aCREATE TABLEstatement specific for this dialect based on the provided record.protected StringgetDatabaseTimeZone(org.hibernate.SessionFactory sessionFactory) protected Stringprotected org.hibernate.dialect.DatabaseVersionintGet 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.protected org.hibernate.engine.jdbc.env.spi.IdentifierHelpergetInsertStatement(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.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.protected StringgetQualifiedTableName(TableId tableId) getSchemaType(org.apache.kafka.connect.data.Schema schema) Resolve the type for a given connect schema.getTableIdFromTopic(org.apache.kafka.connect.sink.SinkRecord record) Resolves the table id for seink record.getTypeName(int jdbcType) Resolves a JDBC type to a given SQL type name.protected StringgetTypeName(int jdbcType, int length) 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.private static booleanisColumnNullable(String columnName, Collection<String> primaryKeyColumnNames, int nullability) protected booleanbooleanReturns 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.protected voidregisterType(Type type) protected voidresolveMissingFields(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.protected StringtoIdentifier(TableId tableId) protected StringtoIdentifier(String text) private static org.hibernate.engine.spi.SessionFactoryImplementorunwrapSessionFactory(org.hibernate.SessionFactory sessionFactory) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.debezium.connector.jdbc.dialect.DatabaseDialect
getAlterTableStatementFieldDelimiter, getMaxTimePrecision, getMaxTimestampPrecision, getTimeQueryBinding
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
DATE_FORMATTER
-
connectorConfig
-
dialect
private final org.hibernate.dialect.Dialect dialect -
ddlTypeRegistry
private final org.hibernate.type.descriptor.sql.spi.DdlTypeRegistry ddlTypeRegistry -
identifierHelper
private final org.hibernate.engine.jdbc.env.spi.IdentifierHelper identifierHelper -
tableNamingStrategy
-
columnNamingStrategy
-
typeRegistry
-
jdbcTimeZone
private final boolean jdbcTimeZone
-
-
Constructor Details
-
GeneralDatabaseDialect
public GeneralDatabaseDialect(JdbcSinkConnectorConfig config, org.hibernate.SessionFactory sessionFactory)
-
-
Method Details
-
getTableIdFromTopic
Description copied from interface:DatabaseDialectResolves the table id for seink record.- Specified by:
getTableIdFromTopicin interfaceDatabaseDialect- Parameters:
record- the sink record.- Returns:
- the parsed table identifier, never
null.
-
tableExists
Description copied from interface:DatabaseDialectCheck whether the specified table exists.- Specified by:
tableExistsin interfaceDatabaseDialect- 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
Description copied from interface:DatabaseDialectRead the table structure data from the database.- Specified by:
readTablein interfaceDatabaseDialect- 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
Description copied from interface:DatabaseDialectResolves what fields are missing from the provided table compared against the incoming record.- Specified by:
resolveMissingFieldsin interfaceDatabaseDialect- 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
Description copied from interface:DatabaseDialectConstruct aCREATE TABLEstatement specific for this dialect based on the provided record.- Specified by:
getCreateTableStatementin interfaceDatabaseDialect- 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
public String getAlterTableStatement(TableDescriptor table, SinkRecordDescriptor record, Set<String> missingFields) Description copied from interface:DatabaseDialectConstruct aALTER TABLEstatement specific for this dialect.- Specified by:
getAlterTableStatementin interfaceDatabaseDialect- 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
-
getInsertStatement
Description copied from interface:DatabaseDialectConstruct aINSERT INTOstatement specific for this dialect.- Specified by:
getInsertStatementin interfaceDatabaseDialect- 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
Description copied from interface:DatabaseDialectConstruct aUPSERTstatement specific for this dialect.- Specified by:
getUpsertStatementin interfaceDatabaseDialect- 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
Description copied from interface:DatabaseDialectConstruct aUPDATEstatement specific for this dialect.- Specified by:
getUpdateStatementin interfaceDatabaseDialect- 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
Description copied from interface:DatabaseDialectConstruct aDELETEstatement specific for this dialect.- Specified by:
getDeleteStatementin interfaceDatabaseDialect- 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
-
bindValue
public int bindValue(SinkRecordDescriptor.FieldDescriptor field, org.hibernate.query.NativeQuery<?> query, int startIndex, Object value) Description copied from interface:DatabaseDialectBind the specified value to the query.- Specified by:
bindValuein interfaceDatabaseDialect- 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
-
getMaxVarcharLengthInKey
public int getMaxVarcharLengthInKey()Description copied from interface:DatabaseDialectGets the maximum length of a VARCHAR field in a primary key column.- Specified by:
getMaxVarcharLengthInKeyin interfaceDatabaseDialect- Returns:
- maximum varchar field length when participating in the primary key
-
getMaxNVarcharLengthInKey
public int getMaxNVarcharLengthInKey()Description copied from interface:DatabaseDialectGets the maximum length of a nationalized VARCHAR field in a primary key column.- Specified by:
getMaxNVarcharLengthInKeyin interfaceDatabaseDialect- Returns:
- maximum varchar field length when participating in the primary key
-
getMaxVarbinaryLength
public int getMaxVarbinaryLength()Description copied from interface:DatabaseDialectGets the maximum length of a variable binary field in a primary key column.- Specified by:
getMaxVarbinaryLengthin interfaceDatabaseDialect- Returns:
- maximum field length when participating in the primary key
-
isTimeZoneSet
public boolean isTimeZoneSet()Description copied from interface:DatabaseDialectReturns whether the user has specified a time zone JDBC property or whether the connector configuration propertydatabase.time_zonehas been specified.- Specified by:
isTimeZoneSetin interfaceDatabaseDialect- Returns:
- true if the properties have been specified; false otherwise.
-
shouldBindTimeWithTimeZoneAsDatabaseTimeZone
public boolean shouldBindTimeWithTimeZoneAsDatabaseTimeZone()Description copied from interface:DatabaseDialectReturns whether a time with time zone details be bound using the database time zone.- Specified by:
shouldBindTimeWithTimeZoneAsDatabaseTimeZonein interfaceDatabaseDialect- Returns:
- true if the value should be shifted; false otherwise (the default).
-
getSchemaType
Description copied from interface:DatabaseDialectResolve the type for a given connect schema.- Specified by:
getSchemaTypein interfaceDatabaseDialect- Parameters:
schema- connect schema, nevernull- Returns:
- resolved type to use
-
getVersion
public org.hibernate.dialect.DatabaseVersion getVersion()Description copied from interface:DatabaseDialectGets the dialect's database version.- Specified by:
getVersionin interfaceDatabaseDialect- Returns:
- database version details
-
getDefaultDecimalPrecision
public int getDefaultDecimalPrecision()Description copied from interface:DatabaseDialectGet the default decimal data type precision for the dialect.- Specified by:
getDefaultDecimalPrecisionin interfaceDatabaseDialect- Returns:
- default decimal precision
-
getDefaultTimestampPrecision
public int getDefaultTimestampPrecision()Description copied from interface:DatabaseDialectGet the default timestamp precision for the dialect.- Specified by:
getDefaultTimestampPrecisionin interfaceDatabaseDialect- Returns:
- default timestamp precision
-
isNegativeScaleAllowed
public boolean isNegativeScaleAllowed()Description copied from interface:DatabaseDialectReturns whether the dialect permits negative scale.- Specified by:
isNegativeScaleAllowedin interfaceDatabaseDialect- Returns:
- true if the dialect permits using negative scale values
-
getTypeName
Description copied from interface:DatabaseDialectResolves a JDBC type to a given SQL type name.- Specified by:
getTypeNamein interfaceDatabaseDialect- Parameters:
jdbcType- the JDBC type- Returns:
- the resolved type name
-
getTypeName
Description copied from interface:DatabaseDialectResolves a JDBC type with optional size parameters to a given SQL type name.- Specified by:
getTypeNamein interfaceDatabaseDialect- Parameters:
jdbcType- the JDBC typesize- the optional size parameters, should not benull- Returns:
- the resolved type name
-
getByteArrayFormat
Description copied from interface:DatabaseDialectReturns the default format for binding a byte array- Specified by:
getByteArrayFormatin interfaceDatabaseDialect- Returns:
- the format for binding a byte array
-
getFormattedBoolean
Description copied from interface:DatabaseDialectFormat a boolean.- Specified by:
getFormattedBooleanin interfaceDatabaseDialect- Parameters:
value- the boolean value- Returns:
- the formatted string value
-
getFormattedDate
Description copied from interface:DatabaseDialectFormat a date.- Specified by:
getFormattedDatein interfaceDatabaseDialect- Parameters:
value- the value to tbe formatted, nevernull- Returns:
- the formatted string value
-
getFormattedTime
Description copied from interface:DatabaseDialectFormat a time.- Specified by:
getFormattedTimein interfaceDatabaseDialect- Parameters:
value- the value to be formatted, nevernull- Returns:
- the formatted string value
-
getFormattedTimeWithTimeZone
Description copied from interface:DatabaseDialectFormat a time with time zone.- Specified by:
getFormattedTimeWithTimeZonein interfaceDatabaseDialect- Parameters:
value- the value to be formatted, nevernull- Returns:
- the formatted string value
-
getFormattedDateTime
Description copied from interface:DatabaseDialectFormat a date and time.- Specified by:
getFormattedDateTimein interfaceDatabaseDialect- Parameters:
value- the value to be formatted, nevernull- Returns:
- the formatted string value
-
getFormattedDateTimeWithNanos
Description copied from interface:DatabaseDialectFormat a date and time with nonoseconds.- Specified by:
getFormattedDateTimeWithNanosin interfaceDatabaseDialect- Parameters:
value- the value to be formatted, nevernull- Returns:
- the formatted string value
-
getFormattedTimestamp
Description copied from interface:DatabaseDialectFormat a timestamp.- Specified by:
getFormattedTimestampin interfaceDatabaseDialect- Parameters:
value- the value to be formatted, nevernull- Returns:
- the formatted string value
-
getFormattedTimestampWithTimeZone
Description copied from interface:DatabaseDialectFormat a timestamp with time zone.- Specified by:
getFormattedTimestampWithTimeZonein interfaceDatabaseDialect- Parameters:
value- the value to be formatted, nevernull- Returns:
- the formatted string value.
-
getTypeName
-
getDatabaseTimeZone
-
getDatabaseTimeZoneQuery
-
getDatabaseTimeZoneQueryResult
- Throws:
SQLException
-
registerTypes
protected void registerTypes() -
registerType
-
getColumnNamingStrategy
-
getConfig
-
getDatabaseVersion
protected org.hibernate.dialect.DatabaseVersion getDatabaseVersion() -
getIdentifierHelper
protected org.hibernate.engine.jdbc.env.spi.IdentifierHelper getIdentifierHelper() -
addColumnDefaultValue
protected void addColumnDefaultValue(SinkRecordDescriptor.FieldDescriptor field, StringBuilder columnSpec) -
columnQueryBindingFromField
-
columnNameFromField
-
columnNameFromField
-
toIdentifier
-
toIdentifier
-
isIdentifierUppercaseWhenNotQuoted
protected boolean isIdentifierUppercaseWhenNotQuoted() -
getQualifiedTableName
-
columnNameEqualsBinding
-
isColumnNullable
private static boolean isColumnNullable(String columnName, Collection<String> primaryKeyColumnNames, int nullability) -
unwrapSessionFactory
private static org.hibernate.engine.spi.SessionFactoryImplementor unwrapSessionFactory(org.hibernate.SessionFactory sessionFactory)
-