org.fluentjdbc.DatabaseBulkQueryable 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 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