Skip to content

Commit

Permalink
HHH-18783 some cleanups, and leave a big TODO
Browse files Browse the repository at this point in the history
Signed-off-by: Gavin King <[email protected]>
  • Loading branch information
gavinking committed Nov 4, 2024
1 parent 050da72 commit 18ccd6e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -401,5 +401,4 @@ protected void renderStringContainsExactlyPredicate(Expression haystack, Express
needle.accept( this );
appendSql( ",'~','~~'),'?','~?'),'%','~%'),'%') escape '~'" );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public static String getSqlType(CastTarget castTarget, SessionFactoryImplementor
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( '(' );
Expand All @@ -72,16 +76,17 @@ private static String getSqlType(CastTarget castTarget, String sqlType, Dialect
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":
case "varchar":
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)";
}
Expand All @@ -94,7 +99,7 @@ private static String getSqlType(CastTarget castTarget, String sqlType, Dialect
case "varbinary":
return castTarget.getLength() == null
? "binary"
: ( "binary(" + castTarget.getLength() + ")" );
: "binary(" + castTarget.getLength() + ")";
}
}
return sqlType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5746,20 +5746,20 @@ else if ( isParameter( expression ) ) {
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 );
}
}

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 );
Expand Down Expand Up @@ -5935,8 +5935,8 @@ assert getStatementStack().getCurrent() instanceof UpdateStatement
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] );
}
Expand Down Expand Up @@ -6113,7 +6113,7 @@ else if ( referenceJoinIndexForPredicateSwap == TableGroupHelper.NO_TABLE_GROUP_

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] );
}
Expand Down

0 comments on commit 18ccd6e

Please sign in to comment.