Search in sources :

Example 26 with Configuration

use of org.jooq.Configuration in project jOOQ by jOOQ.

the class RowSubqueryCondition method delegate.

private final QueryPartInternal delegate(Context<?> ctx) {
    final Configuration configuration = ctx.configuration();
    final RenderContext render = ctx instanceof RenderContext ? (RenderContext) ctx : null;
    SQLDialect family = configuration.dialect().family();
    // [#3505] TODO: Emulate this where it is not supported
    if (rightQuantified != null) {
        return new Native();
    } else // predicates with row value expressions and subqueries:
    if (asList(H2, HSQLDB, MARIADB, MYSQL, POSTGRES).contains(family)) {
        return new Native();
    } else // [#2395] All other configurations have to be emulated
    {
        String table = render == null ? "t" : render.nextAlias();
        List<String> names = new ArrayList<String>();
        for (int i = 0; i < left.size(); i++) {
            names.add(table + "_" + i);
        }
        Field<?>[] fields = new Field[names.size()];
        for (int i = 0; i < fields.length; i++) {
            fields[i] = field(name(table, names.get(i)));
        }
        Condition condition;
        switch(comparator) {
            case GREATER:
                condition = ((RowN) left).gt(row(fields));
                break;
            case GREATER_OR_EQUAL:
                condition = ((RowN) left).ge(row(fields));
                break;
            case LESS:
                condition = ((RowN) left).lt(row(fields));
                break;
            case LESS_OR_EQUAL:
                condition = ((RowN) left).le(row(fields));
                break;
            case IN:
            case EQUALS:
            case NOT_IN:
            case NOT_EQUALS:
            default:
                condition = ((RowN) left).eq(row(fields));
                break;
        }
        Select<Record> subselect = select().from(right.asTable(table, names.toArray(EMPTY_STRING))).where(condition);
        switch(comparator) {
            case NOT_IN:
            case NOT_EQUALS:
                return (QueryPartInternal) notExists(subselect);
            default:
                return (QueryPartInternal) exists(subselect);
        }
    }
}
Also used : Condition(org.jooq.Condition) RenderContext(org.jooq.RenderContext) RowN(org.jooq.RowN) Configuration(org.jooq.Configuration) SQLDialect(org.jooq.SQLDialect) Select(org.jooq.Select) QuantifiedSelect(org.jooq.QuantifiedSelect) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List)

Example 27 with Configuration

use of org.jooq.Configuration in project jOOQ by jOOQ.

the class Mock method result.

/**
     * Wrap a record in a result.
     */
static final Result<?> result(Record data) {
    Configuration configuration = data instanceof AttachableInternal ? ((AttachableInternal) data).configuration() : new DefaultConfiguration();
    Result<Record> result = using(configuration).newResult(data.fields());
    result.add(data);
    return result;
}
Also used : Configuration(org.jooq.Configuration) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) Record(org.jooq.Record) AttachableInternal(org.jooq.AttachableInternal)

Example 28 with Configuration

use of org.jooq.Configuration in project spring-boot by spring-projects.

the class JooqExceptionTranslatorTests method exceptionTranslation.

@Test
public void exceptionTranslation() {
    ExecuteContext context = mock(ExecuteContext.class);
    Configuration configuration = mock(Configuration.class);
    given(context.configuration()).willReturn(configuration);
    given(configuration.dialect()).willReturn(this.dialect);
    given(context.sqlException()).willReturn(this.sqlException);
    this.exceptionTranslator.exception(context);
    ArgumentCaptor<RuntimeException> captor = ArgumentCaptor.forClass(RuntimeException.class);
    verify(context).exception(captor.capture());
    assertThat(captor.getValue()).isInstanceOf(BadSqlGrammarException.class);
}
Also used : Configuration(org.jooq.Configuration) ExecuteContext(org.jooq.ExecuteContext) Test(org.junit.Test)

Example 29 with Configuration

use of org.jooq.Configuration in project vertx-zero by silentbalanceyh.

the class JooqInfix method initInternal.

private static void initInternal(final Vertx vertx, final String name) {
    vertxRef = vertx;
    Fn.pool(CONFIGS, name, () -> Infix.init(Plugins.Infix.JOOQ, (config) -> {
        // Initialized client
        final Configuration configuration = new DefaultConfiguration();
        configuration.set(SQLDialect.MYSQL_8_0);
        final ConnectionProvider provider = new DefaultConnectionProvider(HikariCpPool.getConnection(config.getJsonObject("provider")));
        // Initialized default configuration
        configuration.set(provider);
        return configuration;
    }, JooqInfix.class));
}
Also used : Fn(io.vertx.up.func.Fn) HikariCpPool(io.vertx.tp.hikari.HikariCpPool) ConnectionProvider(org.jooq.ConnectionProvider) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) Infix(io.vertx.up.plugin.Infix) Vertx(io.vertx.core.Vertx) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DefaultConnectionProvider(org.jooq.impl.DefaultConnectionProvider) Plugin(io.vertx.up.annotations.Plugin) Instance(io.vertx.up.tool.mirror.Instance) ConcurrentMap(java.util.concurrent.ConcurrentMap) Configuration(org.jooq.Configuration) DSLContext(org.jooq.DSLContext) Plugins(io.vertx.up.eon.Plugins) SQLDialect(org.jooq.SQLDialect) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) Configuration(org.jooq.Configuration) DefaultConnectionProvider(org.jooq.impl.DefaultConnectionProvider) DefaultConfiguration(org.jooq.impl.DefaultConfiguration) ConnectionProvider(org.jooq.ConnectionProvider) DefaultConnectionProvider(org.jooq.impl.DefaultConnectionProvider)

Example 30 with Configuration

use of org.jooq.Configuration in project spring-boot by spring-projects.

the class JooqExceptionTranslatorTests method whenExceptionCannotBeTranslatedThenExecuteContextExceptionIsNotCalled.

@Test
void whenExceptionCannotBeTranslatedThenExecuteContextExceptionIsNotCalled() {
    ExecuteContext context = mock(ExecuteContext.class);
    Configuration configuration = mock(Configuration.class);
    given(context.configuration()).willReturn(configuration);
    given(configuration.dialect()).willReturn(SQLDialect.POSTGRES);
    given(context.sqlException()).willReturn(new SQLException(null, null, 123456789));
    this.exceptionTranslator.exception(context);
    then(context).should(never()).exception(any());
}
Also used : Configuration(org.jooq.Configuration) SQLException(java.sql.SQLException) ExecuteContext(org.jooq.ExecuteContext) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Configuration (org.jooq.Configuration)46 DSLContext (org.jooq.DSLContext)13 List (java.util.List)9 ArrayList (java.util.ArrayList)8 ExecuteContext (org.jooq.ExecuteContext)8 Query (org.jooq.Query)8 Record (org.jooq.Record)6 DefaultConfiguration (org.jooq.impl.DefaultConfiguration)6 Arrays (java.util.Arrays)5 SQLDialect (org.jooq.SQLDialect)5 BigInteger (java.math.BigInteger)4 OffsetDateTime (java.time.OffsetDateTime)4 Arrays.asList (java.util.Arrays.asList)4 Map (java.util.Map)4 Optional (java.util.Optional)4 DataAccessException (org.jooq.exception.DataAccessException)4 JooqLogger (org.jooq.tools.JooqLogger)4 SQLException (java.sql.SQLException)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3