use of org.hibernate.metamodel.model.domain.internal.CompositeSqmPathSource in project hibernate-orm by hibernate.
the class BaseSqmToSqlAstConverter method determineValueMapping.
protected MappingModelExpressible<?> determineValueMapping(SqmParameter<?> sqmParameter) {
log.debugf("Determining mapping-model type for SqmParameter : %s", sqmParameter);
final QueryParameterImplementor<?> queryParameter = domainParameterXref.getQueryParameter(sqmParameter);
final QueryParameterBinding<?> binding = domainParameterBindings.getBinding(queryParameter);
BindableType<?> paramType = binding.getBindType();
if (paramType == null) {
paramType = queryParameter.getHibernateType();
if (paramType == null) {
paramType = sqmParameter.getAnticipatedType();
}
}
if (paramType == null) {
final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
if (inferredValueMapping != null) {
return inferredValueMapping;
}
// Default to the Object type
return basicType(Object.class);
} else if (paramType instanceof MappingModelExpressible<?>) {
final MappingModelExpressible<?> paramModelType = (MappingModelExpressible<?>) paramType;
final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
// Prefer the model part type instead of the bind type if possible as the model part type contains size information
if (inferredValueMapping instanceof ModelPart) {
final JdbcMapping paramJdbcMapping = paramModelType.getJdbcMappings().get(0);
final JdbcMapping inferredJdbcMapping = inferredValueMapping.getJdbcMappings().get(0);
// If the bind type has a different JDBC type, we prefer that
if (paramJdbcMapping.getJdbcType() == inferredJdbcMapping.getJdbcType()) {
return inferredValueMapping;
}
}
return paramModelType;
} else if (sqmParameter.getAnticipatedType() == null) {
// this should indicate the condition that the user query did not define an
// explicit type in regard to this parameter. Here we should prefer the
// inferrable type and fallback to resolving the binding type
final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
if (inferredValueMapping != null) {
return inferredValueMapping;
}
} else if (paramType instanceof EntityDomainType) {
// In JPA Criteria, it is possible to define a parameter of an entity type,
// but that should infer the mapping type from context,
// otherwise this would default to binding the PK which might be wrong
final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
if (inferredValueMapping != null) {
return inferredValueMapping;
}
}
final SqmExpressible<?> paramSqmType = paramType.resolveExpressible(creationContext.getSessionFactory());
if (paramSqmType instanceof SqmPath) {
final SqmPath<?> sqmPath = (SqmPath<?>) paramSqmType;
final NavigablePath navigablePath = sqmPath.getNavigablePath();
if (navigablePath.getParent() != null) {
final TableGroup tableGroup = getFromClauseAccess().getTableGroup(navigablePath.getParent());
return tableGroup.getModelPart().findSubPart(navigablePath.getLocalName(), null);
}
return getFromClauseAccess().getTableGroup(navigablePath).getModelPart();
}
if (paramSqmType instanceof BasicValuedMapping) {
return (BasicValuedMapping) paramSqmType;
}
if (paramSqmType instanceof CompositeSqmPathSource) {
// Try to infer the value mapping since the other side apparently is a path source
final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
if (inferredValueMapping != null) {
return inferredValueMapping;
}
throw new NotYetImplementedFor6Exception("Support for embedded-valued parameters not yet implemented");
}
if (paramSqmType instanceof SqmPathSource<?> || paramSqmType instanceof BasicDomainType<?>) {
// Try to infer the value mapping since the other side apparently is a path source
final MappingModelExpressible<?> inferredValueMapping = getInferredValueMapping();
if (inferredValueMapping != null) {
return inferredValueMapping;
}
return getTypeConfiguration().getBasicTypeForJavaType(paramSqmType.getExpressibleJavaType().getJavaTypeClass());
}
throw new ConversionException("Could not determine ValueMapping for SqmParameter: " + sqmParameter);
}
Aggregations