com.kenshoo.jooq.DataTableUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of persistence-layer Show documentation
Show all versions of persistence-layer Show documentation
A Java persistence layer based on JOOQ for high performance and business flow support.
package com.kenshoo.jooq;
import org.jooq.*;
import static org.jooq.impl.DSL.constraint;
public class DataTableUtils {
public static void createTable(final DSLContext dslContext, final Table table) {
dslContext.dropTableIfExists(table).execute();
final CreateTableColumnStep createTableAsStep = dslContext.createTable(table)
.columns(table.fields());
final UniqueKey primaryKey = table.getPrimaryKey();
if (primaryKey != null) {
createTableAsStep.constraints(constraint("").primaryKey(primaryKey.getFieldsArray()))
.execute();
} else {
createTableAsStep.execute();
}
}
public static void populateTable(DSLContext dslContext, Table table, Object[][] data) {
InsertValuesStepN insert = dslContext.insertInto(table, table.fields()).values(new Object[table.fields().length]);
BatchBindStep batch = dslContext.batch(insert);
for (Object[] values : data) {
batch.bind(values);
}
batch.execute();
}
}