Skip to content

[6.2] HHH-19560 Remove TupleTransformer and ResultListTransformer from interpretation caching #10404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@
package org.hibernate.dialect.function;

import java.util.List;
import java.util.function.Supplier;

import org.hibernate.metamodel.mapping.BasicValuedMapping;
import org.hibernate.query.ReturnableType;
import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor;
import org.hibernate.query.sqm.produce.function.FunctionReturnTypeResolver;
import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators;
import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers;
import org.hibernate.query.sqm.tree.SqmTypedNode;
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.JavaObjectType;
import org.hibernate.type.spi.TypeConfiguration;

/**
* A function to pass through a SQL fragment.
Expand All @@ -29,7 +34,23 @@ public SqlFunction() {
super(
"sql",
StandardArgumentsValidators.min( 1 ),
StandardFunctionReturnTypeResolvers.invariant( JavaObjectType.INSTANCE ),
new FunctionReturnTypeResolver() {
@Override
public ReturnableType<?> resolveFunctionReturnType(
ReturnableType<?> impliedType,
List<? extends SqmTypedNode<?>> arguments,
TypeConfiguration typeConfiguration) {
return impliedType != null
? impliedType
: typeConfiguration.getBasicTypeForJavaType( Object.class );
}

@Override
public BasicValuedMapping resolveFunctionReturnType(Supplier<BasicValuedMapping> impliedTypeAccess, List<? extends SqlAstNode> arguments) {
final BasicValuedMapping impliedType = impliedTypeAccess.get();
return impliedType != null ? impliedType : JavaObjectType.INSTANCE;
}
},
null
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -812,9 +812,7 @@ private SelectInterpretationsKey generateSelectInterpretationsKey(JdbcValuesMapp
return new SelectInterpretationsKey(
getQueryString(),
resultSetMapping,
getSynchronizedQuerySpaces(),
getQueryOptions().getTupleTransformer(),
getQueryOptions().getResultListTransformer()
getSynchronizedQuerySpaces()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,36 @@ public class SelectInterpretationsKey implements QueryInterpretationCache.Key {
private final String sql;
private final JdbcValuesMappingProducer jdbcValuesMappingProducer;
private final Collection<String> querySpaces;
private final TupleTransformer tupleTransformer;
private final ResultListTransformer resultListTransformer;
private final int hash;

@Deprecated(forRemoval = true)
public SelectInterpretationsKey(
String sql,
JdbcValuesMappingProducer jdbcValuesMappingProducer,
Collection<String> querySpaces,
TupleTransformer tupleTransformer,
ResultListTransformer resultListTransformer) {
this( sql, jdbcValuesMappingProducer, querySpaces );
}

public SelectInterpretationsKey(
String sql,
JdbcValuesMappingProducer jdbcValuesMappingProducer,
Collection<String> querySpaces) {
this.sql = sql;
this.jdbcValuesMappingProducer = jdbcValuesMappingProducer;
this.querySpaces = querySpaces;
this.tupleTransformer = tupleTransformer;
this.resultListTransformer = resultListTransformer;
this.hash = generateHashCode();
}

private SelectInterpretationsKey(
String sql,
JdbcValuesMappingProducer jdbcValuesMappingProducer,
Collection<String> querySpaces,
TupleTransformer tupleTransformer,
ResultListTransformer resultListTransformer,
int hash) {
this.sql = sql;
this.jdbcValuesMappingProducer = jdbcValuesMappingProducer;
this.querySpaces = querySpaces;
this.tupleTransformer = tupleTransformer;
this.resultListTransformer = resultListTransformer;
this.hash = hash;
}

Expand All @@ -66,8 +66,6 @@ public QueryInterpretationCache.Key prepareForStore() {
sql,
jdbcValuesMappingProducer.cacheKeyInstance(),
new HashSet<>( querySpaces ),
tupleTransformer,
resultListTransformer,
hash
);
}
Expand All @@ -94,7 +92,6 @@ public boolean equals(Object o) {
return sql.equals( that.sql )
&& Objects.equals( jdbcValuesMappingProducer, that.jdbcValuesMappingProducer )
&& Objects.equals( querySpaces, that.querySpaces )
&& Objects.equals( tupleTransformer, that.tupleTransformer )
&& Objects.equals( resultListTransformer, that.resultListTransformer );
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
public class ConcreteSqmSelectQueryPlan<R> implements SelectQueryPlan<R> {
private final SqmSelectStatement<?> sqm;
private final DomainParameterXref domainParameterXref;
private final RowTransformer<R> rowTransformer;
private final SqmInterpreter<List<R>, Void> listInterpreter;
private final SqmInterpreter<ScrollableResultsImplementor<R>, ScrollMode> scrollInterpreter;

Expand All @@ -85,8 +84,6 @@ public ConcreteSqmSelectQueryPlan(
this.sqm = sqm;
this.domainParameterXref = domainParameterXref;

this.rowTransformer = determineRowTransformer( sqm, resultType, tupleMetadata, queryOptions );

final ListResultsConsumer.UniqueSemantic uniqueSemantic;
if ( sqm.producesUniqueResults() && !AppliedGraphs.containsCollectionFetches( queryOptions ) ) {
uniqueSemantic = ListResultsConsumer.UniqueSemantic.NONE;
Expand All @@ -111,7 +108,7 @@ public ConcreteSqmSelectQueryPlan(
jdbcSelect,
jdbcParameterBindings,
listInterpreterExecutionContext( hql, executionContext, jdbcSelect, subSelectFetchKeyHandler ),
rowTransformer,
determineRowTransformer( sqm, resultType, tupleMetadata, executionContext.getQueryOptions() ),
uniqueSemantic
);
}
Expand All @@ -138,7 +135,7 @@ public ConcreteSqmSelectQueryPlan(
scrollMode,
jdbcParameterBindings,
new SqmJdbcExecutionContextAdapter( executionContext, sqmInterpretation.jdbcSelect ),
rowTransformer
determineRowTransformer( sqm, resultType, tupleMetadata, executionContext.getQueryOptions() )
);
}
finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

import org.hibernate.LockOptions;
import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.query.ResultListTransformer;
import org.hibernate.query.TupleTransformer;
import org.hibernate.query.spi.QueryInterpretationCache;
import org.hibernate.query.spi.QueryOptions;

Expand Down Expand Up @@ -40,9 +38,7 @@ public static SqmInterpretationsKey createInterpretationsKey(InterpretationsKeyS
return new SqmInterpretationsKey(
keySource.getQueryString(),
keySource.getResultType(),
keySource.getQueryOptions().getLockOptions(),
keySource.getQueryOptions().getTupleTransformer(),
keySource.getQueryOptions().getResultListTransformer()
keySource.getQueryOptions().getLockOptions()
);
}
@SuppressWarnings("RedundantIfStatement")
Expand Down Expand Up @@ -90,20 +86,14 @@ public static QueryInterpretationCache.Key generateNonSelectKey(InterpretationsK
private final String query;
private final Class<?> resultType;
private final LockOptions lockOptions;
private final TupleTransformer<?> tupleTransformer;
private final ResultListTransformer resultListTransformer;

private SqmInterpretationsKey(
String query,
Class<?> resultType,
LockOptions lockOptions,
TupleTransformer<?> tupleTransformer,
ResultListTransformer resultListTransformer) {
LockOptions lockOptions) {
this.query = query;
this.resultType = resultType;
this.lockOptions = lockOptions;
this.tupleTransformer = tupleTransformer;
this.resultListTransformer = resultListTransformer;
}

@Override
Expand All @@ -112,9 +102,7 @@ public QueryInterpretationCache.Key prepareForStore() {
query,
resultType,
// Since lock options are mutable, we need a copy for the cache key
lockOptions.makeCopy(),
tupleTransformer,
resultListTransformer
lockOptions.makeCopy()
);
}

Expand All @@ -135,9 +123,7 @@ public boolean equals(Object o) {
final SqmInterpretationsKey that = (SqmInterpretationsKey) o;
return query.equals( that.query )
&& areEqual( resultType, that.resultType )
&& areEqual( lockOptions, that.lockOptions )
&& areEqual( tupleTransformer, that.tupleTransformer )
&& areEqual( resultListTransformer, that.resultListTransformer );
&& areEqual( lockOptions, that.lockOptions );
}

private <T> boolean areEqual(T o1, T o2) {
Expand Down
Loading