diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBSqlAstTranslator.java index f06bf0b489..ea540352d8 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBSqlAstTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MariaDBSqlAstTranslator.java @@ -401,5 +401,4 @@ public class MariaDBSqlAstTranslator extends AbstractSq needle.accept( this ); appendSql( ",'~','~~'),'?','~?'),'%','~%'),'%') escape '~'" ); } - } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java index b7e1820c83..93ad2d709f 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java @@ -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( diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLSqlAstTranslator.java index cd34a9ca33..b672914dfa 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/MySQLSqlAstTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/MySQLSqlAstTranslator.java @@ -57,6 +57,10 @@ public class MySQLSqlAstTranslator 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 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 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 extends AbstractSqlA case "varbinary": return castTarget.getLength() == null ? "binary" - : ( "binary(" + castTarget.getLength() + ")" ); + : "binary(" + castTarget.getLength() + ")"; } } return sqlType; diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java index b81cb0e3af..85d5710bae 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java @@ -5746,11 +5746,11 @@ public abstract class AbstractSqlAstTranslator 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 implemen } protected void renderCasted(Expression expression) { - if ( expression instanceof SqmParameterInterpretation ) { - expression = ( (SqmParameterInterpretation) expression ).getResolvedExpression(); + if ( expression instanceof SqmParameterInterpretation parameterInterpretation ) { + expression = parameterInterpretation.getResolvedExpression(); } final List arguments = new ArrayList<>( 2 ); arguments.add( expression ); @@ -5935,8 +5935,8 @@ public abstract class AbstractSqlAstTranslator 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 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] ); }