Search in sources :

Example 1 with PhysicalFlowRecord

use of com.khartec.waltz.schema.tables.records.PhysicalFlowRecord in project waltz by khartec.

the class PhysicalFlowGenerator method main.

public static void main(String[] args) {
    ApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<PhysicalSpecification> specifications = dsl.select(PHYSICAL_SPECIFICATION.fields()).select(owningEntityNameField).from(PHYSICAL_SPECIFICATION).fetch(PhysicalSpecificationDao.TO_DOMAIN_MAPPER);
    List<Tuple2<Long, EntityReference>> allLogicalFLows = dsl.select(LOGICAL_FLOW.ID, LOGICAL_FLOW.SOURCE_ENTITY_ID, LOGICAL_FLOW.SOURCE_ENTITY_KIND).from(LOGICAL_FLOW).fetch(r -> Tuple.tuple(r.getValue(LOGICAL_FLOW.ID), mkRef(EntityKind.valueOf(r.getValue(LOGICAL_FLOW.SOURCE_ENTITY_KIND)), r.getValue(LOGICAL_FLOW.SOURCE_ENTITY_ID))));
    Map<EntityReference, Collection<Long>> flowIdsBySource = groupBy(t -> t.v2(), t -> t.v1(), allLogicalFLows);
    System.out.println("---removing demo records");
    dsl.deleteFrom(PHYSICAL_FLOW).where(PHYSICAL_FLOW.PROVENANCE.eq(provenance)).execute();
    final int flowBatchSize = 100000;
    List<PhysicalFlowRecord> flowBatch = new ArrayList<PhysicalFlowRecord>((int) (flowBatchSize * 1.2));
    for (PhysicalSpecification spec : specifications) {
        Collection<Long> flowIds = flowIdsBySource.get(spec.owningEntity());
        if (!isEmpty(flowIds)) {
            List<PhysicalFlowRecord> physicalFlowRecords = mkPhysicalFlowRecords(spec, new LinkedList<>(flowIds));
            flowBatch.addAll(physicalFlowRecords);
        }
        if (flowBatch.size() >= flowBatchSize) {
            System.out.println(String.format("--- saving records: count: %s", flowBatch.size()));
            dsl.batchInsert(flowBatch).execute();
            flowBatch.clear();
        }
    }
    System.out.println(String.format("--- saving records: count: %s", flowBatch.size()));
    dsl.batchInsert(flowBatch).execute();
    flowBatch.clear();
    System.out.println("---done");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PhysicalSpecification(com.khartec.waltz.model.physical_specification.PhysicalSpecification) PhysicalFlowRecord(com.khartec.waltz.schema.tables.records.PhysicalFlowRecord) ListUtilities.newArrayList(com.khartec.waltz.common.ListUtilities.newArrayList) DSLContext(org.jooq.DSLContext) ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Tuple2(org.jooq.lambda.tuple.Tuple2) EntityReference(com.khartec.waltz.model.EntityReference)

Example 2 with PhysicalFlowRecord

use of com.khartec.waltz.schema.tables.records.PhysicalFlowRecord in project waltz by khartec.

the class PhysicalFlowDao method create.

public long create(PhysicalFlow flow) {
    checkNotNull(flow, "flow cannot be null");
    checkFalse(flow.id().isPresent(), "flow must not have an id");
    PhysicalFlowRecord record = dsl.newRecord(PHYSICAL_FLOW);
    record.setLogicalFlowId(flow.logicalFlowId());
    record.setFrequency(flow.frequency().name());
    record.setTransport(flow.transport().name());
    record.setBasisOffset(flow.basisOffset());
    record.setCriticality(flow.criticality().name());
    record.setSpecificationId(flow.specificationId());
    record.setDescription(flow.description());
    record.setLastUpdatedBy(flow.lastUpdatedBy());
    record.setLastUpdatedAt(Timestamp.valueOf(flow.lastUpdatedAt()));
    record.setLastAttestedBy(flow.lastAttestedBy().orElse(null));
    record.setLastAttestedAt(flow.lastAttestedAt().map(ldt -> Timestamp.valueOf(ldt)).orElse(null));
    record.setIsRemoved(flow.isRemoved());
    record.setProvenance("waltz");
    record.store();
    return record.getId();
}
Also used : PhysicalFlowRecord(com.khartec.waltz.schema.tables.records.PhysicalFlowRecord)

Aggregations

PhysicalFlowRecord (com.khartec.waltz.schema.tables.records.PhysicalFlowRecord)2 ListUtilities.newArrayList (com.khartec.waltz.common.ListUtilities.newArrayList)1 EntityReference (com.khartec.waltz.model.EntityReference)1 PhysicalSpecification (com.khartec.waltz.model.physical_specification.PhysicalSpecification)1 DSLContext (org.jooq.DSLContext)1 Tuple2 (org.jooq.lambda.tuple.Tuple2)1 ApplicationContext (org.springframework.context.ApplicationContext)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1