org.fluentjdbc.DatabaseBulkUpdatable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fluent-jdbc Show documentation
Show all versions of fluent-jdbc Show documentation
A Java library used to execute JDBC statements and build SQL
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 which updates values, ie INSERT
* or UPDATE
*/
public interface DatabaseBulkUpdatable> {
/**
* Adds a function that will be called for each object to get the value for
* {@link PreparedStatement#setObject(int, Object)} parameter for each row in the bulk update
* to extract the values for fieldName parameter
*/
@CheckReturnValue
SELF setField(String fieldName, Function transformer);
/**
* Adds a list function that will be called for each object to get the value
* each of the corresponding parameters in the {@link PreparedStatement}
*/
@CheckReturnValue
default > SELF setFields(List fields, Function values) {
for (int i = 0, fieldsSize = fields.size(); i < fieldsSize; i++) {
int index = i;
//noinspection ResultOfMethodCallIgnored
setField(fields.get(i), o -> values.apply(o).get(index));
}
//noinspection unchecked
return (SELF) this;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy