Search in sources :

Example 1 with Context

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

the class InsertQueryImpl method toInsertSelect.

@SuppressWarnings("unchecked")
private final QueryPart toInsertSelect(Context<?> ctx) {
    List<List<? extends Field<?>>> keys = conflictingKeys(ctx);
    if (!keys.isEmpty()) {
        Select<Record> rows = null;
        Set<Field<?>> fields = insertMaps.keysFlattened(ctx);
        // [#10989] INSERT .. SELECT .. ON DUPLICATE KEY IGNORE
        if (select != null) {
            Map<Field<?>, Field<?>> map = new HashMap<>();
            Field<?>[] names = Tools.fields(select.fields().length);
            List<Field<?>> f = new ArrayList<>(fields);
            for (int i = 0; i < fields.size() && i < names.length; i++) map.put(f.get(i), names[i]);
            rows = (Select<Record>) selectFrom(select.asTable(DSL.table(name("t")), names)).whereNotExists(selectOne().from(table()).where(matchByConflictingKeys(ctx, map)));
        } else // [#5089] Multi-row inserts need to explicitly generate UNION ALL
        // here. TODO: Refactor this logic to be more generally
        // reusable - i.e. ordinary UNION ALL emulation should be
        // re-used.
        {
            for (Map<Field<?>, Field<?>> map : insertMaps.maps()) {
                Select<Record> row = select(aliasedFields(map.entrySet().stream().filter(e -> fields.contains(e.getKey())).map(Entry::getValue).collect(toList()))).whereNotExists(selectOne().from(table()).where(matchByConflictingKeys(ctx, map)));
                if (rows == null)
                    rows = row;
                else
                    rows = rows.unionAll(row);
            }
        }
        return ctx.dsl().insertInto(table()).columns(fields).select(selectFrom(rows.asTable("t")));
    } else
        return DSL.sql("[ The ON DUPLICATE KEY IGNORE/UPDATE clause cannot be emulated when inserting into tables without any known keys : " + table() + " ]");
}
Also used : K_VALUES(org.jooq.impl.Keywords.K_VALUES) QueryPartListView.wrap(org.jooq.impl.QueryPartListView.wrap) UniqueKey(org.jooq.UniqueKey) Arrays(java.util.Arrays) Tools.map(org.jooq.impl.Tools.map) UNotYetImplemented(org.jooq.impl.QOM.UNotYetImplemented) InsertQuery(org.jooq.InsertQuery) Table(org.jooq.Table) MergeOnConditionStep(org.jooq.MergeOnConditionStep) Operator(org.jooq.Operator) Condition(org.jooq.Condition) Collections.singletonList(java.util.Collections.singletonList) K_DEFAULT_VALUES(org.jooq.impl.Keywords.K_DEFAULT_VALUES) Clause(org.jooq.Clause) Arrays.asList(java.util.Arrays.asList) K_IGNORE(org.jooq.impl.Keywords.K_IGNORE) Tools.unqualified(org.jooq.impl.Tools.unqualified) Map(java.util.Map) SQLDialect(org.jooq.SQLDialect) Scope(org.jooq.Scope) Tools.aliasedFields(org.jooq.impl.Tools.aliasedFields) Select(org.jooq.Select) DSL.constraint(org.jooq.impl.DSL.constraint) DSL.name(org.jooq.impl.DSL.name) WriteIfReadonly(org.jooq.conf.WriteIfReadonly) Collections.nCopies(java.util.Collections.nCopies) Name(org.jooq.Name) DSL.falseCondition(org.jooq.impl.DSL.falseCondition) Collection(java.util.Collection) Set(java.util.Set) DataExtendedKey(org.jooq.impl.Tools.DataExtendedKey) Field(org.jooq.Field) DSL.select(org.jooq.impl.DSL.select) DATA_INSERT_SELECT_WITHOUT_INSERT_COLUMN_LIST(org.jooq.impl.Tools.BooleanDataKey.DATA_INSERT_SELECT_WITHOUT_INSERT_COLUMN_LIST) INSERT_SELECT(org.jooq.Clause.INSERT_SELECT) Collectors(java.util.stream.Collectors) QueryPart(org.jooq.QueryPart) K_INTO(org.jooq.impl.Keywords.K_INTO) K_ON_DUPLICATE_KEY_UPDATE(org.jooq.impl.Keywords.K_ON_DUPLICATE_KEY_UPDATE) List(java.util.List) K_INSERT(org.jooq.impl.Keywords.K_INSERT) DATA_ON_DUPLICATE_KEY_WHERE(org.jooq.impl.Tools.DataKey.DATA_ON_DUPLICATE_KEY_WHERE) Context(org.jooq.Context) K_SET(org.jooq.impl.Keywords.K_SET) TableField(org.jooq.TableField) Entry(java.util.Map.Entry) INSERT(org.jooq.Clause.INSERT) DATA_INSERT_SELECT(org.jooq.impl.Tools.BooleanDataKey.DATA_INSERT_SELECT) K_ON_CONFLICT(org.jooq.impl.Keywords.K_ON_CONFLICT) TRUE(java.lang.Boolean.TRUE) Tools.anyMatch(org.jooq.impl.Tools.anyMatch) DERBY(org.jooq.SQLDialect.DERBY) Merge(org.jooq.Merge) HashMap(java.util.HashMap) INSERT_ON_DUPLICATE_KEY_UPDATE_ASSIGNMENT(org.jooq.Clause.INSERT_ON_DUPLICATE_KEY_UPDATE_ASSIGNMENT) DSL.row(org.jooq.impl.DSL.row) ArrayList(java.util.ArrayList) MergeNotMatchedStep(org.jooq.MergeNotMatchedStep) K_ON_CONSTRAINT(org.jooq.impl.Keywords.K_ON_CONSTRAINT) DATA_CONSTRAINT_REFERENCE(org.jooq.impl.Tools.BooleanDataKey.DATA_CONSTRAINT_REFERENCE) Identity(org.jooq.Identity) DSL.selectFrom(org.jooq.impl.DSL.selectFrom) INSERT_RETURNING(org.jooq.Clause.INSERT_RETURNING) Tools.flattenCollection(org.jooq.impl.Tools.flattenCollection) K_DEFAULT(org.jooq.impl.Keywords.K_DEFAULT) INSERT_ON_DUPLICATE_KEY_UPDATE(org.jooq.Clause.INSERT_ON_DUPLICATE_KEY_UPDATE) K_DO_NOTHING(org.jooq.impl.Keywords.K_DO_NOTHING) INSERT_INSERT_INTO(org.jooq.Clause.INSERT_INSERT_INTO) MYSQL(org.jooq.SQLDialect.MYSQL) Record(org.jooq.Record) Tools.collect(org.jooq.impl.Tools.collect) K_DO_UPDATE(org.jooq.impl.Keywords.K_DO_UPDATE) StringUtils(org.jooq.tools.StringUtils) DSL.selectOne(org.jooq.impl.DSL.selectOne) K_WHERE(org.jooq.impl.Keywords.K_WHERE) Constraint(org.jooq.Constraint) DSL.one(org.jooq.impl.DSL.one) Configuration(org.jooq.Configuration) Collectors.toList(java.util.stream.Collectors.toList) H2(org.jooq.SQLDialect.H2) MARIADB(org.jooq.SQLDialect.MARIADB) EMPTY_FIELD(org.jooq.impl.Tools.EMPTY_FIELD) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DSL.constraint(org.jooq.impl.DSL.constraint) Constraint(org.jooq.Constraint) Field(org.jooq.Field) TableField(org.jooq.TableField) Entry(java.util.Map.Entry) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) Record(org.jooq.Record)

