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