Search in sources :

Example 1 with JdbcOperation

use of org.hibernate.sql.exec.spi.JdbcOperation in project hibernate-orm by hibernate.

the class AbstractSqlAstTranslator method translate.

@Override
public T translate(JdbcParameterBindings jdbcParameterBindings, QueryOptions queryOptions) {
    try {
        this.jdbcParameterBindings = jdbcParameterBindings;
        this.lockOptions = queryOptions.getLockOptions().makeCopy();
        this.limit = queryOptions.getLimit() == null ? null : queryOptions.getLimit().makeCopy();
        final JdbcOperation jdbcOperation;
        if (statement instanceof DeleteStatement) {
            jdbcOperation = translateDelete((DeleteStatement) statement);
        } else if (statement instanceof UpdateStatement) {
            jdbcOperation = translateUpdate((UpdateStatement) statement);
        } else if (statement instanceof InsertStatement) {
            jdbcOperation = translateInsert((InsertStatement) statement);
        } else if (statement instanceof SelectStatement) {
            jdbcOperation = translateSelect((SelectStatement) statement);
        } else {
            throw new IllegalArgumentException("Unexpected statement!");
        }
        if (jdbcParameterBindings != null && CollectionHelper.isNotEmpty(getFilterJdbcParameters())) {
            for (FilterJdbcParameter filterJdbcParameter : getFilterJdbcParameters()) {
                jdbcParameterBindings.addBinding(filterJdbcParameter.getParameter(), filterJdbcParameter.getBinding());
            }
        }
        return (T) jdbcOperation;
    } finally {
        cleanup();
    }
}
Also used : SelectStatement(org.hibernate.sql.ast.tree.select.SelectStatement) UpdateStatement(org.hibernate.sql.ast.tree.update.UpdateStatement) JdbcOperation(org.hibernate.sql.exec.spi.JdbcOperation) DeleteStatement(org.hibernate.sql.ast.tree.delete.DeleteStatement) FilterJdbcParameter(org.hibernate.internal.FilterJdbcParameter) InsertStatement(org.hibernate.sql.ast.tree.insert.InsertStatement)

Example 2 with JdbcOperation

use of org.hibernate.sql.exec.spi.JdbcOperation 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();
}
Also used : SqlAppender(org.hibernate.sql.ast.spi.SqlAppender) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) BasicTypeImpl(org.hibernate.type.internal.BasicTypeImpl) JdbcOperation(org.hibernate.sql.exec.spi.JdbcOperation) ArrayList(java.util.ArrayList) TrimSpecification(org.hibernate.sql.ast.tree.expression.TrimSpecification) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) SqlAstNode(org.hibernate.sql.ast.tree.SqlAstNode) JdbcMappingContainer(org.hibernate.metamodel.mapping.JdbcMappingContainer) SelfRenderingExpression(org.hibernate.sql.ast.tree.expression.SelfRenderingExpression) StandardSqlAstTranslator(org.hibernate.sql.ast.spi.StandardSqlAstTranslator)

Aggregations

JdbcOperation (org.hibernate.sql.exec.spi.JdbcOperation)2 ArrayList (java.util.ArrayList)1 JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)1 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)1 FilterJdbcParameter (org.hibernate.internal.FilterJdbcParameter)1 JdbcMappingContainer (org.hibernate.metamodel.mapping.JdbcMappingContainer)1 SqlAppender (org.hibernate.sql.ast.spi.SqlAppender)1 StandardSqlAstTranslator (org.hibernate.sql.ast.spi.StandardSqlAstTranslator)1 SqlAstNode (org.hibernate.sql.ast.tree.SqlAstNode)1 DeleteStatement (org.hibernate.sql.ast.tree.delete.DeleteStatement)1 SelfRenderingExpression (org.hibernate.sql.ast.tree.expression.SelfRenderingExpression)1 TrimSpecification (org.hibernate.sql.ast.tree.expression.TrimSpecification)1 InsertStatement (org.hibernate.sql.ast.tree.insert.InsertStatement)1 SelectStatement (org.hibernate.sql.ast.tree.select.SelectStatement)1 UpdateStatement (org.hibernate.sql.ast.tree.update.UpdateStatement)1 BasicTypeImpl (org.hibernate.type.internal.BasicTypeImpl)1