All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.kenshoo.jooq.DataTableUtils Maven / Gradle / Ivy

Go to download

A Java persistence layer based on JOOQ for high performance and business flow support.

There is a newer version: 0.1.121-jooq-3.16.3
Show newest version
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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy