use of com.khartec.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");
}
Aggregations