use of org.springframework.data.relational.core.query.ValueFunction in project spring-data-jdbc by spring-projects.
the class QueryMapper method mapCondition.
private Condition mapCondition(CriteriaDefinition criteria, MapSqlParameterSource parameterSource, Table table, @Nullable RelationalPersistentEntity<?> entity) {
Field propertyField = createPropertyField(entity, criteria.getColumn(), this.mappingContext);
// Single embedded entity
if (propertyField.isEmbedded()) {
return mapEmbeddedObjectCondition(criteria, parameterSource, table, ((MetadataBackedField) propertyField).getPath().getLeafProperty());
}
TypeInformation<?> actualType = propertyField.getTypeHint().getRequiredActualType();
Column column = table.column(propertyField.getMappedColumnName());
Object mappedValue;
SQLType sqlType;
if (criteria.getValue() instanceof JdbcValue) {
JdbcValue settableValue = (JdbcValue) criteria.getValue();
mappedValue = convertValue(settableValue.getValue(), propertyField.getTypeHint());
sqlType = getTypeHint(mappedValue, actualType.getType(), settableValue);
} else if (criteria.getValue() instanceof ValueFunction) {
ValueFunction<Object> valueFunction = (ValueFunction<Object>) criteria.getValue();
Object value = valueFunction.apply(getEscaper(criteria.getComparator()));
mappedValue = convertValue(value, propertyField.getTypeHint());
sqlType = propertyField.getSqlType();
} else if (//
propertyField instanceof MetadataBackedField && //
((MetadataBackedField) propertyField).property != null && (criteria.getValue() == null || !criteria.getValue().getClass().isArray())) {
RelationalPersistentProperty property = ((MetadataBackedField) propertyField).property;
JdbcValue jdbcValue = convertToJdbcValue(property, criteria.getValue());
mappedValue = jdbcValue.getValue();
sqlType = jdbcValue.getJdbcType() != null ? jdbcValue.getJdbcType() : propertyField.getSqlType();
} else {
mappedValue = convertValue(criteria.getValue(), propertyField.getTypeHint());
sqlType = propertyField.getSqlType();
}
return createCondition(column, mappedValue, sqlType, parameterSource, criteria.getComparator(), criteria.isIgnoreCase());
}
Aggregations