Search in sources :

Example 86 with DSLContext

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

the class MeasurablesGenerator method main.

public static void main(String[] args) throws IOException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    generateRegions(dsl);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DSLContext(org.jooq.DSLContext)

Example 87 with DSLContext

use of org.jooq.DSLContext 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 88 with DSLContext

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

the class PhysicalSpecificationGenerator method main.

public static void main(String[] args) {
    ApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<Long> appIds = dsl.select(APPLICATION.ID).from(APPLICATION).fetch(APPLICATION.ID);
    List<PhysicalSpecificationRecord> records = appIds.stream().flatMap(appId -> IntStream.range(0, rnd.nextInt(4)).mapToObj(i -> tuple(appId, i))).map(t -> {
        String name = mkName(t.v2);
        PhysicalSpecificationRecord record = dsl.newRecord(PHYSICAL_SPECIFICATION);
        record.setOwningEntityId(t.v1);
        record.setOwningEntityKind(EntityKind.APPLICATION.name());
        record.setFormat(randomPick(DataFormatKind.values()).name());
        record.setProvenance("DEMO");
        record.setDescription("Desc " + name + " " + t.v2);
        record.setName(name);
        record.setExternalId("ext-" + t.v1 + "." + t.v2);
        record.setLastUpdatedBy("admin");
        return record;
    }).collect(Collectors.toList());
    System.out.println("---deleting old demo records");
    dsl.deleteFrom(PHYSICAL_SPECIFICATION).where(PHYSICAL_SPECIFICATION.PROVENANCE.eq("DEMO")).execute();
    System.out.println("---saving: " + records.size());
    dsl.batchInsert(records).execute();
    System.out.println("---done");
}
Also used : IntStream(java.util.stream.IntStream) PHYSICAL_SPECIFICATION(com.khartec.waltz.schema.tables.PhysicalSpecification.PHYSICAL_SPECIFICATION) ArrayUtilities.randomPick(com.khartec.waltz.common.ArrayUtilities.randomPick) Random(java.util.Random) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) EntityKind(com.khartec.waltz.model.EntityKind) List(java.util.List) DIConfiguration(com.khartec.waltz.service.DIConfiguration) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) PhysicalSpecificationRecord(com.khartec.waltz.schema.tables.records.PhysicalSpecificationRecord) DataFormatKind(com.khartec.waltz.model.physical_specification.DataFormatKind) DSLContext(org.jooq.DSLContext) APPLICATION(com.khartec.waltz.schema.tables.Application.APPLICATION) ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) PhysicalSpecificationRecord(com.khartec.waltz.schema.tables.records.PhysicalSpecificationRecord) DSLContext(org.jooq.DSLContext)

Example 89 with DSLContext

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

the class ProcessGenerator method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    Set<TableRecord<?>> records = new HashSet<>();
    for (long g = 1; g < 5; g++) {
        ProcessRecord record = new ProcessRecord();
        record.setDescription("Process Group: " + g);
        record.setName("Process Group " + g);
        record.setId(g);
        record.setLevel(1);
        record.setLevel_1(g);
        records.add(record);
        for (long p = 0; p < 10; p++) {
            long id = (g * 100) + p;
            ProcessRecord record2 = new ProcessRecord();
            String name = randomPick(p1) + " " + randomPick(p2);
            record2.setDescription("Process: " + name);
            record2.setName(name);
            record2.setId(id);
            record2.setParentId(g);
            record2.setLevel(2);
            record2.setLevel_1(g);
            record2.setLevel_2(id);
            records.add(record2);
        }
    }
    System.out.println("-- deleting");
    dsl.deleteFrom(PROCESS).execute();
    System.out.println("-- inserting");
    dsl.batchInsert(records).execute();
    System.out.println(" -- done");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DSLContext(org.jooq.DSLContext) ProcessRecord(com.khartec.waltz.schema.tables.records.ProcessRecord) TableRecord(org.jooq.TableRecord) HashSet(java.util.HashSet)

Example 90 with DSLContext

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

the class ServerGenerator method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    ServerInformationDao serverDao = ctx.getBean(ServerInformationDao.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    dsl.delete(SERVER_INFORMATION).where(SERVER_INFORMATION.PROVENANCE.eq("RANDOM_GENERATOR")).execute();
    commonHostNames.clear();
    List<ServerInformation> servers = ListUtilities.newArrayList();
    IntStream.range(0, 10_000).forEach(i -> {
        String hostName = mkHostName(i);
        boolean isCommonHost = commonHostNames.contains(hostName);
        servers.add(ImmutableServerInformation.builder().hostname(hostName).environment(isCommonHost ? SampleData.environments[0] : randomPick(SampleData.environments)).location(isCommonHost ? SampleData.locations[0] : randomPick(SampleData.locations)).operatingSystem(isCommonHost ? SampleData.operatingSystems[0] : randomPick(SampleData.operatingSystems)).operatingSystemVersion(isCommonHost ? SampleData.operatingSystemVersions[0] : randomPick(SampleData.operatingSystemVersions)).country("UK").assetCode("wltz-0" + rnd.nextInt(4000)).hardwareEndOfLifeDate(rnd.nextInt(10) > 5 ? Date.valueOf(LocalDate.now().plusMonths(rnd.nextInt(12 * 6) - (12 * 3))) : null).operatingSystemEndOfLifeDate(rnd.nextInt(10) > 5 ? Date.valueOf(LocalDate.now().plusMonths(rnd.nextInt(12 * 6) - (12 * 3))) : null).virtual(isCommonHost || rnd.nextInt(10) > 7).provenance("RANDOM_GENERATOR").lifecycleStatus(randomPick(LifecycleStatus.values())).build());
    });
    // servers.forEach(System.out::println);
    serverDao.bulkSave(servers);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ServerInformationDao(com.khartec.waltz.data.server_information.ServerInformationDao) ServerInformation(com.khartec.waltz.model.server_information.ServerInformation) ImmutableServerInformation(com.khartec.waltz.model.server_information.ImmutableServerInformation) DSLContext(org.jooq.DSLContext)

Aggregations

DSLContext (org.jooq.DSLContext)109 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)55 Connection (java.sql.Connection)23 SQLException (java.sql.SQLException)17 List (java.util.List)17 DIConfiguration (com.khartec.waltz.service.DIConfiguration)14 Collectors (java.util.stream.Collectors)14 EntityKind (com.khartec.waltz.model.EntityKind)11 ArrayList (java.util.ArrayList)9 DSL (org.jooq.impl.DSL)9 EntityReference (com.khartec.waltz.model.EntityReference)8 Timestamp (java.sql.Timestamp)8 Random (java.util.Random)8 IntStream (java.util.stream.IntStream)8 Application (com.khartec.waltz.model.application.Application)7 LogicalFlowDao (com.khartec.waltz.data.logical_flow.LogicalFlowDao)6 OrganisationalUnit (com.khartec.waltz.model.orgunit.OrganisationalUnit)6 Field (org.jooq.Field)6 Record1 (org.jooq.Record1)6 Test (org.junit.Test)6