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

org.fluentjdbc.DatabaseDeleteBuilder Maven / Gradle / Ivy

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