Search in sources :

Example 16 with Record1

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

the class QuantifiedComparisonCondition method accept0.

@SuppressWarnings({ "unchecked" })
private final void accept0(Context<?> ctx) {
    boolean quantifiedArray = query.array instanceof Param<?>;
    boolean emulateOperator;
    switch(comparator) {
        case LIKE:
        case NOT_LIKE:
        case LIKE_IGNORE_CASE:
        case NOT_LIKE_IGNORE_CASE:
            emulateOperator = escape != null || NO_SUPPORT_QUANTIFIED_LIKE.contains(ctx.dialect());
            break;
        case SIMILAR_TO:
        case NOT_SIMILAR_TO:
            emulateOperator = escape != null || NO_SUPPORT_QUANTIFIED_SIMILAR_TO.contains(ctx.dialect());
            break;
        default:
            emulateOperator = false;
            break;
    }
    // arrays, such as x = any(?::int[]) in PostgreSQL
    if (quantifiedArray && SUPPORTS_QUANTIFIED_ARRAYS.contains(ctx.dialect()) && !emulateOperator) {
        accept1(ctx);
    } else if (query.values != null || quantifiedArray) {
        ctx.visit(DSL.condition(query.quantifier == Quantifier.ALL ? Operator.AND : Operator.OR, query.values != null ? map(query.values, v -> comparisonCondition(comparator, (Field<String>) v)) : map(((Param<? extends Object[]>) query.array).getValue(), v -> v instanceof Field ? comparisonCondition(comparator, (Field<String>) v) : comparisonCondition(comparator, v))));
    } else if ((query.array != null || query.query != null) && emulateOperator) {
        Field<String> pattern = DSL.field(name("pattern"), VARCHAR);
        Condition cond;
        Field<Boolean> lhs;
        switch(comparator) {
            case NOT_LIKE:
            case NOT_SIMILAR_TO:
            case NOT_LIKE_IGNORE_CASE:
                cond = comparisonCondition(inverse(comparator), pattern);
                lhs = inline(false);
                break;
            case LIKE:
            case SIMILAR_TO:
            case LIKE_IGNORE_CASE:
                cond = comparisonCondition(comparator, pattern);
                lhs = inline(true);
                break;
            default:
                throw new IllegalStateException();
        }
        Table<?> t = query.array != null ? new ArrayTable(query.array).asTable("t", "pattern") : new AliasedSelect<>(query.query, true, true, name("pattern")).as("t");
        Select<Record1<Boolean>> select = select(DSL.field(cond)).from(t);
        ctx.visit(lhs.eq(query.quantifier.apply(select)));
    } else {
        accept1(ctx);
    }
}
Also used : Condition(org.jooq.Condition) Field(org.jooq.Field) Param(org.jooq.Param) Record1(org.jooq.Record1)

Example 17 with Record1

use of org.jooq.Record1 in project zipkin by openzipkin.

the class AggregateDependencies method apply.

@Override
public List<DependencyLink> apply(DSLContext context) {
    // Subquery on trace IDs to prevent only matching the part of the trace that exists within
    // the interval: we want all of the trace.
    SelectConditionStep<Record1<Long>> traceIDs = context.selectDistinct(ZIPKIN_SPANS.TRACE_ID).from(ZIPKIN_SPANS).where(startTsBegin == startTsEnd ? ZIPKIN_SPANS.START_TS.lessOrEqual(startTsEnd) : ZIPKIN_SPANS.START_TS.between(startTsBegin, startTsEnd));
    // Lazy fetching the cursor prevents us from buffering the whole dataset in memory.
    Cursor<Record> cursor = context.selectDistinct(schema.dependencyLinkerFields).from(ZIPKIN_SPANS.leftJoin(ZIPKIN_ANNOTATIONS).on(ZIPKIN_SPANS.TRACE_ID.eq(ZIPKIN_ANNOTATIONS.TRACE_ID).and(ZIPKIN_SPANS.ID.eq(ZIPKIN_ANNOTATIONS.SPAN_ID))).and(ZIPKIN_ANNOTATIONS.A_KEY.in("lc", "cs", "ca", "sr", "sa", "ma", "mr", "ms", "error"))).where(ZIPKIN_SPANS.TRACE_ID.in(traceIDs)).groupBy(schema.dependencyLinkerGroupByFields).fetchLazy();
    Iterator<Iterator<Span>> traces = new DependencyLinkV2SpanIterator.ByTraceId(cursor.iterator(), schema.hasTraceIdHigh);
    if (!traces.hasNext())
        return Collections.emptyList();
    DependencyLinker linker = new DependencyLinker();
    List<Span> nextTrace = new ArrayList<>();
    while (traces.hasNext()) {
        Iterator<Span> i = traces.next();
        while (i.hasNext()) nextTrace.add(i.next());
        linker.putTrace(nextTrace);
        nextTrace.clear();
    }
    return linker.link();
}
Also used : DependencyLinker(zipkin2.internal.DependencyLinker) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) Record(org.jooq.Record) Span(zipkin2.Span) Record1(org.jooq.Record1)

