// Path: vertx-jooq-async-shared/src/main/java/io/github/jklingsporn/vertx/jooq/async/shared/VertxPojo.java
// public interface VertxPojo {
// 
//     public VertxPojo fromJson(io.vertx.core.json.JsonObject json);
// 
//     public io.vertx.core.json.JsonObject toJson();
// }


import io.github.jklingsporn.vertx.jooq.async.shared.VertxPojo;
import io.vertx.core.impl.Arguments;
import io.vertx.core.json.JsonObject;
import org.jooq.*;
import org.jooq.impl.DSL;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import static org.jooq.impl.DSL.row;
package io.github.jklingsporn.vertx.jooq.async.shared.internal;




/**
 * Created by jensklingsporn on 23.11.17.
 * Utility class to reduce duplicate code in the different VertxDAO implementations.
 * Only meant to be used by vertx-jooq-async.
 */
public class VertxDAOHelper {

    private VertxDAOHelper() {
    }

    static EnumSet<SQLDialect> INSERT_RETURNING_SUPPORT = EnumSet.of(SQLDialect.MYSQL,SQLDialect.MYSQL_5_7,SQLDialect.MYSQL_8_0);


    @SuppressWarnings("unchecked")
    public static <R extends UpdatableRecord<R>,T,F> F applyConditionally(T id, Table<R> table, Function<Condition, F> function){
        UniqueKey<?> uk = table.getPrimaryKey();
        Objects.requireNonNull(uk,()->"No primary key");
        /**
         * Copied from jOOQs DAOImpl#equal-method
         */
        TableField<? extends Record, ?>[] pk = uk.getFieldsArray();
        Condition condition;
        if (pk.length == 1) {
            condition = ((Field<Object>) pk[0]).equal(pk[0].getDataType().convert(id));
        }
        else {
            condition = row(pk).equal((Record) id);
        }
        return function.apply(condition);
    }


    @SuppressWarnings("unchecked")
// Path: vertx-jooq-async-shared/src/main/java/io/github/jklingsporn/vertx/jooq/async/shared/VertxPojo.java
// public interface VertxPojo {
// 
//     public VertxPojo fromJson(io.vertx.core.json.JsonObject json);
// 
//     public io.vertx.core.json.JsonObject toJson();
// }


// Path: vertx-jooq-async-shared/src/main/java/io/github/jklingsporn/vertx/jooq/async/shared/internal/VertxDAOHelper.java
import io.github.jklingsporn.vertx.jooq.async.shared.VertxPojo;
import io.vertx.core.impl.Arguments;
import io.vertx.core.json.JsonObject;
import org.jooq.*;
import org.jooq.impl.DSL;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import static org.jooq.impl.DSL.row;

package io.github.jklingsporn.vertx.jooq.async.shared.internal;




/**
 * Created by jensklingsporn on 23.11.17.
 * Utility class to reduce duplicate code in the different VertxDAO implementations.
 * Only meant to be used by vertx-jooq-async.
 */
public class VertxDAOHelper {

    private VertxDAOHelper() {
    }

    static EnumSet<SQLDialect> INSERT_RETURNING_SUPPORT = EnumSet.of(SQLDialect.MYSQL,SQLDialect.MYSQL_5_7,SQLDialect.MYSQL_8_0);


    @SuppressWarnings("unchecked")
    public static <R extends UpdatableRecord<R>,T,F> F applyConditionally(T id, Table<R> table, Function<Condition, F> function){
        UniqueKey<?> uk = table.getPrimaryKey();
        Objects.requireNonNull(uk,()->"No primary key");
        /**
         * Copied from jOOQs DAOImpl#equal-method
         */
        TableField<? extends Record, ?>[] pk = uk.getFieldsArray();
        Condition condition;
        if (pk.length == 1) {
            condition = ((Field<Object>) pk[0]).equal(pk[0].getDataType().convert(id));
        }
        else {
            condition = row(pk).equal((Record) id);
        }
        return function.apply(condition);
    }


    @SuppressWarnings("unchecked")
    public static <P extends VertxPojo, R extends UpdatableRecord<R>,T,F> F updateExecAsync(P object, DAO<R,P,T> dao, Function<Query,F> function){