use of org.finos.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().value());
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(Timestamp::valueOf).orElse(null));
record.setIsRemoved(flow.isRemoved());
record.setProvenance("waltz");
record.setExternalId(flow.externalId().orElse(null));
record.setCreatedAt(flow.created().map(UserTimestamp::atTimestamp).orElse(Timestamp.valueOf(flow.lastUpdatedAt())));
record.setCreatedBy(flow.created().map(UserTimestamp::by).orElse(flow.lastUpdatedBy()));
record.store();
return record.getId();
}
use of org.finos.waltz.schema.tables.records.PhysicalFlowRecord in project waltz by khartec.
the class PhysicalFlowGenerator method create.
@Override
public Map<String, Integer> create(ApplicationContext ctx) {
DSLContext dsl = getDsl(ctx);
List<PhysicalSpecification> specifications = dsl.select(PHYSICAL_SPECIFICATION.fields()).select(owningEntityNameField).from(PHYSICAL_SPECIFICATION).fetch(PhysicalSpecificationDao.TO_DOMAIN_MAPPER);
List<String> transportKinds = dsl.select(ENUM_VALUE.KEY).from(ENUM_VALUE).where(ENUM_VALUE.TYPE.eq(EnumValueKind.TRANSPORT_KIND.dbValue())).fetch(ENUM_VALUE.KEY);
List<Tuple3<Long, Long, Long>> allLogicalFLows = dsl.select(LOGICAL_FLOW.ID, LOGICAL_FLOW.SOURCE_ENTITY_ID, LOGICAL_FLOW.TARGET_ENTITY_ID).from(LOGICAL_FLOW).fetch(r -> Tuple.tuple(r.getValue(LOGICAL_FLOW.ID), r.getValue(LOGICAL_FLOW.SOURCE_ENTITY_ID), r.getValue(LOGICAL_FLOW.TARGET_ENTITY_ID)));
Map<Long, Collection<Long>> logicalFlowIdsBySourceApp = groupBy(t -> t.v2(), t -> t.v1(), allLogicalFLows);
final int flowBatchSize = 100000;
List<PhysicalFlowRecord> flowBatch = new ArrayList<PhysicalFlowRecord>((int) (flowBatchSize * 1.2));
for (PhysicalSpecification spec : specifications) {
Collection<Long> relatedLogicalFlowsIds = logicalFlowIdsBySourceApp.get(spec.owningEntity().id());
if (!isEmpty(relatedLogicalFlowsIds)) {
List<PhysicalFlowRecord> physicalFlowRecords = mkPhysicalFlowRecords(spec, new LinkedList<>(relatedLogicalFlowsIds), transportKinds);
flowBatch.addAll(physicalFlowRecords);
}
if (flowBatch.size() >= flowBatchSize) {
log(String.format("--- saving records: count: %s", flowBatch.size()));
dsl.batchInsert(flowBatch).execute();
flowBatch.clear();
}
}
log(String.format("--- saving records: count: %s", flowBatch.size()));
dsl.batchInsert(flowBatch).execute();
flowBatch.clear();
log("---done");
return null;
}
Aggregations