Example 18 with Record1

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

the class FlowDiagramService method makeForPhysicalSpecification.

private Long makeForPhysicalSpecification(EntityReference ref, String userId, String providedTitle) {
    PhysicalSpecification spec = physicalSpecificationDao.getById(ref.id());
    Select<Record1<Long>> logicalFlowSelector = logicalFlowIdSelectorFactory.apply(mkOpts(ref, HierarchyQueryScope.EXACT));
    List<LogicalFlow> logicalFlows = logicalFlowDao.findBySelector(logicalFlowSelector);
    List<PhysicalFlow> physicalFlows = physicalFlowDao.findBySpecificationId(ref.id());
    List<EntityReference> nodes = logicalFlows.stream().flatMap(f -> Stream.of(f.source(), f.target())).distinct().collect(toList());
    List<FlowDiagramEntity> entities = ListUtilities.concat(map(logicalFlows, d -> mkDiagramEntity(d)), map(physicalFlows, d -> mkDiagramEntity(d)), newArrayList(mkDiagramEntity(spec)), map(nodes, d -> mkDiagramEntity(d)));
    String title = isEmpty(providedTitle) ? spec.name() + " flows" : providedTitle;
    return mkNewFlowDiagram(title, userId, entities, emptyList());
}
Also used : ChangeInitiative(org.finos.waltz.model.change_initiative.ChangeInitiative) LogicalFlowDao(org.finos.waltz.data.logical_flow.LogicalFlowDao) org.finos.waltz.model(org.finos.waltz.model) Autowired(org.springframework.beans.factory.annotation.Autowired) ListUtilities.newArrayList(org.finos.waltz.common.ListUtilities.newArrayList) ImmutableChangeLog(org.finos.waltz.model.changelog.ImmutableChangeLog) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow) StringUtilities.isEmpty(org.finos.waltz.common.StringUtilities.isEmpty) EntityReference.mkRef(org.finos.waltz.model.EntityReference.mkRef) Measurable(org.finos.waltz.model.measurable.Measurable) Record1(org.jooq.Record1) FlowDiagramDao(org.finos.waltz.data.flow_diagram.FlowDiagramDao) Select(org.jooq.Select) org.finos.waltz.model.flow_diagram(org.finos.waltz.model.flow_diagram) ChangeInitiativeDao(org.finos.waltz.data.change_initiative.ChangeInitiativeDao) MeasurableDao(org.finos.waltz.data.measurable.MeasurableDao) Collections.emptyList(java.util.Collections.emptyList) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) ApplicationDao(org.finos.waltz.data.application.ApplicationDao) ListUtilities.map(org.finos.waltz.common.ListUtilities.map) Stream(java.util.stream.Stream) DateTimeUtilities.nowUtc(org.finos.waltz.common.DateTimeUtilities.nowUtc) SetUtilities(org.finos.waltz.common.SetUtilities) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) Actor(org.finos.waltz.model.actor.Actor) java.util(java.util) FlowDiagramAnnotationDao(org.finos.waltz.data.flow_diagram.FlowDiagramAnnotationDao) PhysicalFlowDao(org.finos.waltz.data.physical_flow.PhysicalFlowDao) EntitySearchOptions(org.finos.waltz.model.entity_search.EntitySearchOptions) DataType(org.finos.waltz.model.datatype.DataType) ChangeLog(org.finos.waltz.model.changelog.ChangeLog) Service(org.springframework.stereotype.Service) PhysicalSpecificationDao(org.finos.waltz.data.physical_specification.PhysicalSpecificationDao) DataTypeService(org.finos.waltz.service.data_type.DataTypeService) ChangeLogService(org.finos.waltz.service.changelog.ChangeLogService) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) Application(org.finos.waltz.model.application.Application) IdSelectionOptions.mkOpts(org.finos.waltz.model.IdSelectionOptions.mkOpts) FlowDiagramEntityDao(org.finos.waltz.data.flow_diagram.FlowDiagramEntityDao) FLOW_DIAGRAM(org.finos.waltz.model.EntityKind.FLOW_DIAGRAM) RandomUtilities(org.finos.waltz.common.RandomUtilities) LogicalFlowIdSelectorFactory(org.finos.waltz.data.logical_flow.LogicalFlowIdSelectorFactory) Collectors.toList(java.util.stream.Collectors.toList) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) ActorDao(org.finos.waltz.data.actor.ActorDao) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) ListUtilities(org.finos.waltz.common.ListUtilities) FlowDiagramIdSelectorFactory(org.finos.waltz.data.flow_diagram.FlowDiagramIdSelectorFactory) InvalidResultException(org.jooq.exception.InvalidResultException) PhysicalSpecification(org.finos.waltz.model.physical_specification.PhysicalSpecification) LogicalFlow(org.finos.waltz.model.logical_flow.LogicalFlow) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow) Record1(org.jooq.Record1)

