use of org.hibernate.sql.ast.tree.expression.Expression in project hibernate-orm by hibernate.
the class TimestampdiffFunction method render.
@Override
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> arguments, SqlAstTranslator<?> walker) {
final DurationUnit field = (DurationUnit) arguments.get(0);
final Expression from = (Expression) arguments.get(1);
final Expression to = (Expression) arguments.get(2);
patternRenderer(field.getUnit(), from, to).render(sqlAppender, arguments, walker);
}
use of org.hibernate.sql.ast.tree.expression.Expression in project hibernate-orm by hibernate.
the class TrimFunction method render.
@Override
public void render(SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
final TrimSpec specification = ((TrimSpecification) sqlAstArguments.get(0)).getSpecification();
final Object trimCharacter = ((Literal) sqlAstArguments.get(1)).getLiteralValue();
final Expression sourceExpr = (Expression) sqlAstArguments.get(2);
String trim = dialect.trimPattern(specification, (char) trimCharacter);
new PatternRenderer(trim).render(sqlAppender, Collections.singletonList(sourceExpr), walker);
}
use of org.hibernate.sql.ast.tree.expression.Expression in project hibernate-orm by hibernate.
the class CompoundNaturalIdLoader method applyNaturalIdRestriction.
@Override
protected void applyNaturalIdRestriction(Object bindValue, TableGroup rootTableGroup, Consumer<Predicate> predicateConsumer, BiConsumer<JdbcParameter, JdbcParameterBinding> jdbcParameterConsumer, LoaderSqlAstCreationState sqlAstCreationState, SharedSessionContractImplementor session) {
final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver();
final SessionFactoryImplementor factory = session.getFactory();
if (bindValue == null) {
final List<SingularAttributeMapping> naturalIdAttributes = naturalIdMapping().getNaturalIdAttributes();
for (int i = 0; i < naturalIdAttributes.size(); i++) {
naturalIdAttributes.get(i).forEachSelectable((index, selectable) -> {
final Expression columnRef = resolveColumnReference(rootTableGroup, selectable, sqlExpressionResolver, factory);
predicateConsumer.accept(new NullnessPredicate(columnRef));
});
}
// EARLY EXIT!!
return;
}
naturalIdMapping().breakDownJdbcValues(bindValue, (jdbcValue, jdbcValueMapping) -> {
final Expression columnReference = resolveColumnReference(rootTableGroup, jdbcValueMapping, sqlExpressionResolver, factory);
if (jdbcValue == null) {
predicateConsumer.accept(new NullnessPredicate(columnReference));
} else {
final JdbcParameter jdbcParameter = new JdbcParameterImpl(jdbcValueMapping.getJdbcMapping());
final ComparisonPredicate predicate = new ComparisonPredicate(columnReference, ComparisonOperator.EQUAL, jdbcParameter);
predicateConsumer.accept(predicate);
jdbcParameterConsumer.accept(jdbcParameter, new JdbcParameterBindingImpl(jdbcValueMapping.getJdbcMapping(), jdbcValue));
}
}, session);
}
use of org.hibernate.sql.ast.tree.expression.Expression in project hibernate-orm by hibernate.
the class DomainResultCreationStateImpl method resolveSqlExpression.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// SqlExpressionResolver
@Override
public Expression resolveSqlExpression(String key, Function<SqlAstProcessingState, Expression> creator) {
final ResultSetMappingSqlSelection existing = sqlSelectionMap.get(key);
if (existing != null) {
return existing;
}
final Expression created = creator.apply(this);
if (created instanceof ResultSetMappingSqlSelection) {
sqlSelectionMap.put(key, (ResultSetMappingSqlSelection) created);
sqlSelectionConsumer.accept((ResultSetMappingSqlSelection) created);
} else if (created instanceof ColumnReference) {
final ColumnReference columnReference = (ColumnReference) created;
final String columnExpression = columnReference.getColumnExpression();
final int jdbcPosition = jdbcResultsMetadata.resolveColumnPosition(columnExpression);
final int valuesArrayPosition = ResultsHelper.jdbcPositionToValuesArrayPosition(jdbcPosition);
final ResultSetMappingSqlSelection sqlSelection = new ResultSetMappingSqlSelection(valuesArrayPosition, columnReference.getJdbcMapping());
sqlSelectionMap.put(key, sqlSelection);
sqlSelectionConsumer.accept(sqlSelection);
return sqlSelection;
}
return created;
}
use of org.hibernate.sql.ast.tree.expression.Expression in project hibernate-orm by hibernate.
the class BaseSqmToSqlAstConverter method consumeSqmParameter.
protected Expression consumeSqmParameter(SqmParameter<?> sqmParameter, MappingModelExpressible<?> valueMapping, BiConsumer<Integer, JdbcParameter> jdbcParameterConsumer) {
final List<JdbcParameter> jdbcParametersForSqm = new ArrayList<>();
resolveSqmParameter(sqmParameter, valueMapping, (index, jdbcParameter) -> {
jdbcParameterConsumer.accept(index, jdbcParameter);
jdbcParametersForSqm.add(jdbcParameter);
});
this.jdbcParameters.addParameters(jdbcParametersForSqm);
this.jdbcParamsBySqmParam.computeIfAbsent(sqmParameter, k -> new ArrayList<>(1)).add(jdbcParametersForSqm);
final QueryParameterImplementor<?> queryParameter = domainParameterXref.getQueryParameter(sqmParameter);
final QueryParameterBinding binding = domainParameterBindings.getBinding(queryParameter);
if (binding.setType(valueMapping)) {
replaceJdbcParametersType(sqmParameter, domainParameterXref.getSqmParameters(queryParameter), valueMapping);
}
return new SqmParameterInterpretation(sqmParameter, queryParameter, jdbcParametersForSqm, valueMapping, qp -> binding);
}
Aggregations