Search in sources :

Example 1 with CACHE_PARSING_CONNECTION

use of org.jooq.impl.CacheType.CACHE_PARSING_CONNECTION 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

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 Configuration (org.jooq.Configuration)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 Rendered (org.jooq.impl.DefaultRenderContext.Rendered)1 EMPTY_PARAM (org.jooq.impl.Tools.EMPTY_PARAM)1