Skip to content

Commit 18ccd6e

Browse files
committed
HHH-18783 some cleanups, and leave a big TODO
Signed-off-by: Gavin King <[email protected]>
1 parent 050da72 commit 18ccd6e

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/MariaDBSqlAstTranslator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,5 +401,4 @@ protected void renderStringContainsExactlyPredicate(Expression haystack, Express
401401
needle.accept( this );
402402
appendSql( ",'~','~~'),'?','~?'),'%','~%'),'%') escape '~'" );
403403
}
404-
405404
}

hibernate-core/src/main/java/org/hibernate/dialect/MySQLDialect.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public class MySQLDialect extends Dialect {
129129
private static final DatabaseVersion MINIMUM_VERSION = DatabaseVersion.make( 8 );
130130

131131
private final MySQLStorageEngine storageEngine = createStorageEngine();
132+
132133
private final SizeStrategy sizeStrategy = new SizeStrategyImpl() {
133134
@Override
134135
public Size resolveSize(

hibernate-core/src/main/java/org/hibernate/dialect/MySQLSqlAstTranslator.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public static String getSqlType(CastTarget castTarget, SessionFactoryImplementor
5757
return getSqlType( castTarget, sqlType, factory.getJdbcServices().getDialect() );
5858
}
5959

60+
//TODO: this is really, really bad since it circumvents the whole machinery we have in DdlType
61+
// and in the Dialect for doing this in a unified way! These mappings should be held in
62+
// the DdlTypes themselves and should be set up in registerColumnTypes(). Doing it here
63+
// means we have problems distinguishing, say, the 'as Character' special case
6064
private static String getSqlType(CastTarget castTarget, String sqlType, Dialect dialect) {
6165
if ( sqlType != null ) {
6266
int parenthesesIndex = sqlType.indexOf( '(' );
@@ -72,16 +76,17 @@ private static String getSqlType(CastTarget castTarget, String sqlType, Dialect
7276
case "float":
7377
case "real":
7478
case "double precision":
75-
final int precision = castTarget.getPrecision() == null ?
76-
dialect.getDefaultDecimalPrecision() :
77-
castTarget.getPrecision();
79+
final int precision = castTarget.getPrecision() == null
80+
? dialect.getDefaultDecimalPrecision()
81+
: castTarget.getPrecision();
7882
final int scale = castTarget.getScale() == null ? Size.DEFAULT_SCALE : castTarget.getScale();
7983
return "decimal(" + precision + "," + scale + ")";
8084
case "char":
8185
case "varchar":
8286
case "nchar":
8387
case "nvarchar":
8488
if ( castTarget.getLength() == null ) {
89+
// TODO: this is ugly and fragile, but could easily be handled in a DdlType
8590
if ( castTarget.getJdbcMapping().getJdbcJavaType().getJavaType() == Character.class ) {
8691
return "char(1)";
8792
}
@@ -94,7 +99,7 @@ private static String getSqlType(CastTarget castTarget, String sqlType, Dialect
9499
case "varbinary":
95100
return castTarget.getLength() == null
96101
? "binary"
97-
: ( "binary(" + castTarget.getLength() + ")" );
102+
: "binary(" + castTarget.getLength() + ")";
98103
}
99104
}
100105
return sqlType;

hibernate-core/src/main/java/org/hibernate/sql/ast/spi/AbstractSqlAstTranslator.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5746,20 +5746,20 @@ else if ( isParameter( expression ) ) {
57465746
renderCasted( expression );
57475747
}
57485748
}
5749-
else if ( expression instanceof CaseSimpleExpression ) {
5750-
visitCaseSimpleExpression( (CaseSimpleExpression) expression, true );
5749+
else if ( expression instanceof CaseSimpleExpression caseSimpleExpression ) {
5750+
visitCaseSimpleExpression( caseSimpleExpression, true );
57515751
}
5752-
else if ( expression instanceof CaseSearchedExpression ) {
5753-
visitCaseSearchedExpression( (CaseSearchedExpression) expression, true );
5752+
else if ( expression instanceof CaseSearchedExpression caseSearchedExpression ) {
5753+
visitCaseSearchedExpression( caseSearchedExpression, true );
57545754
}
57555755
else {
57565756
renderExpressionAsClauseItem( expression );
57575757
}
57585758
}
57595759

57605760
protected void renderCasted(Expression expression) {
5761-
if ( expression instanceof SqmParameterInterpretation ) {
5762-
expression = ( (SqmParameterInterpretation) expression ).getResolvedExpression();
5761+
if ( expression instanceof SqmParameterInterpretation parameterInterpretation ) {
5762+
expression = parameterInterpretation.getResolvedExpression();
57635763
}
57645764
final List<SqlAstNode> arguments = new ArrayList<>( 2 );
57655765
arguments.add( expression );
@@ -5935,8 +5935,8 @@ assert getStatementStack().getCurrent() instanceof UpdateStatement
59355935
processNestedTableGroupJoins( tableGroup, null );
59365936
processTableGroupJoins( tableGroup );
59375937
ModelPartContainer modelPart = tableGroup.getModelPart();
5938-
if ( modelPart instanceof EntityPersister ) {
5939-
String[] querySpaces = (String[]) ( (EntityPersister) modelPart ).getQuerySpaces();
5938+
if ( modelPart instanceof EntityPersister persister ) {
5939+
final String[] querySpaces = (String[]) persister.getQuerySpaces();
59405940
for ( int i = 0; i < querySpaces.length; i++ ) {
59415941
registerAffectedTable( querySpaces[i] );
59425942
}
@@ -6113,7 +6113,7 @@ else if ( referenceJoinIndexForPredicateSwap == TableGroupHelper.NO_TABLE_GROUP_
61136113

61146114
ModelPartContainer modelPart = tableGroup.getModelPart();
61156115
if ( modelPart instanceof EntityPersister persister ) {
6116-
String[] querySpaces = (String[]) persister.getQuerySpaces();
6116+
final String[] querySpaces = (String[]) persister.getQuerySpaces();
61176117
for ( int i = 0; i < querySpaces.length; i++ ) {
61186118
registerAffectedTable( querySpaces[i] );
61196119
}

0 commit comments

Comments
 (0)