use of org.hibernate.sql.ast.tree.expression.TrimSpecification 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.TrimSpecification 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);
}
Aggregations