Search in sources :

Example 36 with Condition

use of org.jooq.Condition 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 37 with Condition

use of org.jooq.Condition in project torodb by torodb.

the class AbstractMetaDataWriteInterface method writeMetaInfo.

@Override
public String writeMetaInfo(DSLContext dsl, MetaInfoKey key, String newValue) {
    Condition c = kvTable.KEY.eq(key.getKeyName());
    Optional<String> oldValue = dsl.select(kvTable.VALUE).from(kvTable).where(c).fetchOptional().map(Record1::value1);
    if (oldValue.isPresent()) {
        int updatedRows = dsl.update(kvTable).set(kvTable.KEY, key.getKeyName()).set(kvTable.VALUE, newValue).where(c).execute();
        assert updatedRows == 1;
    } else {
        int newRows = dsl.insertInto(kvTable, kvTable.KEY, kvTable.VALUE).values(key.getKeyName(), newValue).execute();
        assert newRows == 1;
    }
    return oldValue.orElse(null);
}
Also used : Condition(org.jooq.Condition) Record1(org.jooq.Record1)

Example 38 with Condition

use of org.jooq.Condition in project waltz by khartec.

the class PhysicalSpecificationIdSelectorFactory method mkForLogicalFlow.

private Select<Record1<Long>> mkForLogicalFlow(IdSelectionOptions options) {
    ensureScopeIsExact(options);
    long logicalFlowId = options.entityReference().id();
    Condition matchOnLogicalFlowId = PHYSICAL_FLOW.LOGICAL_FLOW_ID.eq(logicalFlowId);
    return selectViaPhysicalFlowJoin(matchOnLogicalFlowId);
}
Also used : Condition(org.jooq.Condition)

Example 39 with Condition

use of org.jooq.Condition in project waltz by khartec.

the class PhysicalSpecificationIdSelectorFactory method mkForPhysicalFlow.

private Select<Record1<Long>> mkForPhysicalFlow(IdSelectionOptions options) {
    ensureScopeIsExact(options);
    long physicalFlowId = options.entityReference().id();
    Condition matchOnPhysFlowId = PHYSICAL_FLOW.ID.eq(physicalFlowId);
    return selectViaPhysicalFlowJoin(matchOnPhysFlowId);
}
Also used : Condition(org.jooq.Condition)

Example 40 with Condition

use of org.jooq.Condition in project waltz by khartec.

the class PhysicalSpecificationIdSelectorFactory method mkForFlowDiagram.

private Select<Record1<Long>> mkForFlowDiagram(IdSelectionOptions options) {
    ensureScopeIsExact(options);
    Select<Record1<Long>> flowSelector = physicalFlowIdSelectorFactory.apply(options);
    Condition condition = PHYSICAL_FLOW.ID.in(flowSelector);
    return selectViaPhysicalFlowJoin(condition);
}
Also used : Condition(org.jooq.Condition) Record1(org.jooq.Record1)

Aggregations

Condition (org.jooq.Condition)47 Field (org.jooq.Field)17 ArrayList (java.util.ArrayList)14 List (java.util.List)11 GroupField (org.jooq.GroupField)11 SortField (org.jooq.SortField)11 TableField (org.jooq.TableField)11 DSLContext (org.jooq.DSLContext)7 Record1 (org.jooq.Record1)7 SearchUtilities.mkTerms (com.khartec.waltz.data.SearchUtilities.mkTerms)6 Collectors (java.util.stream.Collectors)6 DSL (org.jooq.impl.DSL)6 EntitySearchOptions (com.khartec.waltz.model.entity_search.EntitySearchOptions)5 SetUtilities.orderedUnion (com.khartec.waltz.common.SetUtilities.orderedUnion)4 DatabaseVendorSpecific (com.khartec.waltz.data.DatabaseVendorSpecific)4 FullTextSearch (com.khartec.waltz.data.FullTextSearch)4 JooqUtilities (com.khartec.waltz.data.JooqUtilities)4 Collections.emptyList (java.util.Collections.emptyList)4 Record (org.jooq.Record)4 EntityKind (com.khartec.waltz.model.EntityKind)3