HHH-18783 some cleanups, and leave a big TODO

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-11-04 20:09:47 +01:00
parent 050da72ae9
commit 18ccd6ed80
4 changed files with 19 additions and 14 deletions

View File

@ -401,5 +401,4 @@ public class MariaDBSqlAstTranslator<T extends JdbcOperation> extends AbstractSq
needle.accept( this );
appendSql( ",'~','~~'),'?','~?'),'%','~%'),'%') escape '~'" );
}
}

View File

@ -129,6 +129,7 @@ public class MySQLDialect extends Dialect {
private static final DatabaseVersion MINIMUM_VERSION = DatabaseVersion.make( 8 );
private final MySQLStorageEngine storageEngine = createStorageEngine();
private final SizeStrategy sizeStrategy = new SizeStrategyImpl() {
@Override
public Size resolveSize(

View File

@ -57,6 +57,10 @@ public class MySQLSqlAstTranslator<T extends JdbcOperation> extends AbstractSqlA
return getSqlType( castTarget, sqlType, factory.getJdbcServices().getDialect() );
}
//TODO: this is really, really bad since it circumvents the whole machinery we have in DdlType
// and in the Dialect for doing this in a unified way! These mappings should be held in
// the DdlTypes themselves and should be set up in registerColumnTypes(). Doing it here
// means we have problems distinguishing, say, the 'as Character' special case
private static String getSqlType(CastTarget castTarget, String sqlType, Dialect dialect) {
if ( sqlType != null ) {
int parenthesesIndex = sqlType.indexOf( '(' );
@ -72,9 +76,9 @@ public class MySQLSqlAstTranslator<T extends JdbcOperation> extends AbstractSqlA
case "float":
case "real":
case "double precision":
final int precision = castTarget.getPrecision() == null ?
dialect.getDefaultDecimalPrecision() :
castTarget.getPrecision();
final int precision = castTarget.getPrecision() == null
? dialect.getDefaultDecimalPrecision()
: castTarget.getPrecision();
final int scale = castTarget.getScale() == null ? Size.DEFAULT_SCALE : castTarget.getScale();
return "decimal(" + precision + "," + scale + ")";
case "char":
@ -82,6 +86,7 @@ public class MySQLSqlAstTranslator<T extends JdbcOperation> extends AbstractSqlA
case "nchar":
case "nvarchar":
if ( castTarget.getLength() == null ) {
// TODO: this is ugly and fragile, but could easily be handled in a DdlType
if ( castTarget.getJdbcMapping().getJdbcJavaType().getJavaType() == Character.class ) {
return "char(1)";
}
@ -94,7 +99,7 @@ public class MySQLSqlAstTranslator<T extends JdbcOperation> extends AbstractSqlA
case "varbinary":
return castTarget.getLength() == null
? "binary"
: ( "binary(" + castTarget.getLength() + ")" );
: "binary(" + castTarget.getLength() + ")";
}
}
return sqlType;

View File

@ -5746,11 +5746,11 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
renderCasted( expression );
}
}
else if ( expression instanceof CaseSimpleExpression ) {
visitCaseSimpleExpression( (CaseSimpleExpression) expression, true );
else if ( expression instanceof CaseSimpleExpression caseSimpleExpression ) {
visitCaseSimpleExpression( caseSimpleExpression, true );
}
else if ( expression instanceof CaseSearchedExpression ) {
visitCaseSearchedExpression( (CaseSearchedExpression) expression, true );
else if ( expression instanceof CaseSearchedExpression caseSearchedExpression ) {
visitCaseSearchedExpression( caseSearchedExpression, true );
}
else {
renderExpressionAsClauseItem( expression );
@ -5758,8 +5758,8 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
}
protected void renderCasted(Expression expression) {
if ( expression instanceof SqmParameterInterpretation ) {
expression = ( (SqmParameterInterpretation) expression ).getResolvedExpression();
if ( expression instanceof SqmParameterInterpretation parameterInterpretation ) {
expression = parameterInterpretation.getResolvedExpression();
}
final List<SqlAstNode> arguments = new ArrayList<>( 2 );
arguments.add( expression );
@ -5935,8 +5935,8 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
processNestedTableGroupJoins( tableGroup, null );
processTableGroupJoins( tableGroup );
ModelPartContainer modelPart = tableGroup.getModelPart();
if ( modelPart instanceof EntityPersister ) {
String[] querySpaces = (String[]) ( (EntityPersister) modelPart ).getQuerySpaces();
if ( modelPart instanceof EntityPersister persister ) {
final String[] querySpaces = (String[]) persister.getQuerySpaces();
for ( int i = 0; i < querySpaces.length; i++ ) {
registerAffectedTable( querySpaces[i] );
}
@ -6113,7 +6113,7 @@ public abstract class AbstractSqlAstTranslator<T extends JdbcOperation> implemen
ModelPartContainer modelPart = tableGroup.getModelPart();
if ( modelPart instanceof EntityPersister persister ) {
String[] querySpaces = (String[]) persister.getQuerySpaces();
final String[] querySpaces = (String[]) persister.getQuerySpaces();
for ( int i = 0; i < querySpaces.length; i++ ) {
registerAffectedTable( querySpaces[i] );
}