Search in sources :

Example 36 with Record1

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

the class ChangeInitiativeHarness method main.

public static void main(String[] args) throws ParseException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    ChangeInitiativeDao dao = ctx.getBean(ChangeInitiativeDao.class);
    ChangeInitiative changeInitiative = dao.getById(1L);
    System.out.println(changeInitiative);
    SelectConditionStep<Record1<Long>> ouHier = dsl.selectDistinct(ENTITY_HIERARCHY.ANCESTOR_ID).from(ENTITY_HIERARCHY).where(ENTITY_HIERARCHY.ID.eq(210L).and(ENTITY_HIERARCHY.KIND.eq(EntityKind.ORG_UNIT.name())));
    SelectConditionStep<Record1<Long>> baseIdSelector = dsl.selectDistinct(CHANGE_INITIATIVE.ID).from(CHANGE_INITIATIVE).where(CHANGE_INITIATIVE.ORGANISATIONAL_UNIT_ID.in(ouHier));
    SelectConditionStep<Record1<Long>> ciHier = dsl.selectDistinct(ENTITY_HIERARCHY.ANCESTOR_ID).from(ENTITY_HIERARCHY).where(ENTITY_HIERARCHY.ID.in(baseIdSelector).and(ENTITY_HIERARCHY.KIND.eq(EntityKind.CHANGE_INITIATIVE.name())));
    dsl.select(CHANGE_INITIATIVE.NAME).from(CHANGE_INITIATIVE).where(CHANGE_INITIATIVE.ID.in(ciHier)).forEach(System.out::println);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ChangeInitiativeDao(com.khartec.waltz.data.change_initiative.ChangeInitiativeDao) ChangeInitiative(com.khartec.waltz.model.change_initiative.ChangeInitiative) DSLContext(org.jooq.DSLContext) Record1(org.jooq.Record1)

Example 37 with Record1

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

the class DataFlowHarness method main.

public static void main(String[] args) throws ParseException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    LogicalFlowService service = ctx.getBean(LogicalFlowService.class);
    LogicalFlowDao dao = ctx.getBean(LogicalFlowDao.class);
    LogicalFlowIdSelectorFactory factory = ctx.getBean(LogicalFlowIdSelectorFactory.class);
    IdSelectionOptions options = IdSelectionOptions.mkOpts(EntityReference.mkRef(EntityKind.ORG_UNIT, 5000), HierarchyQueryScope.CHILDREN);
    Select<Record1<Long>> selector = factory.apply(options);
    System.out.println(selector);
    List<LogicalFlow> flows = dao.findBySelector(selector);
    flows.forEach(System.out::println);
    // by data type
    EntityReference dataType = EntityReference.mkRef(EntityKind.DATA_TYPE, 6000);
    IdSelectionOptions dataTypeOptions = IdSelectionOptions.mkOpts(dataType, HierarchyQueryScope.CHILDREN);
    List<LogicalFlow> byDataTypeFlows = service.findBySelector(dataTypeOptions);
    byDataTypeFlows.forEach(System.out::println);
    System.out.println(byDataTypeFlows.size());
}
Also used : LogicalFlowIdSelectorFactory(com.khartec.waltz.data.logical_flow.LogicalFlowIdSelectorFactory) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) LogicalFlowService(com.khartec.waltz.service.logical_flow.LogicalFlowService) LogicalFlow(com.khartec.waltz.model.logical_flow.LogicalFlow) EntityReference(com.khartec.waltz.model.EntityReference) DSLContext(org.jooq.DSLContext) LogicalFlowDao(com.khartec.waltz.data.logical_flow.LogicalFlowDao) IdSelectionOptions(com.khartec.waltz.model.IdSelectionOptions) Record1(org.jooq.Record1)

Example 38 with Record1

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

the class EndUserAppIdSelectorFactory method mkForOrgUnit.

