org.fluentjdbc.DatabaseDeleteBuilder 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.Connection;
/**
* Generate DELETE
statements by collecting field names and parameters. Example:
*
*
* int count = table
* .where("id", id)
* .delete()
* .execute(connection);
*
*/
class DatabaseDeleteBuilder {
private final DatabaseTable table;
private DatabaseWhereBuilder whereClause = new DatabaseWhereBuilder();
public DatabaseDeleteBuilder(DatabaseTable table) {
this.table = table;
}
public int execute(Connection connection) {
return table.newStatement("DELETE", "delete from " + table.getTableName() + whereClause.whereClause(), whereClause.getParameters())
.executeUpdate(connection);
}
@CheckReturnValue
public DatabaseDeleteBuilder where(DatabaseWhereBuilder whereClause) {
this.whereClause = whereClause;
return this;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy