From 26efd4e53065557696f17d5e5115ac043c6e2021 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Sun, 20 Oct 2024 13:59:30 +0200 Subject: [PATCH] squash some warnings by filling in Signed-off-by: Gavin King --- .../query/sqm/SemanticQueryWalker.java | 2 +- .../query/sqm/internal/SqmTreePrinter.java | 106 +++++++++--------- .../sqm/spi/BaseSemanticQueryWalker.java | 46 ++++---- .../sqm/sql/BaseSqmToSqlAstConverter.java | 2 +- .../select/SqmDynamicInstantiationTarget.java | 2 +- 5 files changed, 76 insertions(+), 82 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/SemanticQueryWalker.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/SemanticQueryWalker.java index 7fcf4e0932..4fb6e9f135 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/SemanticQueryWalker.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/SemanticQueryWalker.java @@ -162,7 +162,7 @@ public interface SemanticQueryWalker { T visitRootDerived(SqmDerivedRoot sqmRoot); - T visitRootFunction(SqmFunctionRoot sqmRoot); + T visitRootFunction(SqmFunctionRoot sqmRoot); T visitRootCte(SqmCteRoot sqmRoot); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmTreePrinter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmTreePrinter.java index 20faf7cc8f..8b5a5450ce 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmTreePrinter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmTreePrinter.java @@ -140,7 +140,7 @@ public class SqmTreePrinter implements SemanticQueryWalker { private static final Logger LOGGER = QueryLogging.subLogger( "sqm.ast" ); private static final boolean DEBUG_ENABLED = LOGGER.isDebugEnabled(); - public static void logTree(SqmQuerySpec sqmQuerySpec, String header) { + public static void logTree(SqmQuerySpec sqmQuerySpec, String header) { if ( ! DEBUG_ENABLED ) { return; } @@ -154,24 +154,24 @@ public class SqmTreePrinter implements SemanticQueryWalker { LOGGER.debugf( "%s :%n%s", title, treePrinter.buffer.toString() ); } - public static void logTree(SqmStatement sqmStatement) { + public static void logTree(SqmStatement sqmStatement) { if ( ! DEBUG_ENABLED ) { return; } final SqmTreePrinter printer = new SqmTreePrinter(); - if ( sqmStatement instanceof SqmSelectStatement ) { - printer.visitSelectStatement( (SqmSelectStatement) sqmStatement ); + if ( sqmStatement instanceof SqmSelectStatement statement ) { + printer.visitSelectStatement( statement ); } - else if ( sqmStatement instanceof SqmDeleteStatement ) { - printer.visitDeleteStatement( (SqmDeleteStatement) sqmStatement ); + else if ( sqmStatement instanceof SqmDeleteStatement statement ) { + printer.visitDeleteStatement( statement ); } - else if ( sqmStatement instanceof SqmUpdateStatement ) { - printer.visitUpdateStatement( (SqmUpdateStatement) sqmStatement ); + else if ( sqmStatement instanceof SqmUpdateStatement statement ) { + printer.visitUpdateStatement( statement ); } - else if ( sqmStatement instanceof SqmInsertSelectStatement ) { - printer.visitInsertSelectStatement( (SqmInsertSelectStatement) sqmStatement ); + else if ( sqmStatement instanceof SqmInsertSelectStatement statement ) { + printer.visitInsertSelectStatement( statement ); } LOGGER.debugf( "SqmStatement Tree :%n%s", printer.buffer.toString() ); @@ -257,11 +257,11 @@ public class SqmTreePrinter implements SemanticQueryWalker { } private void logWithIndentation(String pattern, Object arg1, Object arg2) { - logWithIndentation( String.format( pattern, arg1, arg2 ) ); + logWithIndentation( String.format( pattern, arg1, arg2 ) ); } private void logWithIndentation(String pattern, Object... args) { - logWithIndentation( String.format( pattern, args ) ); + logWithIndentation( String.format( pattern, args ) ); } private void logIndented(String line) { @@ -386,7 +386,7 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitCteStatement(SqmCteStatement sqmCteStatement) { + public Object visitCteStatement(SqmCteStatement sqmCteStatement) { if ( DEBUG_ENABLED ) { logIndented( "cte" ); } @@ -536,7 +536,7 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitRootPath(SqmRoot sqmRoot) { + public Object visitRootPath(SqmRoot sqmRoot) { processStanza( "root", "`" + sqmRoot.getNavigablePath() + "`", @@ -551,21 +551,17 @@ public class SqmTreePrinter implements SemanticQueryWalker { processStanza( "derived", "`" + sqmRoot.getNavigablePath() + "`", - () -> { - processJoins( sqmRoot ); - } + () -> processJoins( sqmRoot ) ); return null; } @Override - public Object visitRootFunction(SqmFunctionRoot sqmRoot) { + public Object visitRootFunction(SqmFunctionRoot sqmRoot) { processStanza( "derived", "`" + sqmRoot.getNavigablePath() + "`", - () -> { - processJoins( sqmRoot ); - } + () -> processJoins( sqmRoot ) ); return null; } @@ -575,9 +571,7 @@ public class SqmTreePrinter implements SemanticQueryWalker { processStanza( "cte", "`" + sqmRoot.getNavigablePath() + "`", - () -> { - processJoins( sqmRoot ); - } + () -> processJoins( sqmRoot ) ); return null; } @@ -594,7 +588,7 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitCrossJoin(SqmCrossJoin joinedFromElement) { + public Object visitCrossJoin(SqmCrossJoin joinedFromElement) { processStanza( "cross", "`" + joinedFromElement.getNavigablePath() + "`", @@ -630,7 +624,7 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitQualifiedEntityJoin(SqmEntityJoin joinedFromElement) { + public Object visitQualifiedEntityJoin(SqmEntityJoin joinedFromElement) { if ( inJoinPredicate ) { logWithIndentation( "-> [joined-path] - `%s`", joinedFromElement.getNavigablePath() ); } @@ -648,7 +642,7 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitQualifiedAttributeJoin(SqmAttributeJoin joinedFromElement) { + public Object visitQualifiedAttributeJoin(SqmAttributeJoin joinedFromElement) { if ( inJoinPredicate ) { logWithIndentation( "-> [joined-path] - `%s`", joinedFromElement.getNavigablePath() ); } @@ -722,14 +716,14 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitBasicValuedPath(SqmBasicValuedSimplePath path) { + public Object visitBasicValuedPath(SqmBasicValuedSimplePath path) { logWithIndentation( "-> [basic-path] - `%s`", path.getNavigablePath() ); return null; } @Override - public Object visitEmbeddableValuedPath(SqmEmbeddedValuedSimplePath path) { + public Object visitEmbeddableValuedPath(SqmEmbeddedValuedSimplePath path) { logWithIndentation( "-> [embedded-path] - `%s`", path.getNavigablePath() ); return null; @@ -764,14 +758,14 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitEntityValuedPath(SqmEntityValuedSimplePath path) { + public Object visitEntityValuedPath(SqmEntityValuedSimplePath path) { logWithIndentation( "-> [entity-path] - `%s`", path.getNavigablePath() ); return null; } @Override - public Object visitPluralValuedPath(SqmPluralValuedSimplePath path) { + public Object visitPluralValuedPath(SqmPluralValuedSimplePath path) { logWithIndentation( "-> [plural-path] - `%s`", path.getNavigablePath() ); return null; @@ -783,7 +777,7 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitTreatedPath(SqmTreatedPath sqmTreatedPath) { + public Object visitTreatedPath(SqmTreatedPath sqmTreatedPath) { return null; } @@ -803,7 +797,7 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitSelection(SqmSelection selection) { + public Object visitSelection(SqmSelection selection) { processStanza( selection.getAlias() == null ? "selection" : "selection(" + selection.getAlias() + ")", () -> selection.getSelectableNode().accept( this ) @@ -818,26 +812,26 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitPositionalParameterExpression(SqmPositionalParameter expression) { + public Object visitPositionalParameterExpression(SqmPositionalParameter expression) { logWithIndentation( "?%s", expression.getPosition() ); return null; } @Override - public Object visitNamedParameterExpression(SqmNamedParameter expression) { + public Object visitNamedParameterExpression(SqmNamedParameter expression) { logWithIndentation( ":%s", expression.getName() ); return null; } @Override - public Object visitJpaCriteriaParameter(JpaCriteriaParameter expression) { + public Object visitJpaCriteriaParameter(JpaCriteriaParameter expression) { return null; } @Override - public Object visitEntityTypeLiteralExpression(SqmLiteralEntityType expression) { + public Object visitEntityTypeLiteralExpression(SqmLiteralEntityType expression) { return null; } @@ -847,12 +841,12 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitParameterizedEntityTypeExpression(SqmParameterizedEntityType expression) { + public Object visitParameterizedEntityTypeExpression(SqmParameterizedEntityType expression) { return null; } @Override - public Object visitUnaryOperationExpression(SqmUnaryOperation expression) { + public Object visitUnaryOperationExpression(SqmUnaryOperation expression) { return null; } @@ -1066,12 +1060,12 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitInListPredicate(SqmInListPredicate predicate) { + public Object visitInListPredicate(SqmInListPredicate predicate) { return null; } @Override - public Object visitInSubQueryPredicate(SqmInSubQueryPredicate predicate) { + public Object visitInSubQueryPredicate(SqmInSubQueryPredicate predicate) { return null; } @@ -1096,12 +1090,12 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitOffsetExpression(SqmExpression expression) { + public Object visitOffsetExpression(SqmExpression expression) { return null; } @Override - public Object visitFetchExpression(SqmExpression expression) { + public Object visitFetchExpression(SqmExpression expression) { return null; } @@ -1116,12 +1110,12 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitElementAggregateFunction(SqmElementAggregateFunction binding) { + public Object visitElementAggregateFunction(SqmElementAggregateFunction binding) { return null; } @Override - public Object visitIndexAggregateFunction(SqmIndexAggregateFunction path) { + public Object visitIndexAggregateFunction(SqmIndexAggregateFunction path) { return null; } @@ -1131,12 +1125,12 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitLiteral(SqmLiteral literal) { + public Object visitLiteral(SqmLiteral literal) { return null; } @Override - public Object visitTuple(SqmTuple sqmTuple) { + public Object visitTuple(SqmTuple sqmTuple) { return null; } @@ -1146,22 +1140,22 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitBinaryArithmeticExpression(SqmBinaryArithmetic expression) { + public Object visitBinaryArithmeticExpression(SqmBinaryArithmetic expression) { return null; } @Override - public Object visitSubQueryExpression(SqmSubQuery expression) { + public Object visitSubQueryExpression(SqmSubQuery expression) { return null; } @Override - public Object visitSimpleCaseExpression(SqmCaseSimple expression) { + public Object visitSimpleCaseExpression(SqmCaseSimple expression) { return null; } @Override - public Object visitSearchedCaseExpression(SqmCaseSearched expression) { + public Object visitSearchedCaseExpression(SqmCaseSearched expression) { return null; } @@ -1191,12 +1185,12 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitDynamicInstantiation(SqmDynamicInstantiation sqmDynamicInstantiation) { + public Object visitDynamicInstantiation(SqmDynamicInstantiation sqmDynamicInstantiation) { processStanza( "dynamic-instantiation (" + sqmDynamicInstantiation.getInstantiationTarget().getJavaType() + ')', () -> processStanza( "arguments", - () -> ( (SqmDynamicInstantiation) sqmDynamicInstantiation ).getArguments().forEach( + () -> sqmDynamicInstantiation.getArguments().forEach( argument -> processStanza( "argument (" + argument.getAlias() + ')', () -> { @@ -1228,12 +1222,12 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitFullyQualifiedClass(Class namedClass) { + public Object visitFullyQualifiedClass(Class namedClass) { return null; } @Override - public Object visitAsWrapperExpression(AsWrapperSqmExpression expression) { + public Object visitAsWrapperExpression(AsWrapperSqmExpression expression) { return null; } @@ -1243,7 +1237,7 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitModifiedSubQueryExpression(SqmModifiedSubQueryExpression expression) { + public Object visitModifiedSubQueryExpression(SqmModifiedSubQueryExpression expression) { return null; } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/spi/BaseSemanticQueryWalker.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/spi/BaseSemanticQueryWalker.java index 29f386c518..ba3ce3ff94 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/spi/BaseSemanticQueryWalker.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/spi/BaseSemanticQueryWalker.java @@ -6,6 +6,7 @@ package org.hibernate.query.sqm.spi; import java.util.List; +import org.hibernate.AssertionFailure; import org.hibernate.metamodel.model.domain.DiscriminatorSqmPath; import org.hibernate.metamodel.model.domain.internal.AnyDiscriminatorSqmPath; import org.hibernate.query.sqm.InterpretationException; @@ -227,11 +228,14 @@ public abstract class BaseSemanticQueryWalker implements SemanticQueryWalker selectQuery) { - if ( selectQuery instanceof SqmSelectStatement ) { - return visitSelectStatement( (SqmSelectStatement) selectQuery ); + if ( selectQuery instanceof SqmSelectStatement statement ) { + return visitSelectStatement( statement ); + } + else if ( selectQuery instanceof SqmSubQuery subquery ) { + return visitSubQueryExpression( subquery ); } else { - return visitSubQueryExpression( (SqmSubQuery) selectQuery ); + throw new AssertionFailure( "Unrecognized SQM select query type" ); } } @@ -297,11 +301,7 @@ public abstract class BaseSemanticQueryWalker implements SemanticQueryWalker sqmFrom) { - sqmFrom.visitSqmJoins( - sqmJoin -> { - consumeExplicitJoin( sqmJoin, true ); - } - ); + sqmFrom.visitSqmJoins( sqmJoin -> consumeExplicitJoin( sqmJoin, true ) ); final List> sqmTreats = sqmFrom.getSqmTreats(); if ( !sqmTreats.isEmpty() ) { for ( SqmFrom sqmTreat : sqmTreats ) { @@ -317,26 +317,26 @@ public abstract class BaseSemanticQueryWalker implements SemanticQueryWalker sqmJoin, boolean transitive) { - if ( sqmJoin instanceof SqmAttributeJoin ) { - consumeAttributeJoin( ( (SqmAttributeJoin) sqmJoin ), transitive ); + if ( sqmJoin instanceof SqmAttributeJoin join ) { + consumeAttributeJoin( join, transitive ); } - else if ( sqmJoin instanceof SqmCrossJoin ) { - consumeCrossJoin( ( (SqmCrossJoin) sqmJoin ), transitive ); + else if ( sqmJoin instanceof SqmCrossJoin crossJoin ) { + consumeCrossJoin( crossJoin, transitive ); } - else if ( sqmJoin instanceof SqmEntityJoin ) { - consumeEntityJoin( ( (SqmEntityJoin) sqmJoin ), transitive ); + else if ( sqmJoin instanceof SqmEntityJoin entityJoin ) { + consumeEntityJoin( entityJoin, transitive ); } - else if ( sqmJoin instanceof SqmDerivedJoin ) { - consumeDerivedJoin( ( (SqmDerivedJoin) sqmJoin ), transitive ); + else if ( sqmJoin instanceof SqmDerivedJoin derivedJoin ) { + consumeDerivedJoin( derivedJoin, transitive ); } - else if ( sqmJoin instanceof SqmFunctionJoin ) { - consumeFunctionJoin( (SqmFunctionJoin) sqmJoin, transitive ); + else if ( sqmJoin instanceof SqmFunctionJoin functionJoin ) { + consumeFunctionJoin( functionJoin, transitive ); } - else if ( sqmJoin instanceof SqmCteJoin ) { - consumeCteJoin( ( (SqmCteJoin) sqmJoin ), transitive ); + else if ( sqmJoin instanceof SqmCteJoin cteJoin ) { + consumeCteJoin( cteJoin, transitive ); } - else if ( sqmJoin instanceof SqmPluralPartJoin ) { - consumePluralPartJoin( ( (SqmPluralPartJoin) sqmJoin ), transitive ); + else if ( sqmJoin instanceof SqmPluralPartJoin pluralPartJoin ) { + consumePluralPartJoin( pluralPartJoin, transitive ); } else { throw new InterpretationException( "Could not visit SqmJoin [" + sqmJoin.getNavigablePath() + "] of type [" + sqmJoin.getClass().getName() + "]" ); @@ -416,7 +416,7 @@ public abstract class BaseSemanticQueryWalker implements SemanticQueryWalkersqmRoot) { return sqmRoot; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index 51ffa1b288..2442c8408f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -1686,7 +1686,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base targetJavaType = (Class) Map.class; } else { - targetJavaType = instantiationTarget.getJavaType(); + targetJavaType = (Class) instantiationTarget.getJavaType(); } return getCreationContext().getMappingMetamodel() diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmDynamicInstantiationTarget.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmDynamicInstantiationTarget.java index 9a1a428385..ebab241116 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmDynamicInstantiationTarget.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmDynamicInstantiationTarget.java @@ -33,7 +33,7 @@ public interface SqmDynamicInstantiationTarget extends SqmExpressible { * * @return The type to be instantiated. */ - default Class getJavaType() { + default Class getJavaType() { return getTargetTypeDescriptor().getJavaTypeClass(); } }