Search in sources :

Example 1 with Rendered

use of org.jooq.impl.DefaultRenderContext.Rendered in project jOOQ by jOOQ.

the class AbstractQuery method getSQL0.

private final Rendered getSQL0(ExecuteContext ctx) {
    Rendered result;
    DefaultRenderContext render;
    Configuration c = configurationOrThrow();
    // [#6474] [#6929] Can this be communicated in a leaner way?
    if (ctx.type() == DDL) {
        ctx.data(DATA_FORCE_STATIC_STATEMENT, true);
        render = new DefaultRenderContext(c);
        result = new Rendered(render.paramType(INLINED).visit(this).render(), null, render.skipUpdateCounts());
    } else if (executePreparedStatements(configuration().settings())) {
        try {
            render = new DefaultRenderContext(c);
            render.data(DATA_COUNT_BIND_VALUES, true);
            result = new Rendered(render.visit(this).render(), render.bindValues(), render.skipUpdateCounts());
        } catch (DefaultRenderContext.ForceInlineSignal e) {
            ctx.data(DATA_FORCE_STATIC_STATEMENT, true);
            render = new DefaultRenderContext(c);
            result = new Rendered(render.paramType(INLINED).visit(this).render(), null, render.skipUpdateCounts());
        }
    } else {
        render = new DefaultRenderContext(c);
        result = new Rendered(render.paramType(INLINED).visit(this).render(), null, render.skipUpdateCounts());
    }
    return result;
}
Also used : Configuration(org.jooq.Configuration) Rendered(org.jooq.impl.DefaultRenderContext.Rendered)

Example 2 with Rendered

use of org.jooq.impl.DefaultRenderContext.Rendered in project jOOQ by jOOQ.

the class ParsingConnection method translate.

static final Rendered translate(Configuration configuration, String sql, Param<?>... bindValues) {
    log.debug("Translating from", sql);
    Rendered result = null;
    Supplier<CacheValue> miss = () -> {
        log.debug("Translation cache miss", sql);
        return new CacheValue(configuration, sql, bindValues);
    };
    Settings settings = configuration.settings();
    if (CACHE_PARSING_CONNECTION.category.predicate.test(settings) && bindValues.length > 0) {
        switch(getParamType(settings)) {
            case INLINED:
            case NAMED_OR_INLINED:
                result = miss.get().rendered(bindValues);
                break;
        }
    }
    if (result == null)
        result = Cache.run(configuration, miss, CACHE_PARSING_CONNECTION, () -> Cache.key(sql, map(nonNull(bindValues), f -> f.getDataType()))).rendered(bindValues);
    log.debug("Translating to", result.sql);
    return result;
}
Also used : DataAccessException(org.jooq.exception.DataAccessException) DetachedException(org.jooq.exception.DetachedException) Tools.map(org.jooq.impl.Tools.map) JooqLogger(org.jooq.tools.JooqLogger) Collections.emptyList(java.util.Collections.emptyList) Settings(org.jooq.conf.Settings) HashMap(java.util.HashMap) PreparedStatement(java.sql.PreparedStatement) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) Param(org.jooq.Param) Configuration(org.jooq.Configuration) SQLException(java.sql.SQLException) List(java.util.List) SettingsTools.getParamType(org.jooq.conf.SettingsTools.getParamType) EMPTY_PARAM(org.jooq.impl.Tools.EMPTY_PARAM) Map(java.util.Map) Rendered(org.jooq.impl.DefaultRenderContext.Rendered) Statement(java.sql.Statement) CallableStatement(java.sql.CallableStatement) DSLContext(org.jooq.DSLContext) DefaultConnection(org.jooq.tools.jdbc.DefaultConnection) CACHE_PARSING_CONNECTION(org.jooq.impl.CacheType.CACHE_PARSING_CONNECTION) Rendered(org.jooq.impl.DefaultRenderContext.Rendered) Settings(org.jooq.conf.Settings)

Aggregations

Configuration (org.jooq.Configuration)2 Rendered (org.jooq.impl.DefaultRenderContext.Rendered)2 CallableStatement (java.sql.CallableStatement)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 Collections.emptyList (java.util.Collections.emptyList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Supplier (java.util.function.Supplier)1 DSLContext (org.jooq.DSLContext)1 Param (org.jooq.Param)1 Settings (org.jooq.conf.Settings)1 SettingsTools.getParamType (org.jooq.conf.SettingsTools.getParamType)1 DataAccessException (org.jooq.exception.DataAccessException)1 DetachedException (org.jooq.exception.DetachedException)1 CACHE_PARSING_CONNECTION (org.jooq.impl.CacheType.CACHE_PARSING_CONNECTION)1 EMPTY_PARAM (org.jooq.impl.Tools.EMPTY_PARAM)1