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. * 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 @Override
public String getEnumCheckCondition(String columnName, int sqlType, Class<? extends Enum<?>> enumClass) { public String getEnumCheckCondition(String columnName, int sqlType, Class<? extends Enum<?>> enumClass) {
// don't need it, since we're using the 'enum' type // don't need it, since we're using the 'enum' type
return null; 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 @Override
public String getQueryHintString(String query, String hints) { public String getQueryHintString(String query, String hints) {
return IndexQueryHintHandler.INSTANCE.addQueryHints( query, hints ); return IndexQueryHintHandler.INSTANCE.addQueryHints( query, hints );

View File

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