Search in sources :

Example 81 with DSLContext

use of org.jooq.DSLContext in project Skree by Skelril.

the class RegionManager method writeRemRegion.

private void writeRemRegion(Collection<RegionDatabaseHandle> oldRegions) {
    try (Connection con = SQLHandle.getConnection()) {
        DSLContext create = DSL.using(con);
        con.setAutoCommit(false);
        for (RegionDatabaseHandle region : oldRegions) {
            create.deleteFrom(REGIONS).where(REGIONS.UUID.equal(region.getID().toString())).execute();
        }
        con.commit();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) DSLContext(org.jooq.DSLContext)

Example 82 with DSLContext

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

the class EndUserAppMaker method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    OrganisationalUnitDao organisationalUnitDao = ctx.getBean(OrganisationalUnitDao.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<Long> ids = IdUtilities.toIds(organisationalUnitDao.findAll());
    String[] subjects = { "Trade", "Risk", "Balance", "PnL", "Rate", "Fines", "Party", "Confirmations", "Settlement", "Instruction", "Person", "Profit", "Margin", "Finance", "Account" };
    String[] types = { "Report", "Summary", "Draft", "Calculations", "Breaks", "Record", "Statement", "Information", "Pivot" };
    String[] tech = { "MS ACCESS", "MS EXCEL", "VBA" };
    dsl.delete(END_USER_APPLICATION).execute();
    final Long[] idCounter = { 1L };
    ids.forEach(ouId -> {
        for (int i = 0; i < new Random().nextInt(100) + 40; i++) {
            EndUserApplicationRecord record = dsl.newRecord(END_USER_APPLICATION);
            String name = new StringBuilder().append(randomPick(subjects)).append(" ").append(randomPick(subjects)).append(" ").append(randomPick(types)).append(" ").append(randomPick(types)).toString();
            record.setName(name);
            record.setDescription("About the " + name + " End user app");
            record.setKind(randomPick(tech));
            record.setRiskRating(randomPick(Criticality.values()).name());
            record.setLifecyclePhase(randomPick(LifecyclePhase.values()).name());
            record.setOrganisationalUnitId(ouId);
            record.setId(idCounter[0]++);
            record.insert();
        }
    });
}
Also used : OrganisationalUnitDao(com.khartec.waltz.data.orgunit.OrganisationalUnitDao) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Random(java.util.Random) DSLContext(org.jooq.DSLContext) EndUserApplicationRecord(com.khartec.waltz.schema.tables.records.EndUserApplicationRecord)

Example 83 with DSLContext

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

the class FlowDecorationGenerator method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<Long> flowIds = dsl.select(LOGICAL_FLOW.ID).from(LOGICAL_FLOW).fetch(LOGICAL_FLOW.ID);
    List<Long> typeIds = dsl.select(DATA_TYPE.ID).from(DATA_TYPE).fetch(DATA_TYPE.ID);
    List<LogicalFlowDecoratorRecord> records = map(flowIds, id -> {
        LogicalFlowDecoratorRecord record = dsl.newRecord(LOGICAL_FLOW_DECORATOR);
        record.setLogicalFlowId(id);
        record.setDecoratorEntityId(randomPick(typeIds));
        record.setDecoratorEntityKind(EntityKind.DATA_TYPE.name());
        record.setProvenance("sample");
        return record;
    });
    dsl.deleteFrom(LOGICAL_FLOW_DECORATOR).where(LOGICAL_FLOW_DECORATOR.PROVENANCE.eq("sample")).execute();
    System.out.println("--- saving: " + records.size());
    dsl.batchStore(records).execute();
    System.out.println("--- done");
}
Also used : LogicalFlowDecoratorRecord(com.khartec.waltz.schema.tables.records.LogicalFlowDecoratorRecord) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DSLContext(org.jooq.DSLContext)

Example 84 with DSLContext

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