Example 2 with Context

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

the class BlockImpl method accept0.

private final void accept0(Context<?> ctx) {
    boolean wrapInBeginEnd = alwaysWrapInBeginEnd;
    if (wrapInBeginEnd) {
        boolean topLevel = ctx.scopeLevel() == -1;
        LanguageContext language = ctx.languageContext();
        if (topLevel && language == LanguageContext.QUERY)
            ctx.languageContext(LanguageContext.BLOCK);
        {
            begin(ctx, topLevel);
            scopeDeclarations(ctx, c -> accept1(c));
            end(ctx, topLevel);
        }
        if (topLevel && language == LanguageContext.QUERY)
            ctx.languageContext(language);
    } else
        accept1(ctx);
}
Also used : K_BEGIN(org.jooq.impl.Keywords.K_BEGIN) BiFunction(java.util.function.BiFunction) K_TRUE(org.jooq.impl.Keywords.K_TRUE) UnmodifiableList(org.jooq.impl.QOM.UnmodifiableList) POSTGRES(org.jooq.SQLDialect.POSTGRES) Map(java.util.Map) Tools.decrement(org.jooq.impl.Tools.decrement) SQLDialect(org.jooq.SQLDialect) K_DROP(org.jooq.impl.Keywords.K_DROP) K_NOT(org.jooq.impl.Keywords.K_NOT) DATA_FORCE_STATIC_STATEMENT(org.jooq.impl.Tools.BooleanDataKey.DATA_FORCE_STATIC_STATEMENT) LanguageContext(org.jooq.LanguageContext) Predicate(java.util.function.Predicate) Name(org.jooq.Name) Collection(java.util.Collection) Keyword(org.jooq.Keyword) K_IF(org.jooq.impl.Keywords.K_IF) Tools.toplevel(org.jooq.impl.Tools.toplevel) Set(java.util.Set) DataExtendedKey(org.jooq.impl.Tools.DataExtendedKey) DATA_BLOCK_NESTING(org.jooq.impl.Tools.DataKey.DATA_BLOCK_NESTING) K_ATOMIC(org.jooq.impl.Keywords.K_ATOMIC) QueryPart(org.jooq.QueryPart) Statement(org.jooq.Statement) Block(org.jooq.Block) HSQLDB(org.jooq.SQLDialect.HSQLDB) K_CALL(org.jooq.impl.Keywords.K_CALL) K_AS(org.jooq.impl.Keywords.K_AS) Context(org.jooq.Context) K_END(org.jooq.impl.Keywords.K_END) Query(org.jooq.Query) K_EXECUTE_STATEMENT(org.jooq.impl.Keywords.K_EXECUTE_STATEMENT) DDLQuery(org.jooq.DDLQuery) K_EXECUTE_IMMEDIATE(org.jooq.impl.Keywords.K_EXECUTE_IMMEDIATE) INLINED(org.jooq.conf.ParamType.INLINED) K_EXECUTE_BLOCK(org.jooq.impl.Keywords.K_EXECUTE_BLOCK) ParamType(org.jooq.conf.ParamType) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) K_ALIAS(org.jooq.impl.Keywords.K_ALIAS) Function1(org.jooq.Function1) MYSQL(org.jooq.SQLDialect.MYSQL) K_DO(org.jooq.impl.Keywords.K_DO) FIREBIRD(org.jooq.SQLDialect.FIREBIRD) K_CREATE(org.jooq.impl.Keywords.K_CREATE) ScopeContent(org.jooq.impl.ScopeMarker.ScopeContent) Consumer(java.util.function.Consumer) Configuration(org.jooq.Configuration) YUGABYTEDB(org.jooq.SQLDialect.YUGABYTEDB) H2(org.jooq.SQLDialect.H2) MARIADB(org.jooq.SQLDialect.MARIADB) K_THEN(org.jooq.impl.Keywords.K_THEN) Tools.increment(org.jooq.impl.Tools.increment) LanguageContext(org.jooq.LanguageContext)

Example 3 with Context

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

the class AbstractRowAsField method acceptMultisetContent.

static final void acceptMultisetContent(Context<?> ctx, Row row, Field<?> field, Consumer<? super Context<?>> acceptDefault) {
    Object previous = ctx.data(DATA_MULTISET_CONTENT);
    try {
        ctx.data(DATA_MULTISET_CONTENT, true);
        Name alias = field.getUnqualifiedName();
        switch(emulateMultiset(ctx.configuration())) {
            case JSON:
                switch(ctx.family()) {
                    default:
                        ctx.visit(alias(ctx, alias, returningClob(ctx, jsonArray(row.fields()).nullOnNull())));
                        break;
                }
                break;
            case JSONB:
                switch(ctx.family()) {
                    default:
                        ctx.visit(alias(ctx, alias, returningClob(ctx, jsonbArray(row.fields()).nullOnNull())));
                        break;
                }
                break;
            case XML:
                switch(ctx.family()) {
                    default:
                        ctx.visit(alias(ctx, alias, xmlelement(N_RECORD, map(row.fields(), (f, i) -> xmlelement(fieldNameString(i), f)))));
                        break;
                }
                break;
            // case ARRAY:
            case NATIVE:
            default:
                acceptDefault.accept(ctx);
                break;
        }
    } finally {
        ctx.data(DATA_MULTISET_CONTENT, previous);
    }
}
Also used : Tools.fieldNameString(org.jooq.impl.Tools.fieldNameString) Record(org.jooq.Record) DataType(org.jooq.DataType) Row(org.jooq.Row) Tools.map(org.jooq.impl.Tools.map) Name(org.jooq.Name) Tools.row0(org.jooq.impl.Tools.row0) Field(org.jooq.Field) DSL.jsonbObject(org.jooq.impl.DSL.jsonbObject) DSL.select(org.jooq.impl.DSL.select) DATA_MULTISET_CONTENT(org.jooq.impl.Tools.BooleanDataKey.DATA_MULTISET_CONTENT) DSL.xmlelement(org.jooq.impl.DSL.xmlelement) BooleanSupplier(java.util.function.BooleanSupplier) DSL.jsonbArray(org.jooq.impl.DSL.jsonbArray) Consumer(java.util.function.Consumer) Configuration(org.jooq.Configuration) DSL.jsonArray(org.jooq.impl.DSL.jsonArray) Tools.emulateMultiset(org.jooq.impl.Tools.emulateMultiset) Context(org.jooq.Context) Multiset.returningClob(org.jooq.impl.Multiset.returningClob) Fields(org.jooq.Fields) DSL.jsonObject(org.jooq.impl.DSL.jsonObject) N_RECORD(org.jooq.impl.Names.N_RECORD) TRUE(java.lang.Boolean.TRUE) DSL.jsonbObject(org.jooq.impl.DSL.jsonbObject) DSL.jsonObject(org.jooq.impl.DSL.jsonObject) Name(org.jooq.Name)

