HHH-14439 Clean up expanded list parameters before re-executing a query

Signed-off-by: Yoann Rodière <yoann@hibernate.org>
This commit is contained in:
Yoann Rodière 2021-02-24 15:24:14 +01:00
parent ed3bbf15e4
commit 81071a4594
1 changed files with 15 additions and 0 deletions

View File

@ -63,6 +63,7 @@ public class QueryParameterBindingsImpl implements QueryParameterBindings {
private Map<QueryParameter, QueryParameterBinding> parameterBindingMap; private Map<QueryParameter, QueryParameterBinding> parameterBindingMap;
private Map<QueryParameter, QueryParameterListBinding> parameterListBindingMap; private Map<QueryParameter, QueryParameterListBinding> parameterListBindingMap;
private Set<QueryParameter> parametersConvertedToListBindings; private Set<QueryParameter> parametersConvertedToListBindings;
private Set<QueryParameter> syntheticParametersFromListBindings;
public static QueryParameterBindingsImpl from( public static QueryParameterBindingsImpl from(
ParameterMetadata parameterMetadata, ParameterMetadata parameterMetadata,
@ -514,6 +515,12 @@ public class QueryParameterBindingsImpl implements QueryParameterBindings {
return null; return null;
} }
if ( syntheticParametersFromListBindings != null ) {
// Clean up parameters from previous query executions
parameterBindingMap.keySet().removeAll( syntheticParametersFromListBindings );
syntheticParametersFromListBindings.clear();
}
if ( parameterListBindingMap == null || parameterListBindingMap.isEmpty() ) { if ( parameterListBindingMap == null || parameterListBindingMap.isEmpty() ) {
return queryString; return queryString;
} }
@ -644,6 +651,7 @@ public class QueryParameterBindingsImpl implements QueryParameterBindings {
expansionList.append( "?" ).append( syntheticParam.getPosition() ); expansionList.append( "?" ).append( syntheticParam.getPosition() );
} }
registerSyntheticParamFromListBindings( syntheticParam );
final QueryParameterBinding syntheticBinding = makeBinding( entry.getValue().getBindType() ); final QueryParameterBinding syntheticBinding = makeBinding( entry.getValue().getBindType() );
syntheticBinding.setBindValue( bindValue ); syntheticBinding.setBindValue( bindValue );
parameterBindingMap.put( syntheticParam, syntheticBinding ); parameterBindingMap.put( syntheticParam, syntheticBinding );
@ -669,6 +677,13 @@ public class QueryParameterBindingsImpl implements QueryParameterBindings {
return queryString; return queryString;
} }
private void registerSyntheticParamFromListBindings(QueryParameter<?> syntheticParam) {
if ( syntheticParametersFromListBindings == null ) {
syntheticParametersFromListBindings = new HashSet<>();
}
syntheticParametersFromListBindings.add( syntheticParam );
}
private int getMaxOrdinalPosition() { private int getMaxOrdinalPosition() {
int maxOrdinalPosition = 0; int maxOrdinalPosition = 0;
for ( QueryParameter<?> queryParameter : parameterBindingMap.keySet() ) { for ( QueryParameter<?> queryParameter : parameterBindingMap.keySet() ) {