clean up lots of warnings by adding wildcards to raw types

also comment out some unused code
This commit is contained in:
Gavin King 2022-01-10 11:11:17 +01:00
parent 4b5e6e1969
commit 3e8f1c67df
58 changed files with 435 additions and 401 deletions

View File

@ -59,14 +59,14 @@ public class AvgFunction extends AbstractSqmSelfRenderingFunctionDescriptor {
}
@Override
public void render(SqlAppender sqlAppender, List<SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
render( sqlAppender, sqlAstArguments, null, walker );
}
@Override
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> sqlAstArguments,
List<? extends SqlAstNode> sqlAstArguments,
Predicate filter,
SqlAstTranslator<?> translator) {
final boolean caseWrapper = filter != null && !translator.supportsFilterClause();

View File

@ -10,7 +10,6 @@ import java.util.List;
import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor;
import org.hibernate.query.sqm.produce.function.ArgumentTypesValidator;
import org.hibernate.query.sqm.produce.function.FunctionParameterType;
import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators;
import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers;
import org.hibernate.sql.ast.SqlAstTranslator;
@ -40,7 +39,7 @@ public class CaseLeastGreatestEmulation
@Override
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> arguments,
List<? extends SqlAstNode> arguments,
SqlAstTranslator<?> walker) {
final int numberOfArguments = arguments.size();
if ( numberOfArguments > 1 ) {

View File

@ -43,7 +43,7 @@ public class CaseWhenEveryAnyEmulation extends AbstractSqmSelfRenderingFunctionD
@Override
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> sqlAstArguments,
List<? extends SqlAstNode> sqlAstArguments,
Predicate filter,
SqlAstTranslator<?> walker) {
if ( every ) {
@ -66,7 +66,7 @@ public class CaseWhenEveryAnyEmulation extends AbstractSqmSelfRenderingFunctionD
@Override
public void render(
SqlAppender sqlAppender, List<SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
this.render( sqlAppender, sqlAstArguments, null, walker );
}
}

View File

@ -51,7 +51,7 @@ public class CastFunction extends AbstractSqmSelfRenderingFunctionDescriptor {
}
@Override
public void render(SqlAppender sqlAppender, List<SqlAstNode> arguments, SqlAstTranslator<?> walker) {
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> arguments, SqlAstTranslator<?> walker) {
final Expression source = (Expression) arguments.get( 0 );
final JdbcMapping sourceMapping = source.getExpressionType().getJdbcMappings().get( 0 );
final CastType sourceType = getCastType( sourceMapping );

View File

@ -63,7 +63,7 @@ public class CastingConcatFunction extends AbstractSqmSelfRenderingFunctionDescr
}
@Override
public void render(SqlAppender sqlAppender, List<SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
sqlAppender.appendSql( '(' );
renderAsString( sqlAppender, walker, (Expression) sqlAstArguments.get( 0 ) );
for ( int i = 1; i < sqlAstArguments.size(); i++ ) {

View File

@ -68,14 +68,14 @@ public class CountFunction extends AbstractSqmSelfRenderingFunctionDescriptor {
}
@Override
public void render(SqlAppender sqlAppender, List<SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
render( sqlAppender, sqlAstArguments, null, walker );
}
@Override
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> sqlAstArguments,
List<? extends SqlAstNode> sqlAstArguments,
Predicate filter,
SqlAstTranslator<?> translator) {
final boolean caseWrapper = filter != null && !translator.supportsFilterClause();

View File

@ -36,7 +36,7 @@ public class CurrentFunction
@Override
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> arguments,
List<? extends SqlAstNode> arguments,
SqlAstTranslator<?> walker) {
sqlAppender.appendSql( sql );
}

View File

@ -49,7 +49,7 @@ public class DB2FormatEmulation
@Override
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> arguments,
List<? extends SqlAstNode> arguments,
SqlAstTranslator<?> walker) {
final Expression datetime = (Expression) arguments.get(0);
final boolean isTime = TypeConfiguration.getSqlTemporalType( datetime.getExpressionType() ) == TemporalType.TIME;

View File

@ -43,7 +43,7 @@ public class DerbyLpadEmulation
@Override
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> arguments,
List<? extends SqlAstNode> arguments,
SqlAstTranslator<?> walker) {
final SqlAstNode string = arguments.get( 0 );
final SqlAstNode length = arguments.get( 1 );

View File

@ -43,7 +43,7 @@ public class DerbyRpadEmulation
@Override
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> arguments,
List<? extends SqlAstNode> arguments,
SqlAstTranslator<?> walker) {
final SqlAstNode string = arguments.get( 0 );
final SqlAstNode length = arguments.get( 1 );

View File

@ -44,7 +44,7 @@ public class EveryAnyEmulation extends AbstractSqmSelfRenderingFunctionDescripto
@Override
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> sqlAstArguments,
List<? extends SqlAstNode> sqlAstArguments,
Predicate filter,
SqlAstTranslator<?> walker) {
sqlAppender.appendSql( "(sum(case when " );
@ -72,7 +72,7 @@ public class EveryAnyEmulation extends AbstractSqmSelfRenderingFunctionDescripto
@Override
public void render(
SqlAppender sqlAppender, List<SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
this.render( sqlAppender, sqlAstArguments, null, walker );
}
}

View File

@ -34,7 +34,7 @@ public class FieldFunction extends AbstractSqmSelfRenderingFunctionDescriptor {
@Override
public void render(
SqlAppender sqlAppender, List<SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
sqlAppender.appendSql( "field(" );
sqlAstArguments.get( 0 ).accept( walker );
for ( int i = 1; i < sqlAstArguments.size(); i++ ) {

View File

@ -39,7 +39,7 @@ public class QuantifiedLeastGreatestEmulation
@Override
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> arguments,
List<? extends SqlAstNode> arguments,
SqlAstTranslator<?> walker) {
final int numberOfArguments = arguments.size();
if ( numberOfArguments > 1 ) {

View File

@ -44,7 +44,7 @@ public class SQLServerEveryAnyEmulation extends AbstractSqmSelfRenderingFunction
@Override
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> sqlAstArguments,
List<? extends SqlAstNode> sqlAstArguments,
Predicate filter,
SqlAstTranslator<?> walker) {
if ( every ) {
@ -67,7 +67,7 @@ public class SQLServerEveryAnyEmulation extends AbstractSqmSelfRenderingFunction
@Override
public void render(
SqlAppender sqlAppender, List<SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
this.render( sqlAppender, sqlAstArguments, null, walker );
}
}

View File

@ -10,10 +10,8 @@ import java.util.List;
import jakarta.persistence.TemporalType;
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor;
import org.hibernate.query.sqm.produce.function.ArgumentTypesValidator;
import org.hibernate.query.sqm.produce.function.FunctionParameterType;
import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators;
import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers;
import org.hibernate.sql.ast.SqlAstTranslator;
@ -50,7 +48,7 @@ public class SQLServerFormatEmulation extends AbstractSqmSelfRenderingFunctionDe
@Override
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> arguments,
List<? extends SqlAstNode> arguments,
SqlAstTranslator<?> walker) {
final Expression datetime = (Expression) arguments.get(0);
final boolean isTime = TypeConfiguration.getSqlTemporalType( datetime.getExpressionType() ) == TemporalType.TIME;

View File

@ -15,7 +15,6 @@ import org.hibernate.sql.ast.SqlAstTranslator;
import org.hibernate.sql.ast.spi.SqlAppender;
import org.hibernate.sql.ast.tree.SqlAstNode;
import org.hibernate.sql.ast.tree.expression.QueryLiteral;
import org.hibernate.type.BasicType;
import org.hibernate.type.JavaObjectType;
/**
@ -37,7 +36,7 @@ public class SqlFunction
@Override
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> arguments,
List<? extends SqlAstNode> arguments,
SqlAstTranslator<?> walker) {
final QueryLiteral<String> sqlFragmentLiteral = (QueryLiteral<String>) arguments.get( 0 );
final String sqlFragment = sqlFragmentLiteral.getLiteralValue();

View File

@ -67,7 +67,7 @@ public class TimestampaddFunction
@Override
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> arguments,
List<? extends SqlAstNode> arguments,
SqlAstTranslator<?> walker) {
final DurationUnit field = (DurationUnit) arguments.get( 0 );
@ -143,7 +143,7 @@ public class TimestampaddFunction
1,
new SelfRenderingFunctionSqlAstExpression(
"cast",
castFunction::render,
castFunction,
castArguments,
integerType,
integerType
@ -190,7 +190,7 @@ public class TimestampaddFunction
Expression to = (Expression) sqlAstArguments[2];
return new SelfRenderingFunctionSqlAstExpression(
getName(),
this::render,
this,
asList( sqlAstArguments ),
impliedResultType != null
? impliedResultType

View File

@ -13,7 +13,6 @@ import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType;
import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor;
import org.hibernate.query.sqm.function.SelfRenderingFunctionSqlAstExpression;
import org.hibernate.query.sqm.produce.function.ArgumentTypesValidator;
import org.hibernate.query.sqm.produce.function.FunctionParameterType;
import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators;
import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers;
import org.hibernate.query.sqm.produce.function.internal.PatternRenderer;
@ -54,7 +53,7 @@ public class TimestampdiffFunction
@Override
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> arguments,
List<? extends SqlAstNode> arguments,
SqlAstTranslator<?> walker) {
final DurationUnit field = (DurationUnit) arguments.get( 0 );
@ -104,7 +103,7 @@ public class TimestampdiffFunction
DurationUnit field = (DurationUnit) sqlAstArguments[0];
return new SelfRenderingFunctionSqlAstExpression(
getName(),
this::render,
this,
asList( sqlAstArguments ),
impliedResultType != null
? impliedResultType

View File

@ -67,7 +67,7 @@ public class TransactSQLStrFunction extends CastStrEmulation implements Function
}
@Override
public void render(SqlAppender sqlAppender, List<SqlAstNode> arguments, SqlAstTranslator<?> walker) {
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> arguments, SqlAstTranslator<?> walker) {
sqlAppender.appendSql( "str(" );
arguments.get( 0 ).accept( walker );
for ( int i = 1; i < arguments.size(); i++ ) {

View File

@ -17,7 +17,7 @@ import org.hibernate.sql.ast.SqlAstTranslator;
import org.hibernate.sql.ast.spi.SqlAppender;
import org.hibernate.sql.ast.tree.SqlAstNode;
import org.hibernate.sql.ast.tree.expression.Expression;
import org.hibernate.sql.ast.tree.expression.QueryLiteral;
import org.hibernate.sql.ast.tree.expression.Literal;
import org.hibernate.sql.ast.tree.expression.TrimSpecification;
import org.hibernate.type.StandardBasicTypes;
import org.hibernate.type.spi.TypeConfiguration;
@ -50,12 +50,12 @@ public class TrimFunction extends AbstractSqmSelfRenderingFunctionDescriptor {
}
@Override
public void render(SqlAppender sqlAppender, List<SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
final TrimSpec specification = ( (TrimSpecification) sqlAstArguments.get( 0 ) ).getSpecification();
final Character trimCharacter = ( (QueryLiteral<Character>) sqlAstArguments.get( 1 ) ).getLiteralValue();
final Object trimCharacter = ( (Literal) sqlAstArguments.get( 1 ) ).getLiteralValue();
final Expression sourceExpr = (Expression) sqlAstArguments.get( 2 );
String trim = dialect.trimPattern( specification, trimCharacter );
String trim = dialect.trimPattern( specification, (char) trimCharacter );
new PatternRenderer( trim ).render( sqlAppender, Collections.singletonList( sourceExpr ), walker );
}

View File

@ -108,7 +108,7 @@ public class FunctionExpression implements OrderingExpression, FunctionRendering
}
@Override
public void render(SqlAppender sqlAppender, List<SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
sqlAppender.appendSql( name );
sqlAppender.appendSql( '(' );
if ( !sqlAstArguments.isEmpty() ) {

View File

@ -39,7 +39,7 @@ public class ParameterMetadataImpl implements ParameterMetadataImplementor {
*/
public static final ParameterMetadataImpl EMPTY = new ParameterMetadataImpl();
private final Map<QueryParameterImplementor<?>, List<SqmParameter>> queryParameters;
private final Map<QueryParameterImplementor<?>, List<SqmParameter<?>>> queryParameters;
private final Set<String> names;
private final Set<Integer> labels;
@ -51,7 +51,7 @@ public class ParameterMetadataImpl implements ParameterMetadataImplementor {
this.labels = Collections.emptySet();
}
public ParameterMetadataImpl(Map<QueryParameterImplementor<?>, List<SqmParameter>> queryParameters) {
public ParameterMetadataImpl(Map<QueryParameterImplementor<?>, List<SqmParameter<?>>> queryParameters) {
this.queryParameters = queryParameters;
// if we have any ordinal parameters, make sure the numbers
@ -168,12 +168,12 @@ public class ParameterMetadataImpl implements ParameterMetadataImplementor {
@Override
public <T> AllowableParameterType<T> getInferredParameterType(QueryParameter<T> parameter) {
final List<SqmParameter> sqmParameters = queryParameters.get( parameter );
final List<SqmParameter<?>> sqmParameters = queryParameters.get( parameter );
if ( sqmParameters == null || sqmParameters.isEmpty() ) {
return null;
}
for ( SqmParameter sqmParameter : sqmParameters ) {
final AllowableParameterType nodeType = sqmParameter.getNodeType();
for ( SqmParameter<?> sqmParameter : sqmParameters ) {
final AllowableParameterType<T> nodeType = (AllowableParameterType<T>) sqmParameter.getNodeType();
if ( nodeType != null ) {
return nodeType;
}

View File

@ -6,13 +6,10 @@
*/
package org.hibernate.query.internal;
import java.util.Collections;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Supplier;
import org.hibernate.metamodel.mapping.MappingModelExpressable;
import org.hibernate.query.spi.HqlInterpretation;
import org.hibernate.query.spi.NonSelectQueryPlan;
import org.hibernate.query.spi.ParameterMetadataImplementor;
@ -21,7 +18,6 @@ import org.hibernate.query.spi.SelectQueryPlan;
import org.hibernate.query.sql.spi.ParameterInterpretation;
import org.hibernate.query.sqm.internal.DomainParameterXref;
import org.hibernate.query.sqm.tree.SqmStatement;
import org.hibernate.query.sqm.tree.expression.SqmParameter;
import org.hibernate.stat.spi.StatisticsImplementor;
/**
@ -90,7 +86,7 @@ public class QueryInterpretationCacheDisabledImpl implements QueryInterpretation
return new HqlInterpretation() {
@Override
public SqmStatement getSqmStatement() {
public SqmStatement<?> getSqmStatement() {
return sqmStatement;
}

View File

@ -194,11 +194,11 @@ public class QueryInterpretationCacheStandardImpl implements QueryInterpretation
private static class ImmutableHqlInterpretation {
private final SqmStatement sqmStatement;
private final SqmStatement<?> sqmStatement;
private final ParameterMetadataImplementor parameterMetadata;
public ImmutableHqlInterpretation(
SqmStatement sqmStatement,
SqmStatement<?> sqmStatement,
ParameterMetadataImplementor parameterMetadata) {
this.sqmStatement = sqmStatement;
this.parameterMetadata = parameterMetadata;

View File

@ -26,7 +26,7 @@ public class QueryParameterNamedImpl<T> extends AbstractQueryParameter<T> {
*
* @return The parameter descriptor
*/
public static <T> QueryParameterNamedImpl<T> fromSqm(SqmParameter parameter) {
public static <T> QueryParameterNamedImpl<T> fromSqm(SqmParameter<?> parameter) {
assert parameter.getName() != null;
assert parameter.getPosition() == null;
@ -63,7 +63,7 @@ public class QueryParameterNamedImpl<T> extends AbstractQueryParameter<T> {
@Override
public NamedQueryMemento.ParameterMemento toMemento() {
return session -> new QueryParameterNamedImpl( getName(), allowsMultiValuedBinding(), getHibernateType() );
return session -> new QueryParameterNamedImpl<>( getName(), allowsMultiValuedBinding(), getHibernateType() );
}
@Override

View File

@ -169,10 +169,7 @@ public interface QueryOptions {
default boolean hasLimit() {
final Limit limit = getLimit();
if ( limit != null ) {
if ( limit.getFirstRow() != null ) {
return true;
}
if ( limit.getMaxRows() != null ) {
if ( limit.getFirstRow() != null || limit.getMaxRows() != null ) {
return true;
}
}

View File

@ -13,12 +13,12 @@ import org.hibernate.query.sqm.tree.SqmStatement;
* @author Steve Ebersole
*/
public class SimpleHqlInterpretationImpl implements HqlInterpretation {
private final SqmStatement sqmStatement;
private final SqmStatement<?> sqmStatement;
private final ParameterMetadataImplementor parameterMetadata;
private final DomainParameterXref domainParameterXref;
public SimpleHqlInterpretationImpl(
SqmStatement sqmStatement,
SqmStatement<?> sqmStatement,
ParameterMetadataImplementor parameterMetadata,
DomainParameterXref domainParameterXref) {
this.sqmStatement = sqmStatement;
@ -27,7 +27,7 @@ public class SimpleHqlInterpretationImpl implements HqlInterpretation {
}
@Override
public SqmStatement getSqmStatement() {
public SqmStatement<?> getSqmStatement() {
return sqmStatement;
}

View File

@ -61,7 +61,7 @@ public abstract class AbstractSqmSelfRenderingFunctionDescriptor
}
return new SelfRenderingSqmFunction<>(
this,
this::render,
(sqlAppender, sqlAstArguments, walker) -> render(sqlAppender, sqlAstArguments, walker),
arguments,
impliedResultType,
getArgumentsValidator(),
@ -99,12 +99,12 @@ public abstract class AbstractSqmSelfRenderingFunctionDescriptor
*/
public abstract void render(
SqlAppender sqlAppender,
List<SqlAstNode> sqlAstArguments,
List<? extends SqlAstNode> sqlAstArguments,
SqlAstTranslator<?> walker);
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> sqlAstArguments,
List<? extends SqlAstNode> sqlAstArguments,
Predicate filter,
SqlAstTranslator<?> walker) {
render( sqlAppender, sqlAstArguments, walker );

View File

@ -7,7 +7,6 @@
package org.hibernate.query.sqm.function;
import org.hibernate.sql.ast.SqlAstTranslator;
import org.hibernate.sql.ast.SqlAstWalker;
import org.hibernate.sql.ast.spi.SqlAppender;
import org.hibernate.sql.ast.tree.SqlAstNode;
import org.hibernate.sql.ast.tree.predicate.Predicate;
@ -28,12 +27,12 @@ import java.util.List;
public interface FunctionRenderingSupport {
void render(
SqlAppender sqlAppender,
List<SqlAstNode> sqlAstArguments,
List<? extends SqlAstNode> sqlAstArguments,
SqlAstTranslator<?> walker);
default void render(
SqlAppender sqlAppender,
List<SqlAstNode> sqlAstArguments,
List<? extends SqlAstNode> sqlAstArguments,
Predicate filter,
SqlAstTranslator<?> walker) {
// Ignore the filter by default. Subclasses will override this

View File

@ -91,7 +91,7 @@ public class NamedSqmFunctionDescriptor
@Override
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> sqlAstArguments,
List<? extends SqlAstNode> sqlAstArguments,
SqlAstTranslator<?> translator) {
render( sqlAppender, sqlAstArguments, null, translator );
}
@ -99,7 +99,7 @@ public class NamedSqmFunctionDescriptor
@Override
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> sqlAstArguments,
List<? extends SqlAstNode> sqlAstArguments,
Predicate filter,
SqlAstTranslator<?> translator) {
final boolean useParens = useParenthesesWhenNoArgs || !sqlAstArguments.isEmpty();

View File

@ -71,13 +71,13 @@ public class PatternBasedSqmFunctionDescriptor
@Override
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> sqlAstArguments,
List<? extends SqlAstNode> sqlAstArguments,
SqlAstTranslator<?> walker) {
renderer.render( sqlAppender, sqlAstArguments, null, walker );
}
@Override
public void render(SqlAppender sqlAppender, List<SqlAstNode> sqlAstArguments, Predicate filter, SqlAstTranslator<?> walker) {
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArguments, Predicate filter, SqlAstTranslator<?> walker) {
renderer.render( sqlAppender, sqlAstArguments, filter, walker );
}

View File

@ -31,7 +31,7 @@ public class SelfRenderingAggregateFunctionSqlAstExpression extends SelfRenderin
public SelfRenderingAggregateFunctionSqlAstExpression(
String functionName,
FunctionRenderingSupport renderer,
List<SqlAstNode> sqlAstArguments,
List<? extends SqlAstNode> sqlAstArguments,
Predicate filter,
AllowableFunctionReturnType<?> type,
JdbcMappingContainer expressable) {

View File

@ -47,14 +47,14 @@ public class SelfRenderingFunctionSqlAstExpression
implements SelfRenderingExpression, Selectable, SqlExpressable, DomainResultProducer, FunctionExpression {
private final String functionName;
private final FunctionRenderingSupport renderer;
private final List<SqlAstNode> sqlAstArguments;
private final List<? extends SqlAstNode> sqlAstArguments;
private final AllowableFunctionReturnType<?> type;
private final JdbcMappingContainer expressable;
public SelfRenderingFunctionSqlAstExpression(
String functionName,
FunctionRenderingSupport renderer,
List<SqlAstNode> sqlAstArguments,
List<? extends SqlAstNode> sqlAstArguments,
AllowableFunctionReturnType<?> type,
JdbcMappingContainer expressable) {
this.functionName = functionName;
@ -71,7 +71,7 @@ public class SelfRenderingFunctionSqlAstExpression
}
@Override
public List<SqlAstNode> getArguments() {
public List<? extends SqlAstNode> getArguments() {
return sqlAstArguments;
}

View File

@ -30,6 +30,7 @@ import org.hibernate.query.spi.QueryOptions;
import org.hibernate.query.spi.QueryParameterImplementor;
import org.hibernate.query.spi.ScrollableResultsImplementor;
import org.hibernate.query.spi.SelectQueryPlan;
import org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess;
import org.hibernate.query.sqm.sql.SqmTranslation;
import org.hibernate.query.sqm.sql.SqmTranslator;
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
@ -68,7 +69,7 @@ import static org.hibernate.query.sqm.internal.QuerySqmImpl.CRITERIA_HQL_STRING;
* @author Steve Ebersole
*/
public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
private final SqmSelectStatement sqm;
private final SqmSelectStatement<?> sqm;
private final String hql;
private final DomainParameterXref domainParameterXref;
private final RowTransformer<R> rowTransformer;
@ -79,7 +80,7 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
@SuppressWarnings("WeakerAccess")
public ConcreteSqmSelectQueryPlan(
SqmSelectStatement sqm,
SqmSelectStatement<?> sqm,
String hql,
DomainParameterXref domainParameterXref,
Class<R> resultType,
@ -136,26 +137,24 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
this.scrollInterpreter = (scrollMode, executionContext, sqmInterpretation, jdbcParameterBindings) -> {
try {
final SubselectFetch.RegistrationHandler subSelectFetchKeyHandler = SubselectFetch.createRegistrationHandler(
executionContext.getSession().getPersistenceContext().getBatchFetchQueue(),
sqmInterpretation.selectStatement,
Collections.emptyList(),
jdbcParameterBindings
);
// final SubselectFetch.RegistrationHandler subSelectFetchKeyHandler = SubselectFetch.createRegistrationHandler(
// executionContext.getSession().getPersistenceContext().getBatchFetchQueue(),
// sqmInterpretation.selectStatement,
// Collections.emptyList(),
// jdbcParameterBindings
// );
final JdbcSelectExecutor jdbcSelectExecutor = executionContext.getSession()
.getFactory()
.getJdbcServices()
.getJdbcSelectExecutor();
final ScrollableResultsImplementor<R> result = jdbcSelectExecutor.scroll(
return jdbcSelectExecutor.scroll(
sqmInterpretation.getJdbcSelect(),
scrollMode,
jdbcParameterBindings,
new SqmJdbcExecutionContextAdapter( executionContext, sqmInterpretation.jdbcSelect ),
rowTransformer
);
return result;
}
finally {
domainParameterXref.clearExpansions();
@ -176,7 +175,7 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
@SuppressWarnings("unchecked")
private RowTransformer<R> determineRowTransformer(
SqmSelectStatement sqm,
SqmSelectStatement<?> sqm,
Class<R> resultType,
QueryOptions queryOptions) {
if ( resultType == null || resultType.isArray() ) {
@ -237,7 +236,7 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
}
private RowTransformer<R> makeRowTransformerTupleTransformerAdapter(
SqmSelectStatement sqm,
SqmSelectStatement<?> sqm,
QueryOptions queryOptions) {
final List<String> aliases = new ArrayList<>();
for ( SqmSelection<?> sqmSelection : sqm.getQuerySpec().getSelectClause().getSelections() ) {
@ -252,8 +251,9 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
}
}
return new RowTransformerTupleTransformerAdapter<>(
ArrayHelper.toStringArray( aliases ), queryOptions.getTupleTransformer()
return new RowTransformerTupleTransformerAdapter<R>(
ArrayHelper.toStringArray( aliases ),
queryOptions.getTupleTransformer()
);
}
@ -332,7 +332,13 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
sqmInterpretation.getJdbcParamsXref(),
session.getFactory().getDomainModel(),
sqmInterpretation.getTableGroupAccess()::findTableGroup,
sqmInterpretation.getSqmParameterMappingModelTypes()::get,
new SqmParameterMappingModelResolutionAccess() {
//this is pretty ugly!
@Override @SuppressWarnings("unchecked")
public <T> MappingModelExpressable<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
return (MappingModelExpressable<T>) sqmInterpretation.getSqmParameterMappingModelTypes().get(parameter);
}
},
session
);
sqmInterpretation.getJdbcSelect().bindFilterJdbcParameters( jdbcParameterBindings );
@ -340,7 +346,7 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
}
private static CacheableSqmInterpretation buildCacheableSqmInterpretation(
SqmSelectStatement sqm,
SqmSelectStatement<?> sqm,
DomainParameterXref domainParameterXref,
DomainQueryExecutionContext executionContext) {
final SharedSessionContractImplementor session = executionContext.getSession();
@ -370,17 +376,20 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
sqmInterpretation.getSqlAst()
);
final Map<QueryParameterImplementor<?>, Map<SqmParameter, List<List<JdbcParameter>>>> jdbcParamsXref = SqmUtil.generateJdbcParamsXref(
domainParameterXref,
sqmInterpretation::getJdbcParamsBySqmParam
);
final Map<QueryParameterImplementor<?>, Map<SqmParameter<?>, List<List<JdbcParameter>>>> jdbcParamsXref
= SqmUtil.generateJdbcParamsXref( domainParameterXref, sqmInterpretation::getJdbcParamsBySqmParam );
final JdbcParameterBindings jdbcParameterBindings = SqmUtil.createJdbcParameterBindings(
executionContext.getQueryParameterBindings(),
domainParameterXref,
jdbcParamsXref,
session.getFactory().getDomainModel(),
tableGroupAccess::findTableGroup,
sqmInterpretation.getSqmParameterMappingModelTypeResolutions()::get,
new SqmParameterMappingModelResolutionAccess() {
@Override @SuppressWarnings("unchecked")
public <T> MappingModelExpressable<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
return (MappingModelExpressable<T>) sqmInterpretation.getSqmParameterMappingModelTypeResolutions().get(parameter);
}
},
session
);
final JdbcSelect jdbcSelect = selectTranslator.translate( jdbcParameterBindings, executionContext.getQueryOptions() );
@ -407,16 +416,16 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
private final SelectStatement selectStatement;
private final JdbcSelect jdbcSelect;
private final FromClauseAccess tableGroupAccess;
private final Map<QueryParameterImplementor<?>, Map<SqmParameter, List<List<JdbcParameter>>>> jdbcParamsXref;
private final Map<SqmParameter, MappingModelExpressable> sqmParameterMappingModelTypes;
private final Map<QueryParameterImplementor<?>, Map<SqmParameter<?>, List<List<JdbcParameter>>>> jdbcParamsXref;
private final Map<SqmParameter<?>, MappingModelExpressable<?>> sqmParameterMappingModelTypes;
private transient JdbcParameterBindings firstParameterBindings;
CacheableSqmInterpretation(
SelectStatement selectStatement,
JdbcSelect jdbcSelect,
FromClauseAccess tableGroupAccess,
Map<QueryParameterImplementor<?>, Map<SqmParameter, List<List<JdbcParameter>>>> jdbcParamsXref,
Map<SqmParameter,MappingModelExpressable> sqmParameterMappingModelTypes,
Map<QueryParameterImplementor<?>, Map<SqmParameter<?>, List<List<JdbcParameter>>>> jdbcParamsXref,
Map<SqmParameter<?>,MappingModelExpressable<?>> sqmParameterMappingModelTypes,
JdbcParameterBindings firstParameterBindings) {
this.selectStatement = selectStatement;
this.jdbcSelect = jdbcSelect;
@ -438,11 +447,11 @@ public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
return tableGroupAccess;
}
Map<QueryParameterImplementor<?>, Map<SqmParameter, List<List<JdbcParameter>>>> getJdbcParamsXref() {
Map<QueryParameterImplementor<?>, Map<SqmParameter<?>, List<List<JdbcParameter>>>> getJdbcParamsXref() {
return jdbcParamsXref;
}
public Map<SqmParameter, MappingModelExpressable> getSqmParameterMappingModelTypes() {
public Map<SqmParameter<?>, MappingModelExpressable<?>> getSqmParameterMappingModelTypes() {
return sqmParameterMappingModelTypes;
}

View File

@ -82,10 +82,10 @@ public class DomainParameterXref {
return empty();
}
final Map<QueryParameterImplementor<?>, List<SqmParameter>> sqmParamsByQueryParam = new IdentityHashMap<>();
final Map<QueryParameterImplementor<?>, List<SqmParameter<?>>> sqmParamsByQueryParam = new IdentityHashMap<>();
final int sqmParamCount = parameterResolutions.getSqmParameters().size();
final Map<SqmParameter, QueryParameterImplementor<?>> queryParamBySqmParam = new IdentityHashMap<>( sqmParamCount );
final Map<SqmParameter<?>, QueryParameterImplementor<?>> queryParamBySqmParam = new IdentityHashMap<>( sqmParamCount );
for ( SqmParameter<?> sqmParameter : parameterResolutions.getSqmParameters() ) {
if ( sqmParameter instanceof JpaCriteriaParameter ) {
@ -147,17 +147,17 @@ public class DomainParameterXref {
private final SqmStatement.ParameterResolutions parameterResolutions;
private final Map<QueryParameterImplementor<?>, List<SqmParameter>> sqmParamsByQueryParam;
private final Map<SqmParameter, QueryParameterImplementor<?>> queryParamBySqmParam;
private final Map<QueryParameterImplementor<?>, List<SqmParameter<?>>> sqmParamsByQueryParam;
private final Map<SqmParameter<?>, QueryParameterImplementor<?>> queryParamBySqmParam;
private Map<SqmParameter,List<SqmParameter>> expansions;
private Map<SqmParameter<?>,List<SqmParameter<?>>> expansions;
/**
* @implSpec Constructor is defined as public for
*/
public DomainParameterXref(
Map<QueryParameterImplementor<?>, List<SqmParameter>> sqmParamsByQueryParam,
Map<SqmParameter, QueryParameterImplementor<?>> queryParamBySqmParam,
Map<QueryParameterImplementor<?>, List<SqmParameter<?>>> sqmParamsByQueryParam,
Map<SqmParameter<?>, QueryParameterImplementor<?>> queryParamBySqmParam,
SqmStatement.ParameterResolutions parameterResolutions) {
this.sqmParamsByQueryParam = sqmParamsByQueryParam;
this.queryParamBySqmParam = queryParamBySqmParam;
@ -174,7 +174,7 @@ public class DomainParameterXref {
/**
* Get all of the QueryParameters mapped by this xref
*/
public Map<QueryParameterImplementor<?>, List<SqmParameter>> getQueryParameters() {
public Map<QueryParameterImplementor<?>, List<SqmParameter<?>>> getQueryParameters() {
return sqmParamsByQueryParam;
}
@ -187,7 +187,7 @@ public class DomainParameterXref {
}
public int getNumberOfSqmParameters(QueryParameterImplementor<?> queryParameter) {
final List<SqmParameter> sqmParameters = sqmParamsByQueryParam.get( queryParameter );
final List<SqmParameter<?>> sqmParameters = sqmParamsByQueryParam.get( queryParameter );
if ( sqmParameters == null ) {
// this should maybe be an exception instead
return 0;
@ -199,7 +199,7 @@ public class DomainParameterXref {
* Get the mapping of all QueryParameters to the List of its corresponding
* SqmParameters
*/
public Map<QueryParameterImplementor<?>, List<SqmParameter>> getSqmParamByQueryParam() {
public Map<QueryParameterImplementor<?>, List<SqmParameter<?>>> getSqmParamByQueryParam() {
return sqmParamsByQueryParam;
}
@ -207,13 +207,13 @@ public class DomainParameterXref {
return parameterResolutions;
}
public List<SqmParameter> getSqmParameters(QueryParameterImplementor<?> queryParameter) {
public List<SqmParameter<?>> getSqmParameters(QueryParameterImplementor<?> queryParameter) {
return sqmParamsByQueryParam.get( queryParameter );
}
public QueryParameterImplementor<?> getQueryParameter(SqmParameter sqmParameter) {
public QueryParameterImplementor<?> getQueryParameter(SqmParameter<?> sqmParameter) {
if ( sqmParameter instanceof SqmJpaCriteriaParameterWrapper ) {
return ( (SqmJpaCriteriaParameterWrapper) sqmParameter ).getJpaCriteriaParameter();
return ( (SqmJpaCriteriaParameterWrapper<?>) sqmParameter ).getJpaCriteriaParameter();
}
else if ( sqmParameter instanceof QueryParameterImplementor<?> ) {
return (QueryParameterImplementor<?>) sqmParameter;
@ -235,12 +235,12 @@ public class DomainParameterXref {
expansions.computeIfAbsent( originalSqmParameter, p -> new ArrayList<>() ).add( expansion );
}
public List<SqmParameter> getExpansions(SqmParameter sqmParameter) {
public List<SqmParameter<?>> getExpansions(SqmParameter<?> sqmParameter) {
if ( expansions == null ) {
return Collections.emptyList();
}
final List<SqmParameter> sqmParameters = expansions.get( sqmParameter );
final List<SqmParameter<?>> sqmParameters = expansions.get( sqmParameter );
return sqmParameters == null ? Collections.emptyList() : sqmParameters;
}
@ -249,8 +249,8 @@ public class DomainParameterXref {
return;
}
for ( List<SqmParameter> expansionList : expansions.values() ) {
for ( SqmParameter expansion : expansionList ) {
for ( List<SqmParameter<?>> expansionList : expansions.values() ) {
for ( SqmParameter<?> expansion : expansionList ) {
queryParamBySqmParam.remove( expansion );
}
}

View File

@ -15,6 +15,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
import org.hibernate.metamodel.mapping.MappingModelExpressable;
import org.hibernate.metamodel.mapping.MappingModelHelper;
import org.hibernate.query.NavigablePath;
import org.hibernate.query.spi.DomainQueryExecutionContext;
@ -22,6 +23,7 @@ import org.hibernate.query.spi.NonSelectQueryPlan;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.spi.QueryParameterImplementor;
import org.hibernate.query.sqm.mutation.internal.SqmMutationStrategyHelper;
import org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess;
import org.hibernate.query.sqm.sql.SqmTranslation;
import org.hibernate.query.sqm.sql.SqmTranslator;
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
@ -43,16 +45,16 @@ import org.hibernate.sql.results.internal.SqlSelectionImpl;
*/
public class SimpleDeleteQueryPlan implements NonSelectQueryPlan {
private final EntityMappingType entityDescriptor;
private final SqmDeleteStatement sqmDelete;
private final SqmDeleteStatement<?> sqmDelete;
private final DomainParameterXref domainParameterXref;
private JdbcDelete jdbcDelete;
private SqmTranslation<DeleteStatement> sqmInterpretation;
private Map<QueryParameterImplementor<?>, Map<SqmParameter, List<List<JdbcParameter>>>> jdbcParamsXref;
private Map<QueryParameterImplementor<?>, Map<SqmParameter<?>, List<List<JdbcParameter>>>> jdbcParamsXref;
public SimpleDeleteQueryPlan(
EntityMappingType entityDescriptor,
SqmDeleteStatement sqmDelete,
SqmDeleteStatement<?> sqmDelete,
DomainParameterXref domainParameterXref) {
assert entityDescriptor.getEntityName().equals( sqmDelete.getTarget().getEntityName() );
@ -103,7 +105,12 @@ public class SimpleDeleteQueryPlan implements NonSelectQueryPlan {
jdbcParamsXref,
factory.getDomainModel(),
sqmInterpretation.getFromClauseAccess()::findTableGroup,
sqmInterpretation.getSqmParameterMappingModelTypeResolutions()::get,
new SqmParameterMappingModelResolutionAccess() {
@Override @SuppressWarnings("unchecked")
public <T> MappingModelExpressable<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
return (MappingModelExpressable<T>) sqmInterpretation.getSqmParameterMappingModelTypeResolutions().get(parameter);
}
},
session
);

View File

@ -18,6 +18,7 @@ import org.hibernate.query.spi.DomainQueryExecutionContext;
import org.hibernate.query.spi.NonSelectQueryPlan;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.spi.QueryParameterImplementor;
import org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess;
import org.hibernate.query.sqm.sql.SqmTranslation;
import org.hibernate.query.sqm.sql.SqmTranslator;
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
@ -34,16 +35,16 @@ import org.hibernate.sql.exec.spi.JdbcParameterBindings;
* @author Gavin King
*/
public class SimpleInsertQueryPlan implements NonSelectQueryPlan {
private final SqmInsertStatement sqmInsert;
private final SqmInsertStatement<?> sqmInsert;
private final DomainParameterXref domainParameterXref;
private Map<SqmParameter, MappingModelExpressable> paramTypeResolutions;
private Map<SqmParameter<?>, MappingModelExpressable<?>> paramTypeResolutions;
private JdbcInsert jdbcInsert;
private FromClauseAccess tableGroupAccess;
private Map<QueryParameterImplementor<?>, Map<SqmParameter, List<List<JdbcParameter>>>> jdbcParamsXref;
private Map<QueryParameterImplementor<?>, Map<SqmParameter<?>, List<List<JdbcParameter>>>> jdbcParamsXref;
public SimpleInsertQueryPlan(
SqmInsertStatement sqmInsert,
SqmInsertStatement<?> sqmInsert,
DomainParameterXref domainParameterXref) {
this.sqmInsert = sqmInsert;
this.domainParameterXref = domainParameterXref;
@ -97,7 +98,12 @@ public class SimpleInsertQueryPlan implements NonSelectQueryPlan {
jdbcParamsXref,
factory.getDomainModel(),
tableGroupAccess::findTableGroup,
paramTypeResolutions::get,
new SqmParameterMappingModelResolutionAccess() {
@Override @SuppressWarnings("unchecked")
public <T> MappingModelExpressable<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
return (MappingModelExpressable<T>) paramTypeResolutions.get(parameter);
}
},
session
);

View File

@ -18,6 +18,7 @@ import org.hibernate.query.spi.DomainQueryExecutionContext;
import org.hibernate.query.spi.NonSelectQueryPlan;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.spi.QueryParameterImplementor;
import org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess;
import org.hibernate.query.sqm.sql.SqmTranslation;
import org.hibernate.query.sqm.sql.SqmTranslator;
import org.hibernate.query.sqm.sql.SqmTranslatorFactory;
@ -34,16 +35,16 @@ import org.hibernate.sql.exec.spi.JdbcUpdate;
* @author Steve Ebersole
*/
public class SimpleUpdateQueryPlan implements NonSelectQueryPlan {
private final SqmUpdateStatement sqmUpdate;
private final SqmUpdateStatement<?> sqmUpdate;
private final DomainParameterXref domainParameterXref;
private JdbcUpdate jdbcUpdate;
private FromClauseAccess tableGroupAccess;
private Map<QueryParameterImplementor<?>, Map<SqmParameter, List<List<JdbcParameter>>>> jdbcParamsXref;
private Map<SqmParameter,MappingModelExpressable> sqmParamMappingTypeResolutions;
private Map<QueryParameterImplementor<?>, Map<SqmParameter<?>, List<List<JdbcParameter>>>> jdbcParamsXref;
private Map<SqmParameter<?>,MappingModelExpressable<?>> sqmParamMappingTypeResolutions;
public SimpleUpdateQueryPlan(
SqmUpdateStatement sqmUpdate,
SqmUpdateStatement<?> sqmUpdate,
DomainParameterXref domainParameterXref) {
this.sqmUpdate = sqmUpdate;
this.domainParameterXref = domainParameterXref;
@ -66,7 +67,12 @@ public class SimpleUpdateQueryPlan implements NonSelectQueryPlan {
jdbcParamsXref,
factory.getDomainModel(),
tableGroupAccess::findTableGroup,
sqmParamMappingTypeResolutions::get,
new SqmParameterMappingModelResolutionAccess() {
@Override @SuppressWarnings("unchecked")
public <T> MappingModelExpressable<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
return (MappingModelExpressable<T>) sqmParamMappingTypeResolutions.get(parameter);
}
},
session
);

View File

@ -17,7 +17,6 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.engine.spi.SessionFactoryImplementor;
@ -70,7 +69,7 @@ public class SqmUtil {
private SqmUtil() {
}
public static void verifyIsSelectStatement(SqmStatement sqm, String hqlString) {
public static void verifyIsSelectStatement(SqmStatement<?> sqm, String hqlString) {
if ( !(sqm instanceof SqmSelectStatement) ) {
throw new IllegalQueryOperationException(
String.format(
@ -85,7 +84,7 @@ public class SqmUtil {
}
}
public static void verifyIsNonSelectStatement(SqmStatement sqm, String hqlString) {
public static void verifyIsNonSelectStatement(SqmStatement<?> sqm, String hqlString) {
if ( !(sqm instanceof SqmDmlStatement) ) {
throw new IllegalQueryOperationException(
String.format(
@ -100,7 +99,7 @@ public class SqmUtil {
}
}
public static Map<QueryParameterImplementor<?>, Map<SqmParameter, List<List<JdbcParameter>>>> generateJdbcParamsXref(
public static Map<QueryParameterImplementor<?>, Map<SqmParameter<?>, List<List<JdbcParameter>>>> generateJdbcParamsXref(
DomainParameterXref domainParameterXref,
JdbcParameterBySqmParameterAccess jdbcParameterBySqmParameterAccess) {
if ( domainParameterXref == null || !domainParameterXref.hasParameters() ) {
@ -108,23 +107,23 @@ public class SqmUtil {
}
final int queryParameterCount = domainParameterXref.getQueryParameterCount();
final Map<QueryParameterImplementor<?>, Map<SqmParameter, List<List<JdbcParameter>>>> result = new IdentityHashMap<>( queryParameterCount );
final Map<QueryParameterImplementor<?>, Map<SqmParameter<?>, List<List<JdbcParameter>>>> result = new IdentityHashMap<>( queryParameterCount );
for ( Map.Entry<QueryParameterImplementor<?>, List<SqmParameter>> entry : domainParameterXref.getSqmParamByQueryParam().entrySet() ) {
for ( Map.Entry<QueryParameterImplementor<?>, List<SqmParameter<?>>> entry : domainParameterXref.getSqmParamByQueryParam().entrySet() ) {
final QueryParameterImplementor<?> queryParam = entry.getKey();
final List<SqmParameter> sqmParams = entry.getValue();
final List<SqmParameter<?>> sqmParams = entry.getValue();
final Map<SqmParameter, List<List<JdbcParameter>>> sqmParamMap = result.computeIfAbsent(
final Map<SqmParameter<?>, List<List<JdbcParameter>>> sqmParamMap = result.computeIfAbsent(
queryParam,
qp -> new IdentityHashMap<>( sqmParams.size() )
);
for ( SqmParameter sqmParam : sqmParams ) {
for ( SqmParameter<?> sqmParam : sqmParams ) {
sqmParamMap.put( sqmParam, jdbcParameterBySqmParameterAccess.getJdbcParamsBySqmParam().get( sqmParam ) );
final List<SqmParameter> expansions = domainParameterXref.getExpansions( sqmParam );
final List<SqmParameter<?>> expansions = domainParameterXref.getExpansions( sqmParam );
if ( ! expansions.isEmpty() ) {
for ( SqmParameter expansion : expansions ) {
for ( SqmParameter<?> expansion : expansions ) {
sqmParamMap.put( expansion, jdbcParameterBySqmParameterAccess.getJdbcParamsBySqmParam().get( expansion ) );
result.put( queryParam, sqmParamMap );
}
@ -178,7 +177,7 @@ public class SqmUtil {
public static JdbcParameterBindings createJdbcParameterBindings(
QueryParameterBindings domainParamBindings,
DomainParameterXref domainParameterXref,
Map<QueryParameterImplementor<?>, Map<SqmParameter, List<List<JdbcParameter>>>> jdbcParamXref,
Map<QueryParameterImplementor<?>, Map<SqmParameter<?>, List<List<JdbcParameter>>>> jdbcParamXref,
MappingMetamodel domainModel,
Function<NavigablePath, TableGroup> tableGroupLocator,
SqmParameterMappingModelResolutionAccess mappingModelResolutionAccess,
@ -187,15 +186,15 @@ public class SqmUtil {
domainParameterXref.getSqmParameterCount()
);
for ( Map.Entry<QueryParameterImplementor<?>, List<SqmParameter>> entry :
for ( Map.Entry<QueryParameterImplementor<?>, List<SqmParameter<?>>> entry :
domainParameterXref.getSqmParamByQueryParam().entrySet() ) {
final QueryParameterImplementor<?> queryParam = entry.getKey();
final List<SqmParameter> sqmParameters = entry.getValue();
final List<SqmParameter<?>> sqmParameters = entry.getValue();
final QueryParameterBinding<?> domainParamBinding = domainParamBindings.getBinding( queryParam );
final Map<SqmParameter, List<List<JdbcParameter>>> jdbcParamMap = jdbcParamXref.get( queryParam );
sqm_params: for ( SqmParameter sqmParameter : sqmParameters ) {
final Map<SqmParameter<?>, List<List<JdbcParameter>>> jdbcParamMap = jdbcParamXref.get( queryParam );
for ( SqmParameter<?> sqmParameter : sqmParameters ) {
final Bindable parameterType = determineParameterType(
domainParamBinding,
queryParam,
@ -211,12 +210,12 @@ public class SqmUtil {
continue;
}
if ( !domainParamBinding.isBound() ) {
final MappingModelExpressable mappingExpressable = SqmMappingModelHelper.resolveMappingModelExpressable(
final MappingModelExpressable<?> mappingExpressable = SqmMappingModelHelper.resolveMappingModelExpressable(
sqmParameter,
domainModel,
tableGroupLocator
);
jdbc_params: for ( int i = 0; i < jdbcParamsBinds.size(); i++ ) {
for ( int i = 0; i < jdbcParamsBinds.size(); i++ ) {
final List<JdbcParameter> jdbcParams = jdbcParamsBinds.get( i );
mappingExpressable.forEachJdbcType(
(position, jdbcType) -> {
@ -248,11 +247,11 @@ public class SqmUtil {
}
// an then one for each of the expansions
final List<SqmParameter> expansions = domainParameterXref.getExpansions( sqmParameter );
final List<SqmParameter<?>> expansions = domainParameterXref.getExpansions( sqmParameter );
assert expansions.size() == bindValues.size() - 1;
int expansionPosition = 0;
while ( valueItr.hasNext() ) {
final SqmParameter expansionSqmParam = expansions.get( expansionPosition++ );
final SqmParameter<?> expansionSqmParam = expansions.get( expansionPosition++ );
final List<List<JdbcParameter>> jdbcParamBinds = jdbcParamMap.get( expansionSqmParam );
for ( int i = 0; i < jdbcParamBinds.size(); i++ ) {
List<JdbcParameter> expansionJdbcParams = jdbcParamBinds.get( i );
@ -287,7 +286,7 @@ public class SqmUtil {
final JdbcMapping jdbcMapping;
if ( domainParamBinding.getType() instanceof AttributeConverterTypeAdapter ) {
final AttributeConverterTypeAdapter adapter = (AttributeConverterTypeAdapter) domainParamBinding.getType();
final AttributeConverterTypeAdapter<?> adapter = (AttributeConverterTypeAdapter<?>) domainParamBinding.getType();
valueConverter = adapter.getAttributeConverter();
jdbcMapping = adapter.getJdbcMapping();
}
@ -310,7 +309,7 @@ public class SqmUtil {
);
}
continue sqm_params;
continue;
}
}
@ -394,7 +393,7 @@ public class SqmUtil {
public static Bindable determineParameterType(
QueryParameterBinding<?> binding,
QueryParameterImplementor<?> parameter,
List<SqmParameter> sqmParameters,
List<SqmParameter<?>> sqmParameters,
SqmParameterMappingModelResolutionAccess mappingModelResolutionAccess,
SessionFactoryImplementor sessionFactory) {
if ( binding.getType() != null ) {

View File

@ -19,12 +19,14 @@ import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.MappingModelExpressable;
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.query.spi.DomainQueryExecutionContext;
import org.hibernate.query.sqm.internal.DomainParameterXref;
import org.hibernate.query.sqm.internal.SqmJdbcExecutionContextAdapter;
import org.hibernate.query.sqm.internal.SqmUtil;
import org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess;
import org.hibernate.query.sqm.sql.internal.SqlAstQueryPartProcessingStateImpl;
import org.hibernate.query.sqm.tree.SqmDeleteOrUpdateStatement;
import org.hibernate.query.sqm.tree.expression.SqmParameter;
@ -281,10 +283,16 @@ public class MatchingIdSelectionHelper {
final JdbcParameterBindings jdbcParameterBindings = SqmUtil.createJdbcParameterBindings(
executionContext.getQueryParameterBindings(),
domainParameterXref,
SqmUtil.generateJdbcParamsXref( domainParameterXref, sqmConverter ),
SqmUtil.generateJdbcParamsXref(domainParameterXref, sqmConverter),
factory.getDomainModel(),
navigablePath -> sqmConverter.getMutatingTableGroup(),
sqmConverter.getSqmParameterMappingModelExpressableResolutions()::get,
new SqmParameterMappingModelResolutionAccess() {
@Override @SuppressWarnings("unchecked")
public <T> MappingModelExpressable<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
return (MappingModelExpressable<T>) sqmConverter.getSqmParameterMappingModelExpressableResolutions().get(parameter);
}
}
,
executionContext.getSession()
);
final LockOptions lockOptions = executionContext.getQueryOptions().getLockOptions();

View File

@ -57,7 +57,7 @@ import org.hibernate.sql.ast.tree.update.Assignment;
*/
public class MultiTableSqmMutationConverter extends BaseSqmToSqlAstConverter<Statement> {
public interface SqmParameterResolutionConsumer {
void accept(SqmParameter sqmParam, MappingModelExpressable mappingType, List<JdbcParameter> jdbcParameters);
void accept(SqmParameter<?> sqmParam, MappingModelExpressable<?> mappingType, List<JdbcParameter> jdbcParameters);
}
private final EntityMappingType mutatingEntityDescriptor;
@ -231,7 +231,7 @@ public class MultiTableSqmMutationConverter extends BaseSqmToSqlAstConverter<Sta
}
@Override
protected Expression consumeSingleSqmParameter(SqmParameter sqmParameter) {
protected Expression consumeSingleSqmParameter(SqmParameter<?> sqmParameter) {
assert parameterResolutionConsumer != null;
final Expression expression = super.consumeSingleSqmParameter( sqmParameter );

View File

@ -49,6 +49,7 @@ import org.hibernate.query.sqm.internal.SqmJdbcExecutionContextAdapter;
import org.hibernate.query.sqm.internal.SqmUtil;
import org.hibernate.query.sqm.mutation.internal.InsertHandler;
import org.hibernate.query.sqm.mutation.internal.MultiTableSqmMutationConverter;
import org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess;
import org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter;
import org.hibernate.query.sqm.tree.cte.SqmCteTable;
import org.hibernate.query.sqm.tree.cte.SqmCteTableColumn;
@ -173,7 +174,7 @@ public class CteInsertHandler implements InsertHandler {
);
final TableGroup insertingTableGroup = sqmConverter.getMutatingTableGroup();
final Map<SqmParameter, List<List<JdbcParameter>>> parameterResolutions;
final Map<SqmParameter<?>, List<List<JdbcParameter>>> parameterResolutions;
if ( domainParameterXref.getSqmParameterCount() == 0 ) {
parameterResolutions = Collections.emptyMap();
}
@ -188,7 +189,7 @@ public class CteInsertHandler implements InsertHandler {
final int size = sqmStatement.getInsertionTargetPaths().size();
final List<Map.Entry<SqmCteTableColumn, Assignment>> targetPathColumns = new ArrayList<>( size );
final List<SqmCteTableColumn> targetPathSqmCteColumns = new ArrayList<>( size );
final Map<SqmParameter, MappingModelExpressable> paramTypeResolutions = new LinkedHashMap<>();
final Map<SqmParameter<?>, MappingModelExpressable<?>> paramTypeResolutions = new LinkedHashMap<>();
final NamedTableReference entityTableReference = new NamedTableReference(
cteTable.getCteName(),
TemporaryTable.DEFAULT_ALIAS,
@ -629,7 +630,7 @@ public class CteInsertHandler implements InsertHandler {
final Expression count = createCountStar( factory, sqmConverter );
domainResults.add(
new BasicResult<>(
new BasicResult(
0,
null,
( (SqlExpressable) count).getJdbcMapping().getJavaTypeDescriptor()
@ -656,10 +657,15 @@ public class CteInsertHandler implements InsertHandler {
final JdbcParameterBindings jdbcParameterBindings = SqmUtil.createJdbcParameterBindings(
executionContext.getQueryParameterBindings(),
domainParameterXref,
SqmUtil.generateJdbcParamsXref( domainParameterXref, sqmConverter ),
SqmUtil.generateJdbcParamsXref(domainParameterXref, sqmConverter),
factory.getDomainModel(),
navigablePath -> sqmConverter.getMutatingTableGroup(),
paramTypeResolutions::get,
new SqmParameterMappingModelResolutionAccess() {
@Override @SuppressWarnings("unchecked")
public <T> MappingModelExpressable<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
return (MappingModelExpressable<T>) paramTypeResolutions.get(parameter);
}
},
executionContext.getSession()
);
final JdbcSelect select = translator.translate( jdbcParameterBindings, executionContext.getQueryOptions() );
@ -694,7 +700,7 @@ public class CteInsertHandler implements InsertHandler {
List<Map.Entry<SqmCteTableColumn, Assignment>> assignments,
boolean assignsId,
MultiTableSqmMutationConverter sqmConverter,
Map<SqmParameter, List<List<JdbcParameter>>> parameterResolutions,
Map<SqmParameter<?>, List<List<JdbcParameter>>> parameterResolutions,
SessionFactoryImplementor factory) {
final TableGroup updatingTableGroup = sqmConverter.getMutatingTableGroup();
final EntityMappingType entityDescriptor = getEntityDescriptor();

View File

@ -42,6 +42,7 @@ import org.hibernate.query.spi.DomainQueryExecutionContext;
import org.hibernate.query.sqm.internal.DomainParameterXref;
import org.hibernate.query.sqm.internal.SqmUtil;
import org.hibernate.query.sqm.mutation.internal.MultiTableSqmMutationConverter;
import org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess;
import org.hibernate.query.sqm.tree.expression.SqmParameter;
import org.hibernate.query.sqm.tree.insert.SqmInsertStatement;
import org.hibernate.sql.ast.tree.expression.ColumnReference;
@ -89,7 +90,7 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
private final JdbcParameterBindings jdbcParameterBindings;
private final Map<TableReference, List<Assignment>> assignmentsByTable;
private final Map<SqmParameter, MappingModelExpressable> paramTypeResolutions;
private final Map<SqmParameter<?>, MappingModelExpressable<?>> paramTypeResolutions;
private final SessionFactoryImplementor sessionFactory;
public InsertExecutionDelegate(
@ -103,8 +104,8 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
Map<String, TableReference> tableReferenceByAlias,
List<Assignment> assignments,
InsertStatement insertStatement,
Map<SqmParameter, List<List<JdbcParameter>>> parameterResolutions,
Map<SqmParameter, MappingModelExpressable> paramTypeResolutions,
Map<SqmParameter<?>, List<List<JdbcParameter>>> parameterResolutions,
Map<SqmParameter<?>, MappingModelExpressable<?>> paramTypeResolutions,
DomainQueryExecutionContext executionContext) {
this.sqmInsert = sqmInsert;
this.sqmConverter = sqmConverter;
@ -134,7 +135,13 @@ public class InsertExecutionDelegate implements TableBasedInsertHandler.Executio
),
sessionFactory.getDomainModel(),
navigablePath -> insertingTableGroup,
paramTypeResolutions::get,
new SqmParameterMappingModelResolutionAccess() {
@Override @SuppressWarnings("unchecked")
public <T> MappingModelExpressable<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
return (MappingModelExpressable<T>) paramTypeResolutions.get(parameter);
}
}
,
executionContext.getSession()
);

View File

@ -39,6 +39,7 @@ import org.hibernate.query.sqm.internal.SqmJdbcExecutionContextAdapter;
import org.hibernate.query.sqm.internal.SqmUtil;
import org.hibernate.query.sqm.mutation.internal.MultiTableSqmMutationConverter;
import org.hibernate.query.sqm.mutation.internal.SqmMutationStrategyHelper;
import org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess;
import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement;
import org.hibernate.query.sqm.tree.expression.SqmParameter;
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
@ -121,8 +122,8 @@ public class RestrictedDeleteExecutionDelegate implements TableBasedDeleteHandle
);
assert hierarchyRootTableReference != null;
final Map<SqmParameter, List<List<JdbcParameter>>> parameterResolutions;
final Map<SqmParameter, MappingModelExpressable> paramTypeResolutions;
final Map<SqmParameter<?>, List<List<JdbcParameter>>> parameterResolutions;
final Map<SqmParameter<?>, MappingModelExpressable<?>> paramTypeResolutions;
if ( domainParameterXref.getSqmParameterCount() == 0 ) {
parameterResolutions = Collections.emptyMap();
@ -203,8 +204,8 @@ public class RestrictedDeleteExecutionDelegate implements TableBasedDeleteHandle
private int executeWithoutIdTable(
Predicate suppliedPredicate,
TableGroup tableGroup,
Map<SqmParameter, List<List<JdbcParameter>>> restrictionSqmParameterResolutions,
Map<SqmParameter, MappingModelExpressable> paramTypeResolutions,
Map<SqmParameter<?>, List<List<JdbcParameter>>> restrictionSqmParameterResolutions,
Map<SqmParameter<?>, MappingModelExpressable<?>> paramTypeResolutions,
SqlExpressionResolver sqlExpressionResolver,
ExecutionContext executionContext) {
assert entityDescriptor == entityDescriptor.getRootEntityDescriptor();
@ -234,7 +235,12 @@ public class RestrictedDeleteExecutionDelegate implements TableBasedDeleteHandle
),
sessionFactory.getDomainModel(),
navigablePath -> tableGroup,
paramTypeResolutions::get,
new SqmParameterMappingModelResolutionAccess() {
@Override @SuppressWarnings("unchecked")
public <T> MappingModelExpressable<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
return (MappingModelExpressable<T>) paramTypeResolutions.get(parameter);
}
},
executionContext.getSession()
);
@ -466,8 +472,8 @@ public class RestrictedDeleteExecutionDelegate implements TableBasedDeleteHandle
private int executeWithIdTable(
Predicate predicate,
TableGroup deletingTableGroup,
Map<SqmParameter, List<List<JdbcParameter>>> restrictionSqmParameterResolutions,
Map<SqmParameter, MappingModelExpressable> paramTypeResolutions,
Map<SqmParameter<?>, List<List<JdbcParameter>>> restrictionSqmParameterResolutions,
Map<SqmParameter<?>, MappingModelExpressable<?>> paramTypeResolutions,
ExecutionContext executionContext) {
final JdbcParameterBindings jdbcParameterBindings = SqmUtil.createJdbcParameterBindings(
executionContext.getQueryParameterBindings(),
@ -478,7 +484,12 @@ public class RestrictedDeleteExecutionDelegate implements TableBasedDeleteHandle
),
sessionFactory.getDomainModel(),
navigablePath -> deletingTableGroup,
paramTypeResolutions::get,
new SqmParameterMappingModelResolutionAccess() {
@Override @SuppressWarnings("unchecked")
public <T> MappingModelExpressable<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
return (MappingModelExpressable<T>) paramTypeResolutions.get(parameter);
}
},
executionContext.getSession()
);

View File

@ -80,7 +80,7 @@ public class TableBasedDeleteHandler
}
@Override
public SqmDeleteStatement getSqmDeleteOrUpdateStatement() {
return (SqmDeleteStatement) super.getSqmDeleteOrUpdateStatement();
public SqmDeleteStatement<?> getSqmDeleteOrUpdateStatement() {
return (SqmDeleteStatement<?>) super.getSqmDeleteOrUpdateStatement();
}
}

View File

@ -129,7 +129,7 @@ public class TableBasedInsertHandler implements InsertHandler {
final TableGroup insertingTableGroup = converterDelegate.getMutatingTableGroup();
final Map<SqmParameter, List<List<JdbcParameter>>> parameterResolutions;
final Map<SqmParameter<?>, List<List<JdbcParameter>>> parameterResolutions;
if ( domainParameterXref.getSqmParameterCount() == 0 ) {
parameterResolutions = Collections.emptyMap();
}
@ -142,7 +142,7 @@ public class TableBasedInsertHandler implements InsertHandler {
// information about the target paths
final List<Assignment> targetPathColumns = new ArrayList<>();
final Map<SqmParameter, MappingModelExpressable> paramTypeResolutions = new LinkedHashMap<>();
final Map<SqmParameter<?>, MappingModelExpressable<?>> paramTypeResolutions = new LinkedHashMap<>();
final NamedTableReference entityTableReference = new NamedTableReference(
entityTable.getTableExpression(),
TemporaryTable.DEFAULT_ALIAS,

View File

@ -79,13 +79,13 @@ public class TableBasedUpdateHandler
this.entityDescriptor = sessionFactory.getDomainModel().getEntityDescriptor( targetEntityName );
}
protected SqmUpdateStatement getSqmUpdate() {
protected SqmUpdateStatement<?> getSqmUpdate() {
return getSqmDeleteOrUpdateStatement();
}
@Override
public SqmUpdateStatement getSqmDeleteOrUpdateStatement() {
return (SqmUpdateStatement) super.getSqmDeleteOrUpdateStatement();
public SqmUpdateStatement<?> getSqmDeleteOrUpdateStatement() {
return (SqmUpdateStatement<?>) super.getSqmDeleteOrUpdateStatement();
}
@ -131,7 +131,7 @@ public class TableBasedUpdateHandler
);
assert hierarchyRootTableReference != null;
final Map<SqmParameter, List<List<JdbcParameter>>> parameterResolutions;
final Map<SqmParameter<?>, List<List<JdbcParameter>>> parameterResolutions;
if ( domainParameterXref.getSqmParameterCount() == 0 ) {
parameterResolutions = Collections.emptyMap();
}
@ -144,7 +144,7 @@ public class TableBasedUpdateHandler
// information about the assignments
final List<Assignment> assignments = new ArrayList<>();
final Map<SqmParameter, MappingModelExpressable> paramTypeResolutions = new LinkedHashMap<>();
final Map<SqmParameter<?>, MappingModelExpressable<?>> paramTypeResolutions = new LinkedHashMap<>();
converterDelegate.visitSetClause(
getSqmDeleteOrUpdateStatement().getSetClause(),

View File

@ -27,6 +27,7 @@ import org.hibernate.query.spi.DomainQueryExecutionContext;
import org.hibernate.query.sqm.internal.DomainParameterXref;
import org.hibernate.query.sqm.internal.SqmUtil;
import org.hibernate.query.sqm.mutation.internal.MultiTableSqmMutationConverter;
import org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess;
import org.hibernate.query.sqm.tree.expression.SqmParameter;
import org.hibernate.query.sqm.tree.update.SqmUpdateStatement;
import org.hibernate.sql.ast.tree.expression.ColumnReference;
@ -48,7 +49,7 @@ import org.hibernate.sql.exec.spi.JdbcUpdate;
* @author Steve Ebersole
*/
public class UpdateExecutionDelegate implements TableBasedUpdateHandler.ExecutionDelegate {
private final SqmUpdateStatement sqmUpdate;
private final SqmUpdateStatement<?> sqmUpdate;
private final MultiTableSqmMutationConverter sqmConverter;
private final TemporaryTable idTable;
private final AfterUseAction afterUseAction;
@ -62,7 +63,7 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio
private final JdbcParameterBindings jdbcParameterBindings;
private final Map<TableReference, List<Assignment>> assignmentsByTable;
private final Map<SqmParameter, MappingModelExpressable> paramTypeResolutions;
private final Map<SqmParameter<?>, MappingModelExpressable<?>> paramTypeResolutions;
private final SessionFactoryImplementor sessionFactory;
public UpdateExecutionDelegate(
@ -77,8 +78,8 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio
Map<String, TableReference> tableReferenceByAlias,
List<Assignment> assignments,
Predicate suppliedPredicate,
Map<SqmParameter, List<List<JdbcParameter>>> parameterResolutions,
Map<SqmParameter, MappingModelExpressable> paramTypeResolutions,
Map<SqmParameter<?>, List<List<JdbcParameter>>> parameterResolutions,
Map<SqmParameter<?>, MappingModelExpressable<?>> paramTypeResolutions,
DomainQueryExecutionContext executionContext) {
this.sqmUpdate = sqmUpdate;
this.sqmConverter = sqmConverter;
@ -108,7 +109,12 @@ public class UpdateExecutionDelegate implements TableBasedUpdateHandler.Executio
),
sessionFactory.getDomainModel(),
navigablePath -> updatingTableGroup,
paramTypeResolutions::get,
new SqmParameterMappingModelResolutionAccess() {
@Override @SuppressWarnings("unchecked")
public <T> MappingModelExpressable<T> getResolvedMappingModelType(SqmParameter<T> parameter) {
return (MappingModelExpressable<T>) paramTypeResolutions.get(parameter);
}
},
executionContext.getSession()
);

View File

@ -134,14 +134,14 @@ public class PatternRenderer {
@SuppressWarnings({ "UnusedDeclaration" })
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> args,
List<? extends SqlAstNode> args,
SqlAstTranslator<?> translator) {
render( sqlAppender, args, null, translator );
}
public void render(
SqlAppender sqlAppender,
List<SqlAstNode> args,
List<? extends SqlAstNode> args,
Predicate filter,
SqlAstTranslator<?> translator) {
final int numberOfArguments = args.size();

View File

@ -22,5 +22,5 @@ public interface JdbcParameterBySqmParameterAccess {
/**
* The mapping between an SqmParameter and all of its JDBC parameters
*/
Map<SqmParameter, List<List<JdbcParameter>>> getJdbcParamsBySqmParam();
Map<SqmParameter<?>, List<List<JdbcParameter>>> getJdbcParamsBySqmParam();
}

View File

@ -233,7 +233,6 @@ import org.hibernate.sql.ast.spi.SqlAstQueryPartProcessingState;
import org.hibernate.sql.ast.spi.SqlAstTreeHelper;
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
import org.hibernate.sql.ast.spi.SqlSelection;
import org.hibernate.sql.ast.tree.SqlAstNode;
import org.hibernate.sql.ast.tree.Statement;
import org.hibernate.sql.ast.tree.cte.CteColumn;
import org.hibernate.sql.ast.tree.cte.CteStatement;
@ -349,7 +348,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
private final DomainParameterXref domainParameterXref;
private final QueryParameterBindings domainParameterBindings;
private final Map<SqmParameter,MappingModelExpressable> sqmParameterMappingModelTypes = new LinkedHashMap<>();
private final Map<SqmParameter<?>,MappingModelExpressable<?>> sqmParameterMappingModelTypes = new LinkedHashMap<>();
private final Map<JpaCriteriaParameter<?>, SqmJpaCriteriaParameterWrapper<?>> jpaCriteriaParamResolutions;
private final List<DomainResult<?>> domainResults;
private final EntityGraphTraversalState entityGraphTraversalState;
@ -437,7 +436,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
.getJpaCriteriaParamResolutions();
}
public Map<SqmParameter, MappingModelExpressable> getSqmParameterMappingModelExpressableResolutions() {
public Map<SqmParameter<?>,MappingModelExpressable<?>> getSqmParameterMappingModelExpressableResolutions() {
return sqmParameterMappingModelTypes;
}
@ -597,7 +596,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
// Update statement
@Override
public UpdateStatement visitUpdateStatement(SqmUpdateStatement sqmStatement) {
public UpdateStatement visitUpdateStatement(SqmUpdateStatement<?> sqmStatement) {
Map<String, CteStatement> cteStatements = this.visitCteContainer( sqmStatement );
final SqmRoot<?> sqmTarget = sqmStatement.getTarget();
@ -754,9 +753,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
getFromClauseIndex()
);
final SqmPathInterpretation assignedPathInterpretation;
final SqmPathInterpretation<?> assignedPathInterpretation;
try {
assignedPathInterpretation = (SqmPathInterpretation) sqmAssignment.getTargetPath().accept( this );
assignedPathInterpretation = (SqmPathInterpretation<?>) sqmAssignment.getTargetPath().accept( this );
}
finally {
popProcessingStateStack();
@ -764,7 +763,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
inferrableTypeAccessStack.push( assignedPathInterpretation::getExpressionType );
final List<ColumnReference> valueColumnReferences = new ArrayList<>();
// final List<ColumnReference> valueColumnReferences = new ArrayList<>();
pushProcessingState(
new SqlAstProcessingStateImpl(
getCurrentProcessingState(),
@ -778,7 +777,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
.getSqlExpressionResolver()
.resolveSqlExpression( key, creator );
assert expression instanceof ColumnReference;
valueColumnReferences.add( (ColumnReference) expression );
// valueColumnReferences.add( (ColumnReference) expression );
return expression;
}
},
@ -858,7 +857,8 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
true,
rootPath,
statement.getRoot().getAlias(),
() -> predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates( additionalRestrictions, predicate ),
() -> predicate -> additionalRestrictions
= SqlAstTreeHelper.combinePredicates( additionalRestrictions, predicate ),
this,
getCreationContext()
);
@ -937,7 +937,8 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
true,
rootPath,
sqmStatement.getTarget().getExplicitAlias(),
() -> predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates( additionalRestrictions, predicate ),
() -> predicate -> additionalRestrictions
= SqlAstTreeHelper.combinePredicates( additionalRestrictions, predicate ),
this,
getCreationContext()
);
@ -1011,7 +1012,8 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
true,
rootPath,
sqmStatement.getTarget().getExplicitAlias(),
() -> predicate -> additionalRestrictions = SqlAstTreeHelper.combinePredicates( additionalRestrictions, predicate ),
() -> predicate -> additionalRestrictions
= SqlAstTreeHelper.combinePredicates( additionalRestrictions, predicate ),
this,
getCreationContext()
);
@ -1042,8 +1044,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
throw new SemanticException( "Not expecting multiple table references for an SQM INSERT-SELECT" );
}
List<SqmValues> valuesList = sqmStatement.getValuesList();
for ( SqmValues sqmValues : valuesList ) {
for ( SqmValues sqmValues : sqmStatement.getValuesList() ) {
final Values values = visitValues( sqmValues );
additionalInsertValues.applyValues( values );
insertStatement.getValuesList().add( values );
@ -1249,9 +1250,10 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
return true;
}
}
final String fragment = ( (BulkInsertionCapableIdentifierGenerator) identifierGenerator ).determineBulkInsertionIdentifierGenerationSelectFragment(
sessionFactory.getSqlStringGenerationContext()
);
final String fragment = ( (BulkInsertionCapableIdentifierGenerator) identifierGenerator )
.determineBulkInsertionIdentifierGenerationSelectFragment(
sessionFactory.getSqlStringGenerationContext()
);
// The position is irrelevant as this is only needed for insert
identifierSelection = new SqlSelectionImpl(
1,
@ -1392,15 +1394,13 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
forEachCteColumn(
cteTable,
specification.getCteColumn(),
cteColumn -> {
searchClauseSpecifications.add(
new SearchClauseSpecification(
cteColumn,
specification.getSortOrder(),
specification.getNullPrecedence()
)
);
}
cteColumn -> searchClauseSpecifications.add(
new SearchClauseSpecification(
cteColumn,
specification.getSortOrder(),
specification.getNullPrecedence()
)
)
);
}
@ -1473,14 +1473,12 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
}
if ( valueMapping instanceof EmbeddableValuedModelPart ) {
valueMapping.forEachJdbcType(
(index, jdbcMapping) -> {
sqlCteColumns.add(
new CteColumn(
sqmCteTableColumn.getColumnName() + "_" + index,
jdbcMapping
)
);
}
(index, jdbcMapping) -> sqlCteColumns.add(
new CteColumn(
sqmCteTableColumn.getColumnName() + "_" + index,
jdbcMapping
)
)
);
}
else {
@ -1715,13 +1713,13 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
final TableGroup root = roots.get( 0 );
if ( CollectionHelper.isNotEmpty( collectionFilterPredicates ) ) {
root.getTableGroupJoins().forEach( (tableGroupJoin) -> {
collectionFilterPredicates.forEach( (alias, predicates) -> {
if ( tableGroupJoin.getJoinedGroup().getGroupAlias().equals( alias ) ) {
tableGroupJoin.applyPredicate( predicates.getPredicate() );
}
} );
} );
root.getTableGroupJoins().forEach( (tableGroupJoin) ->
collectionFilterPredicates.forEach( (alias, predicates) -> {
if ( tableGroupJoin.getJoinedGroup().getGroupAlias().equals( alias ) ) {
tableGroupJoin.applyPredicate( predicates.getPredicate() );
}
} )
);
}
}
}
@ -2036,13 +2034,13 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
);
}
public QuerySpec visitOffsetAndFetchExpressions(QuerySpec sqlQuerySpec, SqmQuerySpec<?> sqmQuerySpec) {
final Expression offsetExpression = visitOffsetExpression( sqmQuerySpec.getOffsetExpression() );
final Expression fetchExpression = visitFetchExpression( sqmQuerySpec.getFetchExpression() );
sqlQuerySpec.setOffsetClauseExpression( offsetExpression );
sqlQuerySpec.setFetchClauseExpression( fetchExpression, sqmQuerySpec.getFetchClauseType() );
return sqlQuerySpec;
}
// public QuerySpec visitOffsetAndFetchExpressions(QuerySpec sqlQuerySpec, SqmQuerySpec<?> sqmQuerySpec) {
// final Expression offsetExpression = visitOffsetExpression( sqmQuerySpec.getOffsetExpression() );
// final Expression fetchExpression = visitFetchExpression( sqmQuerySpec.getFetchExpression() );
// sqlQuerySpec.setOffsetClauseExpression( offsetExpression );
// sqlQuerySpec.setFetchClauseExpression( fetchExpression, sqmQuerySpec.getFetchClauseType() );
// return sqlQuerySpec;
// }
@Override
public Expression visitOffsetExpression(SqmExpression<?> expression) {
@ -2958,7 +2956,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
}
@Override
public Expression visitQualifiedEntityJoin(SqmEntityJoin sqmJoin) {
public Expression visitQualifiedEntityJoin(SqmEntityJoin<?> sqmJoin) {
// todo (6.0) : have this resolve to TableGroup instead?
// - trying to remove tracking of TableGroupJoin in the x-refs
@ -3028,7 +3026,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
EntityMappingType mappingType;
if ( path instanceof SqmTreatedPath ) {
mappingType = creationContext.getDomainModel()
.findEntityDescriptor( ( (SqmTreatedPath) path ).getTreatTarget().getHibernateEntityName() );
.findEntityDescriptor( ( (SqmTreatedPath<?,?>) path ).getTreatTarget().getHibernateEntityName() );
}
else {
mappingType = mapping.getEntityMappingType();
@ -3371,7 +3369,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
.getBasicTypeForJavaType( Integer.class );
final Expression expression = new SelfRenderingAggregateFunctionSqlAstExpression(
functionDescriptor.getName(),
functionDescriptor::render,
functionDescriptor,
Collections.singletonList( new QueryLiteral<>( 1, integerType ) ),
null,
integerType,
@ -3537,35 +3535,34 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
tupleElements = new ArrayList<>( jdbcTypeCount );
}
modelPart.forEachSelectable(
(selectionIndex, selectionMapping) -> {
tupleElements.add(
new ColumnReference(
tableGroup.resolveTableReference(
navigablePath,
selectionMapping.getContainingTableExpression()
),
selectionMapping,
creationContext.getSessionFactory()
)
);
}
(selectionIndex, selectionMapping) -> tupleElements.add(
new ColumnReference(
tableGroup.resolveTableReference(
navigablePath,
selectionMapping.getContainingTableExpression()
),
selectionMapping,
creationContext.getSessionFactory()
)
)
);
if ( jdbcTypeCount != 1 ) {
arguments.add( new SqlTuple( tupleElements, modelPart ) );
}
final Expression expression = new SelfRenderingAggregateFunctionSqlAstExpression(
functionDescriptor.getName(),
functionDescriptor::render,
(List<SqlAstNode>) (List<?>) arguments,
functionDescriptor,
arguments,
null,
(AllowableFunctionReturnType<?>) modelPart.getJdbcMappings().get( 0 ),
modelPart
);
subQuerySpec.getSelectClause().addSqlSelection( new SqlSelectionImpl( 1, 0, expression ) );
NavigablePath parent = pluralPartPath.getPluralDomainPath().getNavigablePath().getParent();
subQuerySpec.applyPredicate(
pluralAttributeMapping.getKeyDescriptor().generateJoinPredicate(
parentFromClauseAccess.findTableGroup( pluralPartPath.getPluralDomainPath().getNavigablePath().getParent() ),
parentFromClauseAccess.findTableGroup( parent ),
tableGroup,
SqlAstJoinType.INNER,
getSqlExpressionResolver(),
@ -3776,19 +3773,17 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
else {
final List<ColumnReference> resultColumnReferences = new ArrayList<>( jdbcTypeCount );
modelPart.forEachSelectable(
(selectionIndex, selectionMapping) -> {
resultColumnReferences.add(
new ColumnReference(
identifierVariable,
tableReference.getColumnNames().get( selectionIndex ),
false,
null,
null,
selectionMapping.getJdbcMapping(),
creationContext.getSessionFactory()
)
);
}
(selectionIndex, selectionMapping) -> resultColumnReferences.add(
new ColumnReference(
identifierVariable,
tableReference.getColumnNames().get( selectionIndex ),
false,
null,
null,
selectionMapping.getJdbcMapping(),
creationContext.getSessionFactory()
)
)
);
return new SqlTuple( resultColumnReferences, modelPart );
}
@ -3851,7 +3846,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
@Override
public Expression visitLiteral(SqmLiteral<?> literal) {
final Supplier<MappingModelExpressable> inferableTypeAccess = inferrableTypeAccessStack.getCurrent();
final Supplier<MappingModelExpressable<?>> inferableTypeAccess = inferrableTypeAccessStack.getCurrent();
if ( literal instanceof SqmLiteralNull ) {
MappingModelExpressable<?> mappingModelExpressable = inferableTypeAccess.get();
@ -3884,7 +3879,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
if ( inferableExpressable instanceof ConvertibleModelPart ) {
final ConvertibleModelPart convertibleModelPart = (ConvertibleModelPart) inferableExpressable;
final BasicValueConverter<Object, Object> valueConverter = convertibleModelPart.getValueConverter();
final BasicValueConverter valueConverter = convertibleModelPart.getValueConverter();
if ( valueConverter != null ) {
final Object literalValue = literal.getLiteralValue();
@ -3980,9 +3975,8 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
embeddableValuedModelPart.forEachJdbcValue(
literal.getLiteralValue(),
null,
(selectionIndex, value, jdbcMapping) -> {
list.add( new QueryLiteral<>( value, (BasicValuedMapping) jdbcMapping ) );
},
(selectionIndex, value, jdbcMapping)
-> list.add( new QueryLiteral<>( value, (BasicValuedMapping) jdbcMapping ) ),
null
);
return new SqlTuple( list, expressable );
@ -4021,9 +4015,8 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
associationKeyPart.forEachJdbcValue(
associationKey,
null,
(selectionIndex, value, jdbcMapping) -> {
list.add( new QueryLiteral<>( value, (BasicValuedMapping) jdbcMapping ) );
},
(selectionIndex, value, jdbcMapping)
-> list.add( new QueryLiteral<>( value, (BasicValuedMapping) jdbcMapping ) ),
null
);
return new SqlTuple( list, associationKeyPart );
@ -4054,11 +4047,11 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
}
}
private final Map<SqmParameter, List<List<JdbcParameter>>> jdbcParamsBySqmParam = new IdentityHashMap<>();
private final Map<SqmParameter<?>, List<List<JdbcParameter>>> jdbcParamsBySqmParam = new IdentityHashMap<>();
private final JdbcParameters jdbcParameters = new JdbcParametersImpl();
@Override
public Map<SqmParameter, List<List<JdbcParameter>>> getJdbcParamsBySqmParam() {
public Map<SqmParameter<?>, List<List<JdbcParameter>>> getJdbcParamsBySqmParam() {
return jdbcParamsBySqmParam;
}
@ -4068,9 +4061,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
}
protected Expression consumeSqmParameter(
SqmParameter sqmParameter,
SqmParameter<?> sqmParameter,
BiConsumer<Integer,JdbcParameter> jdbcParameterConsumer) {
final MappingModelExpressable valueMapping = determineValueMapping( sqmParameter );
final MappingModelExpressable<?> valueMapping = determineValueMapping( sqmParameter );
final List<JdbcParameter> jdbcParametersForSqm = new ArrayList<>();
@ -4089,7 +4082,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
.add( jdbcParametersForSqm );
final QueryParameterImplementor<?> queryParameter = domainParameterXref.getQueryParameter( sqmParameter );
final QueryParameterBinding<?> binding = domainParameterBindings.getBinding( queryParameter );
final QueryParameterBinding binding = domainParameterBindings.getBinding( queryParameter );
if ( binding.setType( valueMapping ) ) {
replaceJdbcParametersType(
sqmParameter,
@ -4107,8 +4100,8 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
}
private void replaceJdbcParametersType(
SqmParameter sourceSqmParameter,
List<SqmParameter> sqmParameters,
SqmParameter<?> sourceSqmParameter,
List<SqmParameter<?>> sqmParameters,
MappingModelExpressable<?> valueMapping) {
final JdbcMapping jdbcMapping = valueMapping.getJdbcMappings().get( 0 );
for ( SqmParameter<?> sqmParameter : sqmParameters ) {
@ -4132,20 +4125,20 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
}
}
protected Expression consumeSqmParameter(SqmParameter sqmParameter) {
protected Expression consumeSqmParameter(SqmParameter<?> sqmParameter) {
if ( sqmParameter.allowMultiValuedBinding() ) {
final QueryParameterImplementor<?> domainParam = domainParameterXref.getQueryParameter( sqmParameter );
final QueryParameterBinding domainParamBinding = domainParameterBindings.getBinding( domainParam );
final QueryParameterBinding<?> domainParamBinding = domainParameterBindings.getBinding( domainParam );
if ( !domainParamBinding.isMultiValued() ) {
return consumeSingleSqmParameter( sqmParameter );
}
final Collection bindValues = domainParamBinding.getBindValues();
final Collection<?> bindValues = domainParamBinding.getBindValues();
final List<Expression> expressions = new ArrayList<>( bindValues.size());
boolean first = true;
for ( Object bindValue : bindValues ) {
final SqmParameter sqmParamToConsume;
final SqmParameter<?> sqmParamToConsume;
// for each bind value create an "expansion"
if ( first ) {
sqmParamToConsume = sqmParameter;
@ -4165,8 +4158,8 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
}
}
protected Expression consumeSingleSqmParameter(SqmParameter sqmParameter) {
final MappingModelExpressable valueMapping = determineValueMapping( sqmParameter );
protected Expression consumeSingleSqmParameter(SqmParameter<?> sqmParameter) {
final MappingModelExpressable<?> valueMapping = determineValueMapping( sqmParameter );
final List<JdbcParameter> jdbcParametersForSqm = new ArrayList<>();
@ -4182,7 +4175,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
.add( jdbcParametersForSqm );
final QueryParameterImplementor<?> queryParameter = domainParameterXref.getQueryParameter( sqmParameter );
final QueryParameterBinding<?> binding = domainParameterBindings.getBinding( queryParameter );
final QueryParameterBinding binding = domainParameterBindings.getBinding( queryParameter );
if ( binding.setType( valueMapping ) ) {
replaceJdbcParametersType(
sqmParameter,
@ -4199,33 +4192,33 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
);
}
protected MappingModelExpressable<?> lenientlyResolveMappingExpressable(SqmExpressable<?> nodeType) {
return resolveMappingExpressable( nodeType );
}
protected MappingModelExpressable<?> resolveMappingExpressable(SqmExpressable<?> nodeType) {
final MappingModelExpressable valueMapping = getCreationContext().getDomainModel().resolveMappingExpressable(
nodeType,
this::findTableGroupByPath
);
if ( valueMapping == null ) {
final Supplier<MappingModelExpressable> currentExpressableSupplier = inferrableTypeAccessStack.getCurrent();
if ( currentExpressableSupplier != null ) {
return currentExpressableSupplier.get();
}
}
if ( valueMapping == null ) {
throw new ConversionException( "Could not determine ValueMapping for SqmExpressable: " + nodeType );
}
return valueMapping;
}
// protected MappingModelExpressable<?> lenientlyResolveMappingExpressable(SqmExpressable<?> nodeType) {
// return resolveMappingExpressable( nodeType );
// }
//
// protected MappingModelExpressable<?> resolveMappingExpressable(SqmExpressable<?> nodeType) {
// final MappingModelExpressable<?> valueMapping = getCreationContext().getDomainModel().resolveMappingExpressable(
// nodeType,
// this::findTableGroupByPath
// );
//
// if ( valueMapping == null ) {
// final Supplier<MappingModelExpressable<?>> currentExpressableSupplier = inferrableTypeAccessStack.getCurrent();
// if ( currentExpressableSupplier != null ) {
// return currentExpressableSupplier.get();
// }
// }
//
// if ( valueMapping == null ) {
// throw new ConversionException( "Could not determine ValueMapping for SqmExpressable: " + nodeType );
// }
//
// return valueMapping;
// }
protected MappingModelExpressable<?> determineValueMapping(SqmExpression<?> sqmExpression) {
if ( sqmExpression instanceof SqmParameter ) {
return determineValueMapping( (SqmParameter) sqmExpression );
return determineValueMapping( (SqmParameter<?>) sqmExpression );
}
final MappingMetamodel domainModel = getCreationContext().getDomainModel();
@ -4241,7 +4234,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
// The model type of an enum literal is always inferred
if ( sqmExpression instanceof SqmEnumLiteral<?> ) {
final Supplier<MappingModelExpressable> currentExpressableSupplier = inferrableTypeAccessStack.getCurrent();
final Supplier<MappingModelExpressable<?>> currentExpressableSupplier = inferrableTypeAccessStack.getCurrent();
if ( currentExpressableSupplier != null ) {
return currentExpressableSupplier.get();
}
@ -4304,13 +4297,13 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
// We can't determine the type of the expression
return null;
}
final MappingModelExpressable valueMapping = domainModel.resolveMappingExpressable(
final MappingModelExpressable<?> valueMapping = domainModel.resolveMappingExpressable(
nodeType,
this::findTableGroupByPath
);
if ( valueMapping == null ) {
final Supplier<MappingModelExpressable> currentExpressableSupplier = inferrableTypeAccessStack.getCurrent();
final Supplier<MappingModelExpressable<?>> currentExpressableSupplier = inferrableTypeAccessStack.getCurrent();
if ( currentExpressableSupplier != null ) {
return currentExpressableSupplier.get();
}
@ -4324,9 +4317,9 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
}
protected MappingModelExpressable<?> getInferredValueMapping() {
final Supplier<MappingModelExpressable> currentExpressableSupplier = inferrableTypeAccessStack.getCurrent();
final Supplier<MappingModelExpressable<?>> currentExpressableSupplier = inferrableTypeAccessStack.getCurrent();
if ( currentExpressableSupplier != null ) {
final MappingModelExpressable inferredMapping = currentExpressableSupplier.get();
final MappingModelExpressable<?> inferredMapping = currentExpressableSupplier.get();
if ( inferredMapping != null ) {
if ( inferredMapping instanceof PluralAttributeMapping ) {
return ( (PluralAttributeMapping) inferredMapping ).getElementDescriptor();
@ -4374,7 +4367,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
}
if ( parameterSqmType instanceof SqmPath ) {
final SqmPath sqmPath = (SqmPath) parameterSqmType;
final SqmPath<?> sqmPath = (SqmPath<?>) parameterSqmType;
final NavigablePath navigablePath = sqmPath.getNavigablePath();
if ( navigablePath.getParent() != null ) {
final TableGroup tableGroup = getFromClauseAccess().getTableGroup( navigablePath.getParent() );
@ -4415,13 +4408,13 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
throw new ConversionException( "Could not determine ValueMapping for SqmParameter: " + sqmParameter );
}
protected final Stack<Supplier<MappingModelExpressable>> inferrableTypeAccessStack = new StandardStack<>(
protected final Stack<Supplier<MappingModelExpressable<?>>> inferrableTypeAccessStack = new StandardStack<>(
() -> null
);
private void resolveSqmParameter(
SqmParameter expression,
MappingModelExpressable valueMapping,
SqmParameter<?> expression,
MappingModelExpressable<?> valueMapping,
BiConsumer<Integer,JdbcParameter> jdbcParameterConsumer) {
sqmParameterMappingModelTypes.put( expression, valueMapping );
final Bindable bindable;
@ -4608,8 +4601,8 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
@Override
public Object visitBinaryArithmeticExpression(SqmBinaryArithmetic<?> expression) {
SqmExpression leftOperand = expression.getLeftHandOperand();
SqmExpression rightOperand = expression.getRightHandOperand();
SqmExpression<?> leftOperand = expression.getLeftHandOperand();
SqmExpression<?> rightOperand = expression.getRightHandOperand();
boolean durationToRight = TypeConfiguration.isDuration( rightOperand.getNodeType() );
TypeConfiguration typeConfiguration = getCreationContext().getDomainModel().getTypeConfiguration();
@ -4707,10 +4700,10 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
adjustedTimestamp = toSqlExpression( expression.getLeftHandOperand().accept( this ) );
JdbcMappingContainer type = adjustedTimestamp.getExpressionType();
if ( type instanceof SqmExpressable ) {
adjustedTimestampType = (SqmExpressable) type;
adjustedTimestampType = (SqmExpressable<?>) type;
}
else if (type instanceof AttributeMapping ) {
adjustedTimestampType = (SqmExpressable) ( (AttributeMapping) type ).getMappedType();
adjustedTimestampType = (SqmExpressable<?>) ( (AttributeMapping) type ).getMappedType();
}
else {
// else we know it has not been transformed
@ -4758,7 +4751,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
}
}
private Object transformDatetimeArithmetic(SqmBinaryArithmetic expression) {
private Object transformDatetimeArithmetic(SqmBinaryArithmetic<?> expression) {
BinaryArithmeticOperator operator = expression.getOperator();
// the only kind of algebra we know how to
@ -5055,7 +5048,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
@Override
public CaseSimpleExpression visitSimpleCaseExpression(SqmCaseSimple<?, ?> expression) {
final List<CaseSimpleExpression.WhenFragment> whenFragments = new ArrayList<>( expression.getWhenFragments().size() );
final Supplier<MappingModelExpressable> inferenceSupplier = inferrableTypeAccessStack.getCurrent();
final Supplier<MappingModelExpressable<?>> inferenceSupplier = inferrableTypeAccessStack.getCurrent();
inferrableTypeAccessStack.push(
() -> {
for ( SqmCaseSimple.WhenFragment<?, ?> whenFragment : expression.getWhenFragments() ) {
@ -5113,7 +5106,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
@Override
public CaseSearchedExpression visitSearchedCaseExpression(SqmCaseSearched<?> expression) {
final List<CaseSearchedExpression.WhenFragment> whenFragments = new ArrayList<>( expression.getWhenFragments().size() );
final Supplier<MappingModelExpressable> inferenceSupplier = inferrableTypeAccessStack.getCurrent();
final Supplier<MappingModelExpressable<?>> inferenceSupplier = inferrableTypeAccessStack.getCurrent();
MappingModelExpressable<?> resolved = determineCurrentExpressable( expression );
Expression otherwise = null;
@ -5161,39 +5154,35 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
}
}
private <X> X visitWithLenientInferredType(SqmExpression<?> expression, SqmExpression<?> inferred) {
inferrableTypeAccessStack.push(
() -> {
MappingModelExpressable<?> definedType = creationContext
.getDomainModel()
.resolveMappingExpressable(
expression.getNodeType(),
getFromClauseIndex()::findTableGroup
);
if ( definedType != null ) {
return definedType;
}
definedType = creationContext
.getDomainModel()
.lenientlyResolveMappingExpressable(
inferred.getNodeType(),
getFromClauseIndex()::findTableGroup
);
if ( definedType != null ) {
return definedType;
}
return null;
}
);
try {
return (X) expression.accept( this );
}
finally {
inferrableTypeAccessStack.pop();
}
}
// private <X> X visitWithLenientInferredType(SqmExpression<?> expression, SqmExpression<?> inferred) {
// inferrableTypeAccessStack.push(
// () -> {
// MappingModelExpressable<?> definedType = creationContext
// .getDomainModel()
// .resolveMappingExpressable(
// expression.getNodeType(),
// getFromClauseIndex()::findTableGroup
// );
// if ( definedType != null ) {
// return definedType;
// }
// definedType = creationContext
// .getDomainModel()
// .lenientlyResolveMappingExpressable(
// inferred.getNodeType(),
// getFromClauseIndex()::findTableGroup
// );
// return definedType;
// }
// );
//
// try {
// return (X) expression.accept( this );
// }
// finally {
// inferrableTypeAccessStack.pop();
// }
// }
@Override
public Object visitAny(SqmAny<?> sqmAny) {
@ -5255,7 +5244,8 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
final BasicValuedMapping inferrableType = (BasicValuedMapping) inferrableTypeAccessStack.getCurrent().get();
if ( inferrableType instanceof ConvertibleModelPart ) {
final ConvertibleModelPart inferredPart = (ConvertibleModelPart) inferrableType;
final BasicValueConverter valueConverter = inferredPart.getValueConverter();
@SuppressWarnings("unchecked")
final BasicValueConverter<Enum<?>,?> valueConverter = inferredPart.getValueConverter();
final Object jdbcValue = valueConverter.toRelationalValue( sqmEnumLiteral.getEnumValue() );
return new QueryLiteral<>( jdbcValue, inferredPart );
}
@ -5312,8 +5302,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
() -> ( (EntityCollectionPart) pluralAttributeMapping.getElementDescriptor() ).getKeyTargetMatchPart() );
}
else if ( pluralAttributeMapping.getElementDescriptor() instanceof EmbeddedCollectionPart ) {
inferrableTypeAccessStack.push(
() -> pluralAttributeMapping.getElementDescriptor() );
inferrableTypeAccessStack.push(pluralAttributeMapping::getElementDescriptor);
}
else {
inferrableTypeAccessStack.push( () -> pluralAttributeMapping );
@ -5722,7 +5711,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
}
@Override
public InSubQueryPredicate visitInSubQueryPredicate(SqmInSubQueryPredicate predicate) {
public InSubQueryPredicate visitInSubQueryPredicate(SqmInSubQueryPredicate<?> predicate) {
return new InSubQueryPredicate(
visitWithInferredType( predicate.getTestExpression(), predicate.getSubQueryExpression() ),
visitWithInferredType( predicate.getSubQueryExpression(), predicate.getTestExpression() ),
@ -5865,16 +5854,16 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
}
}
final TableGroup existingJoinedGroup = fromClauseIndex.findTableGroup( fetchablePath );
if ( existingJoinedGroup != null ) {
// final TableGroup existingJoinedGroup = fromClauseIndex.findTableGroup( fetchablePath );
// if ( existingJoinedGroup != null ) {
// we can use this to trigger the fetch from the joined group.
// todo (6.0) : do we want to do this though?
// On the positive side it would allow EntityGraph to use the existing TableGroup. But that ties in
// to the discussion above regarding how to handle eager and EntityGraph (JOIN versus SELECT).
// Can be problematic if the existing one is restricted
//fetchTiming = FetchTiming.IMMEDIATE;
}
// fetchTiming = FetchTiming.IMMEDIATE;
// }
// lastly, account for any app-defined max-fetch-depth
final Integer maxDepth = getCreationContext().getMaximumFetchDepth();
@ -6147,10 +6136,6 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
return delegate.resolveSqlSelection( expression, javaTypeDescriptor, typeConfiguration );
}
public SqmAliasedNodeCollector getSqmAliasedNodeCollector() {
return sqmAliasedNodeCollector;
}
public void setSqmAliasedNodeCollector(SqmAliasedNodeCollector sqmAliasedNodeCollector) {
this.sqmAliasedNodeCollector = sqmAliasedNodeCollector;
}
@ -6161,6 +6146,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
private final List<SqlSelection>[] sqlSelectionsForSqmSelection;
private int index = -1;
@SuppressWarnings("unchecked")
public SqmAliasedNodePositionTracker(SqlExpressionResolver delegate, List<? extends SqmAliasedNode<?>> selections) {
this.delegate = delegate;
this.sqlSelectionsForSqmSelection = new List[countIndividualSelections( selections )];
@ -6211,20 +6197,18 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
}
@Override
public List<Expression> expandSelfRenderingFunctionMultiValueParameter(SqmParameter sqmParameter) {
public List<Expression> expandSelfRenderingFunctionMultiValueParameter(SqmParameter<?> sqmParameter) {
assert sqmParameter.allowMultiValuedBinding();
final QueryParameterImplementor<?> domainParam = domainParameterXref.getQueryParameter(
sqmParameter );
final QueryParameterBinding domainParamBinding = domainParameterBindings.getBinding(
domainParam );
final QueryParameterImplementor<?> domainParam = domainParameterXref.getQueryParameter( sqmParameter );
final QueryParameterBinding<?> domainParamBinding = domainParameterBindings.getBinding( domainParam );
final Collection bindValues = domainParamBinding.getBindValues();
final Collection<?> bindValues = domainParamBinding.getBindValues();
final int bindValuesSize = bindValues.size();
final List<Expression> result = new ArrayList<>( bindValuesSize );
boolean first = true;
for ( int i = 0; i < bindValuesSize; i++ ) {
final SqmParameter sqmParamToConsume;
final SqmParameter<?> sqmParamToConsume;
// for each bind value create an "expansion"
if ( first ) {
sqmParamToConsume = sqmParameter;

View File

@ -74,7 +74,7 @@ public class FakeSqmToSqlAstConverter extends BaseSemanticQueryWalker implements
}
@Override
public List<Expression> expandSelfRenderingFunctionMultiValueParameter(SqmParameter sqmParameter) {
public List<Expression> expandSelfRenderingFunctionMultiValueParameter(SqmParameter<?> sqmParameter) {
return null;
}
}

View File

@ -23,6 +23,6 @@ import org.hibernate.sql.ast.tree.expression.Expression;
public interface SqmToSqlAstConverter extends SemanticQueryWalker<Object>, SqlAstCreationState {
Stack<Clause> getCurrentClauseStack();
List<Expression> expandSelfRenderingFunctionMultiValueParameter(SqmParameter sqmParameter);
List<Expression> expandSelfRenderingFunctionMultiValueParameter(SqmParameter<?> sqmParameter);
}

View File

@ -8,10 +8,8 @@ package org.hibernate.query.sqm.sql;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import org.hibernate.metamodel.mapping.MappingModelExpressable;
import org.hibernate.query.sqm.spi.SqmParameterMappingModelResolutionAccess;
import org.hibernate.query.sqm.tree.expression.SqmParameter;
import org.hibernate.sql.ast.spi.FromClauseAccess;
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
@ -27,6 +25,6 @@ public interface SqmTranslation<T extends Statement> {
T getSqlAst();
SqlExpressionResolver getSqlExpressionResolver();
FromClauseAccess getFromClauseAccess();
Map<SqmParameter, List<List<JdbcParameter>>> getJdbcParamsBySqmParam();
Map<SqmParameter,MappingModelExpressable> getSqmParameterMappingModelTypeResolutions();
Map<SqmParameter<?>, List<List<JdbcParameter>>> getJdbcParamsBySqmParam();
Map<SqmParameter<?>, MappingModelExpressable<?>> getSqmParameterMappingModelTypeResolutions();
}

View File

@ -22,15 +22,15 @@ import org.hibernate.sql.ast.tree.expression.JdbcParameter;
public class StandardSqmTranslation<T extends Statement> implements SqmTranslation<T> {
private final T sqlAst;
private final Map<SqmParameter, List<List<JdbcParameter>>> jdbcParamMap;
private final Map<SqmParameter, MappingModelExpressable> parameterMappingModelTypeMap;
private final Map<SqmParameter<?>, List<List<JdbcParameter>>> jdbcParamMap;
private final Map<SqmParameter<?>, MappingModelExpressable<?>> parameterMappingModelTypeMap;
private final SqlExpressionResolver sqlExpressionResolver;
private final FromClauseAccess fromClauseAccess;
public StandardSqmTranslation(
T sqlAst,
Map<SqmParameter, List<List<JdbcParameter>>> jdbcParamMap,
Map<SqmParameter, MappingModelExpressable> parameterMappingModelTypeMap,
Map<SqmParameter<?>, List<List<JdbcParameter>>> jdbcParamMap,
Map<SqmParameter<?>, MappingModelExpressable<?>> parameterMappingModelTypeMap,
SqlExpressionResolver sqlExpressionResolver,
FromClauseAccess fromClauseAccess) {
this.sqlAst = sqlAst;
@ -46,12 +46,12 @@ public class StandardSqmTranslation<T extends Statement> implements SqmTranslati
}
@Override
public Map<SqmParameter, List<List<JdbcParameter>>> getJdbcParamsBySqmParam() {
public Map<SqmParameter<?>, List<List<JdbcParameter>>> getJdbcParamsBySqmParam() {
return jdbcParamMap;
}
@Override
public Map<SqmParameter, MappingModelExpressable> getSqmParameterMappingModelTypeResolutions() {
public Map<SqmParameter<?>, MappingModelExpressable<?>> getSqmParameterMappingModelTypeResolutions() {
return parameterMappingModelTypeMap;
}

View File

@ -42,7 +42,7 @@ public interface FromClauseAccess {
/**
* Register a TableGroup under the given `navigablePath`. Logs a message
* if thhis registration over-writes an existing one.
* if this registration over-writes an existing one.
*/
void registerTableGroup(NavigablePath navigablePath, TableGroup tableGroup);

View File

@ -19,5 +19,5 @@ public interface FunctionExpression extends Expression {
String getFunctionName();
List<SqlAstNode> getArguments();
List<? extends SqlAstNode> getArguments();
}

View File

@ -59,9 +59,9 @@ public class SubqueryTest extends BaseSessionFactoryFunctionalTest {
@Override
public void render(
SqlAppender sqlAppender, List<SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
sqlAstArguments.get( 0 ).accept( walker );
sqlAppender.appendSql( " limit " + ( (QueryLiteral) sqlAstArguments.get( 1 ) ).getLiteralValue() );
sqlAppender.appendSql( " limit " + ( (QueryLiteral<?>) sqlAstArguments.get( 1 ) ).getLiteralValue() );
}
}