Example 4 with Context

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

the class SelectQueryImpl method accept0.

final void accept0(Context<?> context) {
    boolean topLevelCte = false;
    // Subquery scopes are started in AbstractContext
    if (context.subqueryLevel() == 0) {
        context.scopeStart();
        if (topLevelCte |= (context.data(DATA_TOP_LEVEL_CTE) == null))
            context.data(DATA_TOP_LEVEL_CTE, new TopLevelCte());
    }
    SQLDialect dialect = context.dialect();
    // [#2791] TODO: Instead of explicitly manipulating these data() objects, future versions
    // of jOOQ should implement a push / pop semantics to clearly delimit such scope.
    Object renderTrailingLimit = context.data(DATA_RENDER_TRAILING_LIMIT_IF_APPLICABLE);
    Object localWindowDefinitions = context.data(DATA_WINDOW_DEFINITIONS);
    Name[] selectAliases = (Name[]) context.data(DATA_SELECT_ALIASES);
    try {
        List<Field<?>> originalFields = null;
        List<Field<?>> alternativeFields = null;
        if (selectAliases != null) {
            context.data().remove(DATA_SELECT_ALIASES);
            alternativeFields = map(originalFields = getSelect(), (f, i) -> i < selectAliases.length ? f.as(selectAliases[i]) : f);
        }
        if (TRUE.equals(renderTrailingLimit))
            context.data().remove(DATA_RENDER_TRAILING_LIMIT_IF_APPLICABLE);
        // [#5127] Lazy initialise this map
        if (localWindowDefinitions != null)
            context.data(DATA_WINDOW_DEFINITIONS, null);
        if (intoTable != null && !TRUE.equals(context.data(DATA_OMIT_INTO_CLAUSE)) && EMULATE_SELECT_INTO_AS_CTAS.contains(dialect)) {
            context.data(DATA_OMIT_INTO_CLAUSE, true, c -> c.visit(createTable(intoTable).as(this)));
            return;
        }
        if (with != null)
            context.visit(with);
        else if (topLevelCte)
            markTopLevelCteAndAccept(context, c -> {
            });
        pushWindow(context);
        Boolean wrapDerivedTables = (Boolean) context.data(DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES);
        if (TRUE.equals(wrapDerivedTables)) {
            context.sqlIndentStart('(').data().remove(DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES);
        }
        switch(dialect) {
            case CUBRID:
            case FIREBIRD:
            case MYSQL:
            case YUGABYTEDB:
                {
                    if (getLimit().isApplicable() && getLimit().withTies())
                        toSQLReferenceLimitWithWindowFunctions(context);
                    else
                        toSQLReferenceLimitDefault(context, originalFields, alternativeFields);
                    break;
                }
            // By default, render the dialect's limit clause
            default:
                {
                    toSQLReferenceLimitDefault(context, originalFields, alternativeFields);
                    break;
                }
        }
        // [#1296] [#7328] FOR UPDATE is emulated in some dialects using hints
        if (forLock != null)
            context.visit(forLock);
        // end-of-query clauses are appended to the end of a query
        if (!StringUtils.isBlank(option))
            context.formatSeparator().sql(option);
        if (TRUE.equals(wrapDerivedTables))
            context.sqlIndentEnd(')').data(DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES, true);
    } finally {
        context.data(DATA_WINDOW_DEFINITIONS, localWindowDefinitions);
        if (renderTrailingLimit != null)
            context.data(DATA_RENDER_TRAILING_LIMIT_IF_APPLICABLE, renderTrailingLimit);
        if (selectAliases != null)
            context.data(DATA_SELECT_ALIASES, selectAliases);
    }
    if (context.subqueryLevel() == 0)
        context.scopeEnd();
}
Also used : Internal.isub(org.jooq.impl.Internal.isub) Tools.aliased(org.jooq.impl.Tools.aliased) UnmodifiableList(org.jooq.impl.QOM.UnmodifiableList) DSL.emptyGroupingSet(org.jooq.impl.DSL.emptyGroupingSet) K_BY(org.jooq.impl.Keywords.K_BY) Arrays.asList(java.util.Arrays.asList) DSL.createTable(org.jooq.impl.DSL.createTable) Map(java.util.Map) QualifiedAsterisk(org.jooq.QualifiedAsterisk) SQLDialect(org.jooq.SQLDialect) Scope(org.jooq.Scope) Select(org.jooq.Select) SELECT_START_WITH(org.jooq.Clause.SELECT_START_WITH) DSL.partitionBy(org.jooq.impl.DSL.partitionBy) QueryPartCollectionView.wrap(org.jooq.impl.QueryPartCollectionView.wrap) Tools.isWindow(org.jooq.impl.Tools.isWindow) DataExtendedKey(org.jooq.impl.Tools.DataExtendedKey) DATA_TRANSFORM_ROWNUM_TO_LIMIT(org.jooq.impl.Tools.DataExtendedKey.DATA_TRANSFORM_ROWNUM_TO_LIMIT) TableField(org.jooq.TableField) SUPPORT_NATIVE_EXCEPT(org.jooq.impl.AsteriskImpl.SUPPORT_NATIVE_EXCEPT) DSL.noCondition(org.jooq.impl.DSL.noCondition) K_START_WITH(org.jooq.impl.Keywords.K_START_WITH) DATA_INSERT_SELECT(org.jooq.impl.Tools.BooleanDataKey.DATA_INSERT_SELECT) TRUE(java.lang.Boolean.TRUE) DERBY(org.jooq.SQLDialect.DERBY) EXCEPT_ALL(org.jooq.impl.CombineOperator.EXCEPT_ALL) DATA_RENDER_TRAILING_LIMIT_IF_APPLICABLE(org.jooq.impl.Tools.BooleanDataKey.DATA_RENDER_TRAILING_LIMIT_IF_APPLICABLE) DSL.jsonArrayAgg(org.jooq.impl.DSL.jsonArrayAgg) K_WITH_READ_ONLY(org.jooq.impl.Keywords.K_WITH_READ_ONLY) LinkedHashMap(java.util.LinkedHashMap) K_ORDER_BY(org.jooq.impl.Keywords.K_ORDER_BY) Tools.autoAlias(org.jooq.impl.Tools.autoAlias) INTERSECT(org.jooq.impl.CombineOperator.INTERSECT) VARCHAR(org.jooq.impl.SQLDataType.VARCHAR) XML(org.jooq.impl.SQLDataType.XML) DATA_OMIT_INTO_CLAUSE(org.jooq.impl.Tools.BooleanDataKey.DATA_OMIT_INTO_CLAUSE) DATA_DML_TARGET_TABLE(org.jooq.impl.Tools.DataKey.DATA_DML_TARGET_TABLE) MYSQL(org.jooq.SQLDialect.MYSQL) DATA_COLLECTED_SEMI_ANTI_JOIN(org.jooq.impl.Tools.DataKey.DATA_COLLECTED_SEMI_ANTI_JOIN) K_WITH_CHECK_OPTION(org.jooq.impl.Keywords.K_WITH_CHECK_OPTION) K_FROM(org.jooq.impl.Keywords.K_FROM) Comparator(org.jooq.Comparator) SelectFieldOrAsterisk(org.jooq.SelectFieldOrAsterisk) DSL.jsonbArrayAgg(org.jooq.impl.DSL.jsonbArrayAgg) DATA_COLLECT_SEMI_ANTI_JOIN(org.jooq.impl.Tools.BooleanDataKey.DATA_COLLECT_SEMI_ANTI_JOIN) FIREBIRD(org.jooq.SQLDialect.FIREBIRD) K_WHERE(org.jooq.impl.Keywords.K_WHERE) SELECT(org.jooq.Clause.SELECT) DSL.xmlattributes(org.jooq.impl.DSL.xmlattributes) JoinType(org.jooq.JoinType) IGNITE(org.jooq.SQLDialect.IGNITE) MARIADB(org.jooq.SQLDialect.MARIADB) NO_SUPPORT_ABSENT_ON_NULL(org.jooq.impl.JSONNull.NO_SUPPORT_ABSENT_ON_NULL) K_DISTINCT_ON(org.jooq.impl.Keywords.K_DISTINCT_ON) SelectQuery(org.jooq.SelectQuery) DSL.table(org.jooq.impl.DSL.table) INTERSECT_ALL(org.jooq.impl.CombineOperator.INTERSECT_ALL) Row(org.jooq.Row) IntStream.range(java.util.stream.IntStream.range) SELECT_WINDOW(org.jooq.Clause.SELECT_WINDOW) BiFunction(java.util.function.BiFunction) Table(org.jooq.Table) DSL.rowNumber(org.jooq.impl.DSL.rowNumber) Operator(org.jooq.Operator) ForLockWaitMode(org.jooq.impl.ForLock.ForLockWaitMode) SelectLimitPercentStep(org.jooq.SelectLimitPercentStep) Clause(org.jooq.Clause) SELECT_SELECT(org.jooq.Clause.SELECT_SELECT) NO_SUPPORT_UNQUALIFIED_COMBINED(org.jooq.impl.AsteriskImpl.NO_SUPPORT_UNQUALIFIED_COMBINED) JSONB(org.jooq.impl.SQLDataType.JSONB) DataKey(org.jooq.impl.Tools.DataKey) Tools.aliasedFields(org.jooq.impl.Tools.aliasedFields) SELECT_FROM(org.jooq.Clause.SELECT_FROM) K_TOP(org.jooq.impl.Keywords.K_TOP) GroupField(org.jooq.GroupField) OR(org.jooq.Operator.OR) DataType(org.jooq.DataType) DSL.name(org.jooq.impl.DSL.name) K_HAVING(org.jooq.impl.Keywords.K_HAVING) SELECT_CONNECT_BY(org.jooq.Clause.SELECT_CONNECT_BY) Name(org.jooq.Name) Collection(java.util.Collection) SelectLimitStep(org.jooq.SelectLimitStep) Field(org.jooq.Field) DATA_INSERT_SELECT_WITHOUT_INSERT_COLUMN_LIST(org.jooq.impl.Tools.BooleanDataKey.DATA_INSERT_SELECT_WITHOUT_INSERT_COLUMN_LIST) CUBRID(org.jooq.SQLDialect.CUBRID) SELECT_UNION(org.jooq.Clause.SELECT_UNION) K_QUALIFY(org.jooq.impl.Keywords.K_QUALIFY) EXCEPT(org.jooq.impl.CombineOperator.EXCEPT) K_INTO(org.jooq.impl.Keywords.K_INTO) Tools.containsUnaliasedTable(org.jooq.impl.Tools.containsUnaliasedTable) SelectWithTiesStep(org.jooq.SelectWithTiesStep) JSON(org.jooq.impl.SQLDataType.JSON) Entry(java.util.Map.Entry) K_DISTINCT(org.jooq.impl.Keywords.K_DISTINCT) Tools.anyMatch(org.jooq.impl.Tools.anyMatch) ResultSetMetaData(java.sql.ResultSetMetaData) K_SELECT(org.jooq.impl.Keywords.K_SELECT) K_SIBLINGS(org.jooq.impl.Keywords.K_SIBLINGS) SELECT_HAVING(org.jooq.Clause.SELECT_HAVING) INLINED(org.jooq.conf.ParamType.INLINED) Function(java.util.function.Function) K_CONNECT_BY(org.jooq.impl.Keywords.K_CONNECT_BY) TableLike(org.jooq.TableLike) Tools.fieldArray(org.jooq.impl.Tools.fieldArray) DSL.inline(org.jooq.impl.DSL.inline) K_PERCENT(org.jooq.impl.Keywords.K_PERCENT) SelectHavingStep(org.jooq.SelectHavingStep) DataAccessException(org.jooq.exception.DataAccessException) DATA_NESTED_SET_OPERATIONS(org.jooq.impl.Tools.BooleanDataKey.DATA_NESTED_SET_OPERATIONS) SELECT_INTERSECT(org.jooq.Clause.SELECT_INTERSECT) Consumer(java.util.function.Consumer) SortField(org.jooq.SortField) Multiset.returningClob(org.jooq.impl.Multiset.returningClob) H2(org.jooq.SQLDialect.H2) Tools.unalias(org.jooq.impl.Tools.unalias) K_WINDOW(org.jooq.impl.Keywords.K_WINDOW) Arrays(java.util.Arrays) DSL.orderBy(org.jooq.impl.DSL.orderBy) POSTGRES(org.jooq.SQLDialect.POSTGRES) DATA_UNALIAS_ALIASED_EXPRESSIONS(org.jooq.impl.Tools.BooleanDataKey.DATA_UNALIAS_ALIASED_EXPRESSIONS) JOIN(org.jooq.JoinType.JOIN) Condition(org.jooq.Condition) DSL.trueCondition(org.jooq.impl.DSL.trueCondition) EMULATE_WITH_GROUP_CONCAT(org.jooq.impl.JSONArrayAgg.EMULATE_WITH_GROUP_CONCAT) SelectField(org.jooq.SelectField) Tools.unqualified(org.jooq.impl.Tools.unqualified) CommonTableExpressionList.markTopLevelCteAndAccept(org.jooq.impl.CommonTableExpressionList.markTopLevelCteAndAccept) JSONObjectNullStep(org.jooq.JSONObjectNullStep) K_NOCYCLE(org.jooq.impl.Keywords.K_NOCYCLE) Set(java.util.Set) Tools.camelCase(org.jooq.impl.Tools.camelCase) QueryPart(org.jooq.QueryPart) Tools.traverseJoins(org.jooq.impl.Tools.traverseJoins) SELECT_UNION_ALL(org.jooq.Clause.SELECT_UNION_ALL) Tools.qualify(org.jooq.impl.Tools.qualify) N_LEVEL(org.jooq.impl.Names.N_LEVEL) Materialized(org.jooq.impl.QOM.Materialized) DSL.jsonObject(org.jooq.impl.DSL.jsonObject) K_AND(org.jooq.impl.Keywords.K_AND) DSL.xmlagg(org.jooq.impl.DSL.xmlagg) DATA_SELECT_INTO_TABLE(org.jooq.impl.Tools.DataKey.DATA_SELECT_INTO_TABLE) XML(org.jooq.XML) K_GROUP_BY(org.jooq.impl.Keywords.K_GROUP_BY) CompareCondition(org.jooq.impl.QOM.CompareCondition) DSL.row(org.jooq.impl.DSL.row) DSL.xmlelement(org.jooq.impl.DSL.xmlelement) ArrayList(java.util.ArrayList) Tools.isNotEmpty(org.jooq.impl.Tools.isNotEmpty) SELECT_INTO(org.jooq.Clause.SELECT_INTO) Transformations.transformRownum(org.jooq.impl.Transformations.transformRownum) SQLITE(org.jooq.SQLDialect.SQLITE) SELECT_WHERE(org.jooq.Clause.SELECT_WHERE) Record(org.jooq.Record) RIGHT_OUTER_JOIN(org.jooq.JoinType.RIGHT_OUTER_JOIN) JSONObjectReturningStep(org.jooq.JSONObjectReturningStep) K_MATERIALIZE(org.jooq.impl.Keywords.K_MATERIALIZE) K_ORDER(org.jooq.impl.Keywords.K_ORDER) DATA_TOP_LEVEL_CTE(org.jooq.impl.Tools.DataKey.DATA_TOP_LEVEL_CTE) SELECT_INTERSECT_ALL(org.jooq.Clause.SELECT_INTERSECT_ALL) StringUtils(org.jooq.tools.StringUtils) YUGABYTEDB(org.jooq.SQLDialect.YUGABYTEDB) UNION_ALL(org.jooq.impl.CombineOperator.UNION_ALL) ArrayDeque(java.util.ArrayDeque) ForLockMode(org.jooq.impl.ForLock.ForLockMode) TableOnStep(org.jooq.TableOnStep) Tools.map(org.jooq.impl.Tools.map) WindowDefinition(org.jooq.WindowDefinition) DSL.jsonbObject(org.jooq.impl.DSL.jsonbObject) Transformations.transformQualify(org.jooq.impl.Transformations.transformQualify) SelectOffsetStep(org.jooq.SelectOffsetStep) DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES(org.jooq.impl.Tools.BooleanDataKey.DATA_WRAP_DERIVED_TABLES_IN_PARENTHESES) K_INLINE(org.jooq.impl.Keywords.K_INLINE) DSL.regexpReplaceAll(org.jooq.impl.DSL.regexpReplaceAll) DATA_SELECT_ALIASES(org.jooq.impl.Tools.DataKey.DATA_SELECT_ALIASES) JSONArrayAgg.patchOracleArrayAggBug(org.jooq.impl.JSONArrayAgg.patchOracleArrayAggBug) SELECT_EXCEPT(org.jooq.Clause.SELECT_EXCEPT) DEFAULT(org.jooq.SQLDialect.DEFAULT) Tools.selectQueryImpl(org.jooq.impl.Tools.selectQueryImpl) SELECT_GROUP_BY(org.jooq.Clause.SELECT_GROUP_BY) JooqLogger(org.jooq.tools.JooqLogger) Collections.emptyList(java.util.Collections.emptyList) DSL.falseCondition(org.jooq.impl.DSL.falseCondition) JSONEntry(org.jooq.JSONEntry) DATA_WINDOW_DEFINITIONS(org.jooq.impl.Tools.DataKey.DATA_WINDOW_DEFINITIONS) HSQLDB(org.jooq.SQLDialect.HSQLDB) List(java.util.List) Context(org.jooq.Context) DATA_OVERRIDE_ALIASES_IN_ORDER_BY(org.jooq.impl.Tools.DataKey.DATA_OVERRIDE_ALIASES_IN_ORDER_BY) TablePartitionByStep(org.jooq.TablePartitionByStep) Tools.recordType(org.jooq.impl.Tools.recordType) DSL.key(org.jooq.impl.DSL.key) ForeignKey(org.jooq.ForeignKey) Deque(java.util.Deque) BooleanDataKey(org.jooq.impl.Tools.BooleanDataKey) UNION(org.jooq.impl.CombineOperator.UNION) DSL.asterisk(org.jooq.impl.DSL.asterisk) SELECT_EXCEPT_ALL(org.jooq.Clause.SELECT_EXCEPT_ALL) Tools.hasAmbiguousNames(org.jooq.impl.Tools.hasAmbiguousNames) DSL.unquotedName(org.jooq.impl.DSL.unquotedName) Tools.isEmpty(org.jooq.impl.Tools.isEmpty) DESC(org.jooq.SortOrder.DESC) N_ROWNUM(org.jooq.impl.Names.N_ROWNUM) DSL.one(org.jooq.impl.DSL.one) Configuration(org.jooq.Configuration) TableOptionalOnStep(org.jooq.TableOptionalOnStep) SELECT_ORDER_BY(org.jooq.Clause.SELECT_ORDER_BY) LEFT_OUTER_JOIN(org.jooq.JoinType.LEFT_OUTER_JOIN) DSL.generateSeries(org.jooq.impl.DSL.generateSeries) OrderField(org.jooq.OrderField) Collections(java.util.Collections) TableField(org.jooq.TableField) GroupField(org.jooq.GroupField) Field(org.jooq.Field) SortField(org.jooq.SortField) SelectField(org.jooq.SelectField) OrderField(org.jooq.OrderField) SQLDialect(org.jooq.SQLDialect) DSL.jsonObject(org.jooq.impl.DSL.jsonObject) DSL.jsonbObject(org.jooq.impl.DSL.jsonbObject) Name(org.jooq.Name) DSL.unquotedName(org.jooq.impl.DSL.unquotedName)

