HHH-17729 move validation of constructors in HQL instantiations to SemanticQueryBuilder
also validate injection via fields/properties
This commit is contained in:
parent
dcb2c60d4e
commit
a9ea331e40
|
@ -143,7 +143,7 @@ public class SqmDynamicInstantiation<T>
|
||||||
|
|
||||||
private List<Class<?>> argumentTypes() {
|
private List<Class<?>> argumentTypes() {
|
||||||
return getArguments().stream()
|
return getArguments().stream()
|
||||||
.map(arg -> arg.getNodeJavaType().getJavaTypeClass())
|
.map(arg -> arg.getNodeJavaType() == null ? Void.class : arg.getNodeJavaType().getJavaTypeClass())
|
||||||
.collect(toList());
|
.collect(toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class InstantiationHelper {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return findField(targetJavaType, alias, argType) != null;
|
return findField( targetJavaType, alias, argType ) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isConstructorCompatible(Class<?> javaClass, List<Class<?>> argTypes, TypeConfiguration typeConfiguration) {
|
public static boolean isConstructorCompatible(Class<?> javaClass, List<Class<?>> argTypes, TypeConfiguration typeConfiguration) {
|
||||||
|
@ -74,11 +74,11 @@ public class InstantiationHelper {
|
||||||
for (int i = 0; i < argumentTypes.size(); i++ ) {
|
for (int i = 0; i < argumentTypes.size(); i++ ) {
|
||||||
final Type parameterType = genericParameterTypes[i];
|
final Type parameterType = genericParameterTypes[i];
|
||||||
final Class<?> argumentType = argumentTypes.get( i );
|
final Class<?> argumentType = argumentTypes.get( i );
|
||||||
final Class<?> argType = parameterType instanceof Class<?>
|
final Class<?> type = parameterType instanceof Class<?>
|
||||||
? (Class<?>) parameterType
|
? (Class<?>) parameterType
|
||||||
: typeConfiguration.getJavaTypeRegistry().resolveDescriptor( parameterType ).getJavaTypeClass();
|
: typeConfiguration.getJavaTypeRegistry().resolveDescriptor( parameterType ).getJavaTypeClass();
|
||||||
|
|
||||||
if ( !areAssignmentCompatible( argType, argumentType ) ) {
|
if ( !areAssignmentCompatible( type, argumentType ) ) {
|
||||||
if ( log.isDebugEnabled() ) {
|
if ( log.isDebugEnabled() ) {
|
||||||
log.debugf(
|
log.debugf(
|
||||||
"Skipping constructor for dynamic-instantiation match due to argument mismatch [%s] : %s -> %s",
|
"Skipping constructor for dynamic-instantiation match due to argument mismatch [%s] : %s -> %s",
|
||||||
|
@ -116,7 +116,7 @@ public class InstantiationHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean propertyMatches(String alias, Class<?> argType, PropertyDescriptor propertyDescriptor) {
|
static boolean propertyMatches(String alias, Class<?> argType, PropertyDescriptor propertyDescriptor) {
|
||||||
return alias.equals(propertyDescriptor.getName())
|
return alias.equals( propertyDescriptor.getName() )
|
||||||
&& propertyDescriptor.getWriteMethod() != null
|
&& propertyDescriptor.getWriteMethod() != null
|
||||||
&& areAssignmentCompatible( propertyDescriptor.getWriteMethod().getParameterTypes()[0], argType );
|
&& areAssignmentCompatible( propertyDescriptor.getWriteMethod().getParameterTypes()[0], argType );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue