Search in sources :

Example 1 with TableRecord

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

the class ChangeInitiativeGenerator method main.

public static void main(String[] args) {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    List<Long> groupIds = dsl.select(APPLICATION_GROUP.ID).from(APPLICATION_GROUP).fetch(APPLICATION_GROUP.ID);
    List<String> employeeIds = dsl.select(PERSON.EMPLOYEE_ID).from(PERSON).fetch(PERSON.EMPLOYEE_ID);
    List<Long> orgUnitIds = dsl.select(ORGANISATIONAL_UNIT.ID).from(ORGANISATIONAL_UNIT).fetch(ORGANISATIONAL_UNIT.ID);
    List<TableRecord<?>> records = LongStream.range(0, 400).mapToObj(i -> {
        String name = randomPick(p1) + " " + randomPick(p2) + " " + randomPick(p3);
        Long ouId = randomPick(orgUnitIds.toArray(new Long[0]));
        return Tuple.tuple(i, name, ouId);
    }).map(t -> buildChangeInitiativeRecord(t)).flatMap(r -> Stream.concat(Stream.of(r), buildLinks(r, groupIds, employeeIds))).collect(toList());
    System.out.println("-- deleting");
    dsl.deleteFrom(CHANGE_INITIATIVE).execute();
    System.out.println("-- inserting");
    dsl.batchInsert(records).execute();
    System.out.println(" -- done");
}
Also used : IntStream(java.util.stream.IntStream) InvolvementRecord(com.khartec.waltz.schema.tables.records.InvolvementRecord) Random(java.util.Random) EntityKind(com.khartec.waltz.model.EntityKind) Tuple3(org.jooq.lambda.tuple.Tuple3) DIConfiguration(com.khartec.waltz.service.DIConfiguration) DSLContext(org.jooq.DSLContext) APP_GROUP(com.khartec.waltz.model.EntityKind.APP_GROUP) LongStream(java.util.stream.LongStream) LifecyclePhase(com.khartec.waltz.model.application.LifecyclePhase) ArrayUtilities.randomPick(com.khartec.waltz.common.ArrayUtilities.randomPick) ListUtilities(com.khartec.waltz.common.ListUtilities) PERSON(com.khartec.waltz.schema.tables.Person.PERSON) TableRecord(org.jooq.TableRecord) Instant(java.time.Instant) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) Date(java.sql.Date) List(java.util.List) ORGANISATIONAL_UNIT(com.khartec.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT) Collectors.toList(java.util.stream.Collectors.toList) Tuple(org.jooq.lambda.tuple.Tuple) Stream(java.util.stream.Stream) EntityRelationshipRecord(com.khartec.waltz.schema.tables.records.EntityRelationshipRecord) APPLICATION_GROUP(com.khartec.waltz.schema.tables.ApplicationGroup.APPLICATION_GROUP) RelationshipKind(com.khartec.waltz.model.entity_relationship.RelationshipKind) CHANGE_INITIATIVE(com.khartec.waltz.schema.tables.ChangeInitiative.CHANGE_INITIATIVE) ChangeInitiativeRecord(com.khartec.waltz.schema.tables.records.ChangeInitiativeRecord) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DSLContext(org.jooq.DSLContext) TableRecord(org.jooq.TableRecord)

Example 2 with TableRecord

use of org.jooq.TableRecord 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 3 with TableRecord

use of org.jooq.TableRecord in project jOOQ by jOOQ.

the class AbstractResult method formatInsert.

@Override
public final void formatInsert(Writer writer, Table<?> table, Field<?>... f) {
    DSLContext ctx = configuration.dsl();
    try {
        for (R record : this) {
            if (table == null)
                if (record instanceof TableRecord)
                    table = ((TableRecord<?>) record).getTable();
                else
                    table = table(name("UNKNOWN_TABLE"));
            writer.append(ctx.renderInlined(insertInto(table, f).values(record.intoArray()))).append(";\n");
        }
        writer.flush();
    } catch (java.io.IOException e) {
        throw new IOException("Exception while writing INSERTs", e);
    }
}
Also used : DSLContext(org.jooq.DSLContext) IOException(org.jooq.exception.IOException) TableRecord(org.jooq.TableRecord)

Aggregations

DSLContext (org.jooq.DSLContext)3 TableRecord (org.jooq.TableRecord)3 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)2 ArrayUtilities.randomPick (com.khartec.waltz.common.ArrayUtilities.randomPick)1 ListUtilities (com.khartec.waltz.common.ListUtilities)1 EntityKind (com.khartec.waltz.model.EntityKind)1 APP_GROUP (com.khartec.waltz.model.EntityKind.APP_GROUP)1 LifecyclePhase (com.khartec.waltz.model.application.LifecyclePhase)1 RelationshipKind (com.khartec.waltz.model.entity_relationship.RelationshipKind)1 APPLICATION_GROUP (com.khartec.waltz.schema.tables.ApplicationGroup.APPLICATION_GROUP)1 CHANGE_INITIATIVE (com.khartec.waltz.schema.tables.ChangeInitiative.CHANGE_INITIATIVE)1 ORGANISATIONAL_UNIT (com.khartec.waltz.schema.tables.OrganisationalUnit.ORGANISATIONAL_UNIT)1 PERSON (com.khartec.waltz.schema.tables.Person.PERSON)1 ChangeInitiativeRecord (com.khartec.waltz.schema.tables.records.ChangeInitiativeRecord)1 EntityRelationshipRecord (com.khartec.waltz.schema.tables.records.EntityRelationshipRecord)1 InvolvementRecord (com.khartec.waltz.schema.tables.records.InvolvementRecord)1 ProcessRecord (com.khartec.waltz.schema.tables.records.ProcessRecord)1 DIConfiguration (com.khartec.waltz.service.DIConfiguration)1 Date (java.sql.Date)1 Instant (java.time.Instant)1