Example 19 with Record1

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

the class FacetService method getApplicationKindTallies.

public List<Tally<String>> getApplicationKindTallies(IdSelectionOptions options) {
    // we don't want the facets to apply and filter out non selected kinds, so we default to all kinds
    IdSelectionOptions appOptions = mkOpts(options.entityReference(), options.scope());
    Select<Record1<Long>> appSelector = applicationIdSelectorFactory.apply(appOptions);
    return applicationDao.countByApplicationKind(appSelector);
}
Also used : IdSelectionOptions(org.finos.waltz.model.IdSelectionOptions) Record1(org.jooq.Record1)

Example 20 with Record1

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

the class ChangeUnitIdSelectorFactory method mkByAppSelector.

private Select<Record1<Long>> mkByAppSelector(IdSelectionOptions options) {
    Select<Record1<Long>> appSelector = applicationIdSelectorFactory.apply(options);
    Condition sourceRef = LOGICAL_FLOW.SOURCE_ENTITY_KIND.eq(EntityKind.APPLICATION.name()).and(LOGICAL_FLOW.SOURCE_ENTITY_ID.in(appSelector));
    Condition targetRef = LOGICAL_FLOW.TARGET_ENTITY_KIND.eq(EntityKind.APPLICATION.name()).and(LOGICAL_FLOW.TARGET_ENTITY_ID.in(appSelector));
    return DSL.select(CHANGE_UNIT.ID).from(CHANGE_UNIT).innerJoin(PHYSICAL_FLOW).on(PHYSICAL_FLOW.ID.eq(CHANGE_UNIT.SUBJECT_ENTITY_ID).and(CHANGE_UNIT.SUBJECT_ENTITY_KIND.eq(EntityKind.PHYSICAL_FLOW.name()))).innerJoin(LOGICAL_FLOW).on(LOGICAL_FLOW.ID.eq(PHYSICAL_FLOW.LOGICAL_FLOW_ID)).where(sourceRef.or(targetRef));
}
Also used : Condition(org.jooq.Condition) Record1(org.jooq.Record1)

Aggregations

Record1 (org.jooq.Record1)58 Condition (org.jooq.Condition)22 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)16 DSLContext (org.jooq.DSLContext)14 Select (org.jooq.Select)10 ApplicationIdSelectorFactory (org.finos.waltz.data.application.ApplicationIdSelectorFactory)9 EntityReference (org.finos.waltz.model.EntityReference)8 IdSelectionOptions (org.finos.waltz.model.IdSelectionOptions)8 Record (org.jooq.Record)7 IdSelectionOptions (com.khartec.waltz.model.IdSelectionOptions)5 EntityKind (org.finos.waltz.model.EntityKind)5 EntityReference (com.khartec.waltz.model.EntityReference)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 LogicalFlowDao (org.finos.waltz.data.logical_flow.LogicalFlowDao)4 EntityReference.mkRef (org.finos.waltz.model.EntityReference.mkRef)4 LogicalFlow (org.finos.waltz.model.logical_flow.LogicalFlow)4 DSL (org.jooq.impl.DSL)4 java.util (java.util)3 ArrayList (java.util.ArrayList)3