Skip to content

Commit

Permalink
[Improve][Jdbc] Remove MysqlType references in JdbcDialect (#7333)
Browse files Browse the repository at this point in the history
  • Loading branch information
whhe authored Aug 7, 2024
1 parent 191d9e1 commit 16eeb1c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.mysql.cj.MysqlType;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
Expand Down Expand Up @@ -532,8 +530,7 @@ default String buildAlterTableSql(
"ALTER TABLE %s drop column %s", tableName, quoteIdentifier(oldColumnName));
}
TypeConverter<?> typeConverter = ConverterLoader.loadTypeConverter(dialectName());
BasicTypeDefine<MysqlType> typeBasicTypeDefine =
(BasicTypeDefine<MysqlType>) typeConverter.reconvert(newColumn);
BasicTypeDefine typeBasicTypeDefine = (BasicTypeDefine) typeConverter.reconvert(newColumn);

String basicSql = buildAlterTableBasicSql(alterOperation, tableName);
basicSql =
Expand Down Expand Up @@ -616,8 +613,7 @@ default String decorateWithColumnNameAndType(
* @param typeBasicTypeDefine type basic type define of new column
* @return alter table sql with nullable for sink table
*/
default String decorateWithNullable(
String basicSql, BasicTypeDefine<MysqlType> typeBasicTypeDefine) {
default String decorateWithNullable(String basicSql, BasicTypeDefine typeBasicTypeDefine) {
StringBuilder sql = new StringBuilder(basicSql);
if (typeBasicTypeDefine.isNullable()) {
sql.append("NULL ");
Expand All @@ -634,8 +630,7 @@ default String decorateWithNullable(
* @param typeBasicTypeDefine type basic type define of new column
* @return alter table sql with default value for sink table
*/
default String decorateWithDefaultValue(
String basicSql, BasicTypeDefine<MysqlType> typeBasicTypeDefine) {
default String decorateWithDefaultValue(String basicSql, BasicTypeDefine typeBasicTypeDefine) {
Object defaultValue = typeBasicTypeDefine.getDefaultValue();
if (Objects.nonNull(defaultValue)
&& needsQuotesWithDefaultValue(typeBasicTypeDefine.getColumnType())
Expand All @@ -656,8 +651,7 @@ && needsQuotesWithDefaultValue(typeBasicTypeDefine.getColumnType())
* @param typeBasicTypeDefine type basic type define of new column
* @return alter table sql with comment for sink table
*/
default String decorateWithComment(
String basicSql, BasicTypeDefine<MysqlType> typeBasicTypeDefine) {
default String decorateWithComment(String basicSql, BasicTypeDefine typeBasicTypeDefine) {
String comment = typeBasicTypeDefine.getComment();
StringBuilder sql = new StringBuilder(basicSql);
if (StringUtils.isNotBlank(comment)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,12 @@ public void refreshTableSchemaBySchemaChangeEvent(
}

@Override
public String decorateWithComment(
String basicSql, BasicTypeDefine<MysqlType> mysqlTypeBasicTypeDefine) {
MysqlType nativeType = mysqlTypeBasicTypeDefine.getNativeType();
public String decorateWithComment(String basicSql, BasicTypeDefine typeBasicTypeDefine) {
MysqlType nativeType = (MysqlType) typeBasicTypeDefine.getNativeType();
if (NOT_SUPPORTED_DEFAULT_VALUES.contains(nativeType)) {
return basicSql;
}
return JdbcDialect.super.decorateWithComment(basicSql, mysqlTypeBasicTypeDefine);
return JdbcDialect.super.decorateWithComment(basicSql, typeBasicTypeDefine);
}

@Override
Expand Down

0 comments on commit 16eeb1c

Please sign in to comment.