Search in sources :

Example 1 with PersonRecord

use of org.finos.waltz.schema.tables.records.PersonRecord in project waltz by khartec.

the class MSSqlImportExportExample method main.

public static void main(String[] args) throws ParseException, IOException {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(DIConfiguration.class);
    DSLContext dsl = ctx.getBean(DSLContext.class);
    if (false) {
        System.out.println("-- saving");
        dsl.selectFrom(PERSON).fetch().formatCSV(new FileOutputStream("person.csv"), ',', "{null}");
    }
    if (true) {
        System.out.println("-- deleting");
        dsl.deleteFrom(PERSON).execute();
        dsl.transaction(cfg -> {
            // insert the identity insert statement
            ExecuteListener listener = new DefaultExecuteListener() {

                @Override
                public void renderEnd(ExecuteContext ctx) {
                    ctx.sql("SET IDENTITY_INSERT [person] ON " + ctx.sql());
                }
            };
            cfg.set(new DefaultExecuteListenerProvider(listener));
            DSLContext tx = DSL.using(cfg);
            System.out.println("-- loading");
            Loader<PersonRecord> loader = tx.loadInto(PERSON).loadCSV(new FileInputStream("person.csv")).fields(PERSON.fields()).nullString(// treat this from the csv as a database NULL value
            "{null}").execute();
            System.out.println("processed:" + loader.processed());
            System.out.println("stored:" + loader.stored());
            System.out.println("ignored:" + loader.ignored());
            loader.errors().forEach(e -> System.out.println("error:" + e.exception().getMessage()));
        });
    }
    System.out.println("-- done");
}
Also used : DefaultExecuteListener(org.jooq.impl.DefaultExecuteListener) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DefaultExecuteListenerProvider(org.jooq.impl.DefaultExecuteListenerProvider) FileOutputStream(java.io.FileOutputStream) DSLContext(org.jooq.DSLContext) ExecuteContext(org.jooq.ExecuteContext) ExecuteListener(org.jooq.ExecuteListener) DefaultExecuteListener(org.jooq.impl.DefaultExecuteListener) PersonRecord(org.finos.waltz.schema.tables.records.PersonRecord) FileInputStream(java.io.FileInputStream)

Example 2 with PersonRecord

use of org.finos.waltz.schema.tables.records.PersonRecord in project waltz by khartec.

the class PersonHelper method createPerson.

public Long createPerson(String name) {
    PersonRecord p = dsl.newRecord(PERSON);
    p.setDepartmentName("dept");
    p.setEmail(name);
    p.setKind(PersonKind.EMPLOYEE.name());
    p.setDisplayName(name);
    p.setEmployeeId(Long.toString(ctr.incrementAndGet()));
    p.insert();
    return p.getId();
}
Also used : PersonRecord(org.finos.waltz.schema.tables.records.PersonRecord)

Aggregations

PersonRecord (org.finos.waltz.schema.tables.records.PersonRecord)2 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 DSLContext (org.jooq.DSLContext)1 ExecuteContext (org.jooq.ExecuteContext)1 ExecuteListener (org.jooq.ExecuteListener)1 DefaultExecuteListener (org.jooq.impl.DefaultExecuteListener)1 DefaultExecuteListenerProvider (org.jooq.impl.DefaultExecuteListenerProvider)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1