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");
}
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();
}
Aggregations