also use enum type for boolean->char mappings on MySQL

This commit is contained in:
Gavin 2022-12-10 11:51:05 +01:00 committed by Gavin King
parent 413b9ba03e
commit a25e53d1ab
3 changed files with 25 additions and 2 deletions

View File

@ -653,6 +653,10 @@ public abstract class Dialect implements ConversionContext {
}
}
public String getBooleanTypeDeclaration(int sqlType, char falseChar, char trueChar) {
return null;
}
/**
* Render a SQL check condition for a column that represents a boolean value.
*/

View File

@ -771,12 +771,23 @@ public class MySQLDialect extends Dialect {
}
}
@Override
public String getBooleanTypeDeclaration(int sqlType, char falseChar, char trueChar) {
return isCharacterType( sqlType ) ? "enum ('" + falseChar + "','" + trueChar + "')" : null;
}
@Override
public String getEnumCheckCondition(String columnName, int sqlType, Class<? extends Enum<?>> enumClass) {
// don't need it, since we're using the 'enum' type
return null;
}
@Override
public String getBooleanCheckCondition(String columnName, int sqlType, char falseChar, char trueChar) {
return isCharacterType( sqlType ) ? null
: super.getBooleanCheckCondition( columnName, sqlType, falseChar, trueChar );
}
@Override
public String getQueryHintString(String query, String hints) {
return IndexQueryHintHandler.INSTANCE.addQueryHints( query, hints );

View File

@ -168,13 +168,21 @@ public class BooleanJavaType extends AbstractClassJavaType<Boolean> implements
}
@Override
public String getCheckCondition(String columnName, JdbcType sqlTypeDescriptor, Dialect dialect) {
public String getCheckCondition(String columnName, JdbcType jdbcType, Dialect dialect) {
return dialect.getBooleanCheckCondition(
columnName,
sqlTypeDescriptor.getJdbcTypeCode(),
jdbcType.getJdbcTypeCode(),
characterValueFalse,
characterValueTrue
);
}
@Override
public String getSpecializedTypeDeclaration(JdbcType jdbcType, Dialect dialect) {
return dialect.getBooleanTypeDeclaration(
jdbcType.getJdbcTypeCode(),
characterValueFalse,
characterValueTrue
);
}
}