Example 5 with Context

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

the class RowInCondition method accept.

@Override
public final void accept(Context<?> ctx) {
    if (EMULATE_IN.contains(ctx.dialect())) {
        Condition result = DSL.or(map(right, r -> new RowCondition(left, r, EQUALS)));
        if (not)
            result = result.not();
        ctx.visit(result);
    } else {
        if (right.size() == 0) {
            if (not)
                ctx.visit(trueCondition());
            else
                ctx.visit(falseCondition());
        } else {
            ctx.visit(left).sql(' ').visit((not ? NOT_IN : IN).toKeyword()).sql(" (").visit(new QueryPartListView<>(AbstractInList.padded(ctx, right))).sql(')');
        }
    }
}
Also used : Condition(org.jooq.Condition) DSL.trueCondition(org.jooq.impl.DSL.trueCondition) DSL.falseCondition(org.jooq.impl.DSL.falseCondition) DERBY(org.jooq.SQLDialect.DERBY) Row(org.jooq.Row) Tools.map(org.jooq.impl.Tools.map) UNotYetImplemented(org.jooq.impl.QOM.UNotYetImplemented) MAX_ROW_DEGREE(org.jooq.Constants.MAX_ROW_DEGREE) Condition(org.jooq.Condition) ArrayList(java.util.ArrayList) DSL.trueCondition(org.jooq.impl.DSL.trueCondition) Clause(org.jooq.Clause) SQLITE(org.jooq.SQLDialect.SQLITE) SQLDialect(org.jooq.SQLDialect) QueryPartInternal(org.jooq.QueryPartInternal) CONDITION_IN(org.jooq.Clause.CONDITION_IN) DSL.falseCondition(org.jooq.impl.DSL.falseCondition) CONDITION(org.jooq.Clause.CONDITION) Set(java.util.Set) Constants(org.jooq.Constants) FIREBIRD(org.jooq.SQLDialect.FIREBIRD) EQUALS(org.jooq.Comparator.EQUALS) Configuration(org.jooq.Configuration) List(java.util.List) Context(org.jooq.Context) NOT_IN(org.jooq.Comparator.NOT_IN) CONDITION_NOT_IN(org.jooq.Clause.CONDITION_NOT_IN) IN(org.jooq.Comparator.IN)

Aggregations

Context (org.jooq.Context)14 Set (java.util.Set)13 SQLDialect (org.jooq.SQLDialect)13 Field (org.jooq.Field)12 Configuration (org.jooq.Configuration)11 List (java.util.List)10 Clause (org.jooq.Clause)10 Collection (java.util.Collection)9 Condition (org.jooq.Condition)9 QueryPart (org.jooq.QueryPart)9 FIREBIRD (org.jooq.SQLDialect.FIREBIRD)9 H2 (org.jooq.SQLDialect.H2)9 Tools.map (org.jooq.impl.Tools.map)9 ArrayList (java.util.ArrayList)8 Arrays (java.util.Arrays)8 Map (java.util.Map)8 Name (org.jooq.Name)8 Record (org.jooq.Record)8 Row (org.jooq.Row)8 DERBY (org.jooq.SQLDialect.DERBY)8