the class FlowGenerator method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    AuthoritativeSourceDao authSourceDao = ctx.getBean(AuthoritativeSourceDao.class);
    ApplicationService applicationDao = ctx.getBean(ApplicationService.class);
    LogicalFlowService dataFlowDao = ctx.getBean(LogicalFlowService.class);
    OrganisationalUnitService orgUnitDao = ctx.getBean(OrganisationalUnitService.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<AuthoritativeSource> authSources = authSourceDao.findByEntityKind(EntityKind.ORG_UNIT);
    List<Application> apps = applicationDao.findAll();
    List<OrganisationalUnit> orgUnits = orgUnitDao.findAll();
    Set<LogicalFlow> expectedFlows = authSources.stream().flatMap(a -> {
        long orgUnitId = a.parentReference().id();
        return IntStream.range(0, rnd.nextInt(40)).mapToObj(i -> ImmutableLogicalFlow.builder().source(a.applicationReference()).target(randomAppPick(apps, orgUnitId)).build());
    }).collect(toSet());
    Set<LogicalFlow> probableFlows = authSources.stream().flatMap(a -> IntStream.range(0, rnd.nextInt(30)).mapToObj(i -> ImmutableLogicalFlow.builder().source(a.applicationReference()).target(randomAppPick(apps, randomPick(orgUnits).id().get())).build())).collect(toSet());
    Set<LogicalFlow> randomFlows = apps.stream().flatMap(a -> IntStream.range(0, rnd.nextInt(5)).mapToObj(i -> {
        EntityReference target = randomAppPick(apps, randomPick(orgUnits).id().get());
        return ImmutableLogicalFlow.builder().source(a.entityReference()).target(target).lastUpdatedBy("admin").build();
    })).collect(toSet());
    dsl.deleteFrom(LOGICAL_FLOW).execute();
    Set<LogicalFlow> all = new HashSet<>();
    all.addAll(randomFlows);
    all.addAll(expectedFlows);
    all.addAll(probableFlows);
    System.out.println("--- saving: " + all.size());
    Set<LogicalFlowRecord> records = SetUtilities.map(all, df -> LogicalFlowDao.TO_RECORD_MAPPER.apply(df, dsl));
    dsl.batchStore(records).execute();
    System.out.println("--- done");
}
Also used : OrganisationalUnitService(com.khartec.waltz.service.orgunit.OrganisationalUnitService) IntStream(java.util.stream.IntStream) AuthoritativeSource(com.khartec.waltz.model.authoritativesource.AuthoritativeSource) SetUtilities(com.khartec.waltz.common.SetUtilities) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit) EntityReference(com.khartec.waltz.model.EntityReference) Random(java.util.Random) LogicalFlow(com.khartec.waltz.model.logical_flow.LogicalFlow) EntityKind(com.khartec.waltz.model.EntityKind) HashSet(java.util.HashSet) ImmutableLogicalFlow(com.khartec.waltz.model.logical_flow.ImmutableLogicalFlow) DIConfiguration(com.khartec.waltz.service.DIConfiguration) OrganisationalUnitService(com.khartec.waltz.service.orgunit.OrganisationalUnitService) LogicalFlowDao(com.khartec.waltz.data.logical_flow.LogicalFlowDao) DSLContext(org.jooq.DSLContext) ApplicationService(com.khartec.waltz.service.application.ApplicationService) LogicalFlowRecord(com.khartec.waltz.schema.tables.records.LogicalFlowRecord) Collectors.toSet(java.util.stream.Collectors.toSet) LOGICAL_FLOW(com.khartec.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW) Application(com.khartec.waltz.model.application.Application) LogicalFlowService(com.khartec.waltz.service.logical_flow.LogicalFlowService) Set(java.util.Set) AuthoritativeSourceDao(com.khartec.waltz.data.authoritative_source.AuthoritativeSourceDao) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ListUtilities.randomPick(com.khartec.waltz.common.ListUtilities.randomPick) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) LogicalFlowRecord(com.khartec.waltz.schema.tables.records.LogicalFlowRecord) LogicalFlowService(com.khartec.waltz.service.logical_flow.LogicalFlowService) AuthoritativeSourceDao(com.khartec.waltz.data.authoritative_source.AuthoritativeSourceDao) DSLContext(org.jooq.DSLContext) AuthoritativeSource(com.khartec.waltz.model.authoritativesource.AuthoritativeSource) OrganisationalUnit(com.khartec.waltz.model.orgunit.OrganisationalUnit) LogicalFlow(com.khartec.waltz.model.logical_flow.LogicalFlow) ImmutableLogicalFlow(com.khartec.waltz.model.logical_flow.ImmutableLogicalFlow) EntityReference(com.khartec.waltz.model.EntityReference) Application(com.khartec.waltz.model.application.Application) ApplicationService(com.khartec.waltz.service.application.ApplicationService) HashSet(java.util.HashSet)

