use of org.hibernate.sql.ast.tree.expression.SelfRenderingExpression in project hibernate-orm by hibernate.
the class AnsiTrimEmulationFunctionTest method render.
private String render(Dialect dialect, TrimFunction function, TrimSpec trimSpec, char trimCharacter, String trimSource) {
SessionFactoryImplementor factory = Mockito.mock(SessionFactoryImplementor.class);
JdbcServices jdbcServices = Mockito.mock(JdbcServices.class);
Mockito.doReturn(jdbcServices).when(factory).getJdbcServices();
Mockito.doReturn(dialect).when(jdbcServices).getDialect();
StandardSqlAstTranslator<JdbcOperation> walker = new StandardSqlAstTranslator<>(factory, null);
List<SqlAstNode> sqlAstArguments = new ArrayList<>();
sqlAstArguments.add(new TrimSpecification(trimSpec));
sqlAstArguments.add(new QueryLiteral<>(trimCharacter, new BasicTypeImpl<>(CharacterJavaType.INSTANCE, CharJdbcType.INSTANCE)));
sqlAstArguments.add(new SelfRenderingExpression() {
@Override
public void renderToSql(SqlAppender sqlAppender, SqlAstTranslator<?> walker, SessionFactoryImplementor sessionFactory) {
sqlAppender.appendSql(trimSource);
}
@Override
public JdbcMappingContainer getExpressionType() {
return null;
}
});
function.render(walker, sqlAstArguments, walker);
return walker.getSql();
}
use of org.hibernate.sql.ast.tree.expression.SelfRenderingExpression in project hibernate-orm by hibernate.
the class CaseStatementDiscriminatorMappingImpl method createCaseSearchedExpression.
private Expression createCaseSearchedExpression(TableGroup entityTableGroup) {
return new SelfRenderingExpression() {
CaseSearchedExpression caseSearchedExpression;
@Override
public void renderToSql(SqlAppender sqlAppender, SqlAstTranslator<?> walker, SessionFactoryImplementor sessionFactory) {
if (caseSearchedExpression == null) {
// todo (6.0): possible optimization is to omit cases for table reference joins, that touch a super class, where a subclass is inner joined due to pruning
caseSearchedExpression = new CaseSearchedExpression(CaseStatementDiscriminatorMappingImpl.this);
tableDiscriminatorDetailsMap.forEach((tableName, tableDiscriminatorDetails) -> {
final TableReference tableReference = entityTableGroup.getTableReference(entityTableGroup.getNavigablePath(), tableName, false, false);
if (tableReference == null) {
// assume this is because it is a table that is not part of the processing entity's sub-hierarchy
return;
}
final Predicate predicate = new NullnessPredicate(new ColumnReference(tableReference, tableDiscriminatorDetails.getCheckColumnName(), false, null, null, getJdbcMapping(), getSessionFactory()), true);
caseSearchedExpression.when(predicate, new QueryLiteral<>(tableDiscriminatorDetails.getDiscriminatorValue(), getUnderlyingJdbcMappingType()));
});
}
caseSearchedExpression.accept(walker);
}
@Override
public JdbcMappingContainer getExpressionType() {
return CaseStatementDiscriminatorMappingImpl.this;
}
};
}
Aggregations