@Override
protected Select<Record1<Long>> mkForOrgUnit(EntityReference ref, HierarchyQueryScope scope) {
    IdSelectionOptions ouSelectorOptions = ImmutableIdSelectionOptions.builder().entityReference(ref).scope(scope).build();
    Select<Record1<Long>> ouSelector = orgUnitIdSelectorFactory.apply(ouSelectorOptions);
    return dsl.selectDistinct(eua.ID).from(eua).where(dsl.renderInlined(eua.ORGANISATIONAL_UNIT_ID.in(ouSelector)));
}
Also used : ImmutableIdSelectionOptions(com.khartec.waltz.model.ImmutableIdSelectionOptions) IdSelectionOptions(com.khartec.waltz.model.IdSelectionOptions) Record1(org.jooq.Record1)

Example 39 with Record1

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

the class LogicalFlowIdSelectorFactory method wrapAppIdSelector.

private Select<Record1<Long>> wrapAppIdSelector(IdSelectionOptions options) {
    Select<Record1<Long>> appIdSelector = applicationIdSelectorFactory.apply(options);
    Condition sourceCondition = LOGICAL_FLOW.SOURCE_ENTITY_ID.in(appIdSelector).and(LOGICAL_FLOW.SOURCE_ENTITY_KIND.eq(EntityKind.APPLICATION.name()));
    Condition targetCondition = LOGICAL_FLOW.TARGET_ENTITY_ID.in(appIdSelector).and(LOGICAL_FLOW.TARGET_ENTITY_KIND.eq(EntityKind.APPLICATION.name()));
    return DSL.select(LOGICAL_FLOW.ID).from(LOGICAL_FLOW).where(sourceCondition.or(targetCondition)).and(NOT_REMOVED);
}
Also used : Condition(org.jooq.Condition) Record1(org.jooq.Record1)

Example 40 with Record1

use of org.jooq.Record1 in project steve by RWTH-i5-IDSG.

the class OcppServerRepositoryImpl method insertTransaction.

@Override
public Integer insertTransaction(InsertTransactionParams p) {
    return ctx.transactionResult(configuration -> {
        DSLContext ctx = DSL.using(configuration);
        insertIgnoreConnector(ctx, p.getChargeBoxId(), p.getConnectorId());
        // it is important to insert idTag before transaction, since the transaction table references it
        boolean unknownTagInserted = insertIgnoreIdTag(ctx, p);
        SelectConditionStep<Record1<Integer>> connectorPkQuery = DSL.select(CONNECTOR.CONNECTOR_PK).from(CONNECTOR).where(CONNECTOR.CHARGE_BOX_ID.equal(p.getChargeBoxId())).and(CONNECTOR.CONNECTOR_ID.equal(p.getConnectorId()));
        // -------------------------------------------------------------------------
        // Step 1: Insert transaction
        // -------------------------------------------------------------------------
        int transactionId = ctx.insertInto(TRANSACTION).set(CONNECTOR_STATUS.CONNECTOR_PK, connectorPkQuery).set(TRANSACTION.ID_TAG, p.getIdTag()).set(TRANSACTION.START_TIMESTAMP, p.getStartTimestamp()).set(TRANSACTION.START_VALUE, p.getStartMeterValue()).returning(TRANSACTION.TRANSACTION_PK).fetchOne().getTransactionPk();
        if (unknownTagInserted) {
            log.warn("The transaction '{}' contains an unknown idTag '{}' which was inserted into DB " + "to prevent information loss and has been blocked", transactionId, p.getIdTag());
        }
        if (p.isSetReservationId()) {
            reservationRepository.used(ctx, connectorPkQuery, p.getIdTag(), p.getReservationId(), transactionId);
        }
        // -------------------------------------------------------------------------
        // Step 3: Set connector status to "Occupied"
        // -------------------------------------------------------------------------
        insertConnectorStatus(ctx, connectorPkQuery, p.getStartTimestamp(), p.getStatusUpdate());
        return transactionId;
    });
}
Also used : DSLContext(org.jooq.DSLContext) 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