Example 85 with DSLContext

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

the class MeasurablesGenerator method generateRegions.

private static void generateRegions(DSLContext dsl) throws IOException {
    List<String> lines = readLines(OrgUnitGenerator.class.getResourceAsStream("/regions.csv"));
    System.out.println("Deleting existing Regions & Countries ...");
    int deletedCount = dsl.deleteFrom(MEASURABLE).where(MEASURABLE.MEASURABLE_CATEGORY_ID.in(DSL.select(MEASURABLE_CATEGORY.ID).from(MEASURABLE_CATEGORY).where(MEASURABLE_CATEGORY.EXTERNAL_ID.eq(REGION_CATEGORY_EXTERNAL_ID)))).and(MEASURABLE.PROVENANCE.eq("demo")).execute();
    System.out.println("Deleted: " + deletedCount + " existing Regions & Countries");
    Map<String, Map<String, Set<String>>> regionHierarchy = lines.stream().skip(1).map(line -> StringUtils.splitPreserveAllTokens(line, ",")).filter(cells -> notEmpty(cells[0]) && notEmpty(cells[6]) && notEmpty(cells[5])).map(cells -> Tuple.tuple(cells[0], cells[6], cells[5])).collect(groupingBy(t -> t.v3, groupingBy(t -> t.v2, mapping(t -> t.v1, toSet()))));
    final long measurableCategoryId = dsl.select(MEASURABLE_CATEGORY.ID).from(MEASURABLE_CATEGORY).where(MEASURABLE_CATEGORY.EXTERNAL_ID.eq(REGION_CATEGORY_EXTERNAL_ID)).fetchAny().value1();
    AtomicInteger insertCount = new AtomicInteger(0);
    regionHierarchy.forEach((region, subRegionMap) -> {
        final long regionId = dsl.insertInto(MEASURABLE).set(createRegion(null, region, measurableCategoryId, false)).returning(MEASURABLE.ID).fetchOne().getId();
        insertCount.incrementAndGet();
        subRegionMap.forEach((subRegion, countries) -> {
            final long subRegionId = dsl.insertInto(MEASURABLE).set(createRegion(regionId, subRegion, measurableCategoryId, true)).returning(MEASURABLE.ID).fetchOne().getId();
            insertCount.incrementAndGet();
            insertCount.addAndGet(dsl.batchInsert(countries.stream().map(country -> createRegion(subRegionId, country, measurableCategoryId, true)).collect(toList())).execute().length);
        });
    });
    System.out.println("Inserted: " + insertCount + " Regions & Countries");
}
Also used : DSL(org.jooq.impl.DSL) MeasurableRecord(com.khartec.waltz.schema.tables.records.MeasurableRecord) StringUtilities.notEmpty(com.khartec.waltz.common.StringUtilities.notEmpty) Set(java.util.Set) IOException(java.io.IOException) MEASURABLE(com.khartec.waltz.schema.tables.Measurable.MEASURABLE) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) List(java.util.List) Tuple(org.jooq.lambda.tuple.Tuple) DIConfiguration(com.khartec.waltz.service.DIConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) MEASURABLE_CATEGORY(com.khartec.waltz.schema.tables.MeasurableCategory.MEASURABLE_CATEGORY) DSLContext(org.jooq.DSLContext) IOUtilities.readLines(com.khartec.waltz.common.IOUtilities.readLines) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map)

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