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

org.fluentjdbc.DatabaseBulkQueryable Maven / Gradle / Ivy

There is a newer version: 0.5.3
Show newest version
package org.fluentjdbc;

import javax.annotation.CheckReturnValue;
import java.sql.PreparedStatement;
import java.util.List;
import java.util.function.Function;

/**
 * Fluently create a statement for a list of objects with a WHERE ... clause,
 * such as UPDATE  or DELETE
 */
public interface DatabaseBulkQueryable> {
    /**
     * Adds a function that will be called for each object to get the value for
     * {@link PreparedStatement#setObject(int, Object)} for each row in the bulk update
     * to extract the values for the SET fieldName = ? clause
     */
    @CheckReturnValue
    SELF where(String field, Function value);

    /**
     * Adds a list of functions that will be called for each object to get the value for
     * {@link PreparedStatement#setObject(int, Object)} for each row in the bulk update
     * to extract the values for the SET fieldName1 = ?, fieldName2 = ?, ... clause
     */
    @CheckReturnValue
    default SELF whereAll(List fields, Function> values) {
        for (int i = 0, fieldsSize = fields.size(); i < fieldsSize; i++) {
            int index = i;
            //noinspection ResultOfMethodCallIgnored
            where(fields.get(i), o -> values.apply(o).get(index));
        }
        //noinspection unchecked
        return (SELF) this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy