HHH-12685 - Fix CriteriaQueryTypeQueryAdapter parameters type validation issues

This commit is contained in:
Andrea Boriero 2018-06-29 11:48:25 +02:00 committed by Guillaume Smet
parent d4a46fa93e
commit d64a9a9000
1 changed files with 54 additions and 43 deletions

View File

@ -362,7 +362,7 @@ public class CriteriaQueryTypeQueryAdapter<X> implements QueryImplementor<X> {
return (ExplicitParameterInfo) param;
}
else if ( ParameterExpression.class.isInstance( param ) ) {
return explicitParameterInfoMap.get( (ParameterExpression) param );
return explicitParameterInfoMap.get( param );
}
else {
for ( ExplicitParameterInfo parameterInfo : explicitParameterInfoMap.values() ) {
@ -501,23 +501,27 @@ public class CriteriaQueryTypeQueryAdapter<X> implements QueryImplementor<X> {
@Override
public QueryImplementor<X> setEntity(String name, Object val) {
entityManager.checkOpen( false );
ExplicitParameterInfo parameterInfo = locateParameterByName( name );
parameterInfo.validateDateBind();
parameterInfo.validateBindValue( val );
jpqlQuery.setEntity( name, val );
return this;
}
@Override
public QueryImplementor<X> setParameter(String name, Object val, Type type) {
entityManager.checkOpen( false );
ExplicitParameterInfo parameterInfo = locateParameterByName( name );
parameterInfo.validateDateBind();
parameterInfo.validateBindValue( val );
jpqlQuery.setParameter( name, val, type );
return this;
}
@Override
public <T> QueryImplementor<X> setParameter(QueryParameter<T> parameter, T val) {
entityManager.checkOpen( false );
final ExplicitParameterInfo parameterInfo = resolveParameterInfo( parameter );
parameterInfo.validateBindValue( val );
if ( parameterInfo.isNamed() ) {
jpqlQuery.setParameter( parameterInfo.getName(), val );
}
@ -530,6 +534,7 @@ public class CriteriaQueryTypeQueryAdapter<X> implements QueryImplementor<X> {
@Override
public <P> QueryImplementor<X> setParameter(
QueryParameter<P> parameter, P val, TemporalType temporalType) {
entityManager.checkOpen( false );
final ExplicitParameterInfo parameterInfo = resolveParameterInfo( parameter );
if ( parameterInfo.isNamed() ) {
jpqlQuery.setParameter( parameterInfo.getName(), val, temporalType );
@ -542,14 +547,15 @@ public class CriteriaQueryTypeQueryAdapter<X> implements QueryImplementor<X> {
@Override
public <P> QueryImplementor<X> setParameter(String name, P val, TemporalType temporalType) {
ExplicitParameterInfo parameterInfo = locateParameterByName( name );
parameterInfo.validateDateBind();
entityManager.checkOpen( false );
locateParameterByName( name );
jpqlQuery.setParameter( name, val, temporalType );
return this;
}
@Override
public <P> QueryImplementor<X> setParameterList(QueryParameter<P> parameter, Collection<P> values) {
entityManager.checkOpen( false );
final ExplicitParameterInfo parameterInfo = resolveParameterInfo( parameter );
if ( parameterInfo.isNamed() ) {
jpqlQuery.setParameter( parameterInfo.getName(), values );
@ -562,70 +568,71 @@ public class CriteriaQueryTypeQueryAdapter<X> implements QueryImplementor<X> {
@Override
public QueryImplementor<X> setParameterList(String name, Collection values) {
ExplicitParameterInfo parameterInfo = locateParameterByName( name );
parameterInfo.validateDateBind();
entityManager.checkOpen( false );
locateParameterByName( name );
jpqlQuery.setParameter( name, values );
return this;
}
@Override
public Query<X> setParameterList(int position, Collection values) {
ExplicitParameterInfo parameterInfo = locateParameterByPosition( position );
parameterInfo.validateDateBind();
entityManager.checkOpen( false );
locateParameterByPosition( position );
jpqlQuery.setParameter( position, values );
return this;
}
@Override
public QueryImplementor<X> setParameterList(String name, Collection values, Type type) {
ExplicitParameterInfo parameterInfo = locateParameterByName( name );
parameterInfo.validateDateBind();
entityManager.checkOpen( false );
locateParameterByName( name );
jpqlQuery.setParameter( name, values, type );
return this;
}
@Override
public Query<X> setParameterList(int position, Collection values, Type type) {
ExplicitParameterInfo parameterInfo = locateParameterByPosition( position );
parameterInfo.validateDateBind();
entityManager.checkOpen( false );
locateParameterByPosition( position );
jpqlQuery.setParameter( position, values, type );
return this;
}
@Override
public QueryImplementor<X> setParameterList(String name, Object[] values, Type type) {
ExplicitParameterInfo parameterInfo = locateParameterByName( name );
parameterInfo.validateDateBind();
entityManager.checkOpen( false );
locateParameterByName( name );
jpqlQuery.setParameter( name, values, type );
return this;
}
@Override
public Query<X> setParameterList(int position, Object[] values, Type type) {
ExplicitParameterInfo parameterInfo = locateParameterByPosition( position );
parameterInfo.validateDateBind();
entityManager.checkOpen( false );
locateParameterByPosition( position );
jpqlQuery.setParameter( position, values, type );
return this;
}
@Override
public QueryImplementor<X> setParameterList(String name, Object[] values) {
ExplicitParameterInfo parameterInfo = locateParameterByName( name );
parameterInfo.validateDateBind();
entityManager.checkOpen( false );
locateParameterByName( name );
jpqlQuery.setParameter( name, values );
return this;
}
@Override
public Query<X> setParameterList(int position, Object[] values) {
ExplicitParameterInfo parameterInfo = locateParameterByPosition( position );
parameterInfo.validateDateBind();
entityManager.checkOpen( false );
locateParameterByPosition( position );
jpqlQuery.setParameter( position, values );
return this;
}
@Override
public <P> QueryImplementor<X> setParameter(QueryParameter<P> parameter, P value, Type type) {
entityManager.checkOpen( false );
final ExplicitParameterInfo parameterInfo = resolveParameterInfo( parameter );
if ( parameterInfo.isNamed() ) {
jpqlQuery.setParameter( parameterInfo.getName(), value, type );
@ -638,6 +645,7 @@ public class CriteriaQueryTypeQueryAdapter<X> implements QueryImplementor<X> {
@Override
public QueryImplementor<X> setParameter(Parameter<Instant> param, Instant value, TemporalType temporalType){
entityManager.checkOpen( false );
final ExplicitParameterInfo parameterInfo = resolveParameterInfo( param );
if ( parameterInfo.isNamed() ) {
jpqlQuery.setParameter( parameterInfo.getName(), value, temporalType );
@ -650,6 +658,7 @@ public class CriteriaQueryTypeQueryAdapter<X> implements QueryImplementor<X> {
@Override
public QueryImplementor<X> setParameter(Parameter<LocalDateTime> param, LocalDateTime value, TemporalType temporalType){
entityManager.checkOpen( false );
final ExplicitParameterInfo parameterInfo = resolveParameterInfo( param );
if ( parameterInfo.isNamed() ) {
jpqlQuery.setParameter( parameterInfo.getName(), value, temporalType );
@ -662,6 +671,7 @@ public class CriteriaQueryTypeQueryAdapter<X> implements QueryImplementor<X> {
@Override
public QueryImplementor<X> setParameter(Parameter<ZonedDateTime> param, ZonedDateTime value, TemporalType temporalType){
entityManager.checkOpen( false );
final ExplicitParameterInfo parameterInfo = resolveParameterInfo( param );
if ( parameterInfo.isNamed() ) {
jpqlQuery.setParameter( parameterInfo.getName(), value, temporalType );
@ -674,6 +684,7 @@ public class CriteriaQueryTypeQueryAdapter<X> implements QueryImplementor<X> {
@Override
public QueryImplementor<X> setParameter(Parameter<OffsetDateTime> param, OffsetDateTime value, TemporalType temporalType){
entityManager.checkOpen( false );
final ExplicitParameterInfo parameterInfo = resolveParameterInfo( param );
if ( parameterInfo.isNamed() ) {
jpqlQuery.setParameter( parameterInfo.getName(), value, temporalType );
@ -686,32 +697,32 @@ public class CriteriaQueryTypeQueryAdapter<X> implements QueryImplementor<X> {
@Override
public QueryImplementor<X> setParameter(String name, Instant value, TemporalType temporalType){
ExplicitParameterInfo parameterInfo = locateParameterByName( name );
parameterInfo.validateCalendarBind();
entityManager.checkOpen( false );
locateParameterByName( name );
jpqlQuery.setParameter( name, value, temporalType );
return this;
}
@Override
public QueryImplementor<X> setParameter(String name, LocalDateTime value, TemporalType temporalType){
ExplicitParameterInfo parameterInfo = locateParameterByName( name );
parameterInfo.validateCalendarBind();
entityManager.checkOpen( false );
locateParameterByName( name );
jpqlQuery.setParameter( name, value, temporalType );
return this;
}
@Override
public QueryImplementor<X> setParameter(String name, ZonedDateTime value, TemporalType temporalType){
ExplicitParameterInfo parameterInfo = locateParameterByName( name );
parameterInfo.validateCalendarBind();
entityManager.checkOpen( false );
locateParameterByName( name );
jpqlQuery.setParameter( name, value, temporalType );
return this;
}
@Override
public QueryImplementor<X> setParameter(String name, OffsetDateTime value, TemporalType temporalType){
ExplicitParameterInfo parameterInfo = locateParameterByName( name );
parameterInfo.validateCalendarBind();
entityManager.checkOpen( false );
locateParameterByName( name );
jpqlQuery.setParameter( name, value, temporalType );
return this;
}
@ -756,56 +767,56 @@ public class CriteriaQueryTypeQueryAdapter<X> implements QueryImplementor<X> {
@Override
public QueryImplementor<X> setParameter(int position, LocalDateTime value, TemporalType temporalType) {
final ExplicitParameterInfo explicitParameterInfo = locateParameterByPosition( position );
explicitParameterInfo.validateDateBind();
entityManager.checkOpen( false );
locateParameterByPosition( position );
jpqlQuery.setParameter( position, value, temporalType );
return this;
}
@Override
public QueryImplementor<X> setParameter(int position, Instant value, TemporalType temporalType) {
final ExplicitParameterInfo explicitParameterInfo = locateParameterByPosition( position );
explicitParameterInfo.validateDateBind();
entityManager.checkOpen( false );
locateParameterByPosition( position );
jpqlQuery.setParameter( position, value, temporalType );
return this;
}
@Override
public QueryImplementor<X> setParameter(int position, ZonedDateTime value, TemporalType temporalType) {
final ExplicitParameterInfo explicitParameterInfo = locateParameterByPosition( position );
explicitParameterInfo.validateDateBind();
entityManager.checkOpen( false );
locateParameterByPosition( position );
jpqlQuery.setParameter( position, value, temporalType );
return this;
}
@Override
public QueryImplementor<X> setParameter(int position, OffsetDateTime value, TemporalType temporalType) {
final ExplicitParameterInfo explicitParameterInfo = locateParameterByPosition( position );
explicitParameterInfo.validateDateBind();
entityManager.checkOpen( false );
locateParameterByPosition( position );
jpqlQuery.setParameter( position, value, temporalType );
return this;
}
@Override
public QueryImplementor<X> setParameter(int position, Object val, Type type) {
final ExplicitParameterInfo explicitParameterInfo = locateParameterByPosition( position );
explicitParameterInfo.validateDateBind();
entityManager.checkOpen( false );
locateParameterByPosition( position );
jpqlQuery.setParameter( position, val, type );
return this;
}
@Override
public QueryImplementor<X> setEntity(int position, Object val) {
final ExplicitParameterInfo explicitParameterInfo = locateParameterByPosition( position );
explicitParameterInfo.validateDateBind();
entityManager.checkOpen( false );
locateParameterByPosition( position );
jpqlQuery.setParameter( position, val );
return this;
}
@Override
public <P> QueryImplementor<X> setParameter(int position, P val, TemporalType temporalType) {
final ExplicitParameterInfo explicitParameterInfo = locateParameterByPosition( position );
explicitParameterInfo.validateDateBind();
entityManager.checkOpen( false );
locateParameterByPosition( position );
jpqlQuery.setParameter( position, val, temporalType );
return this;
}