package com.j256.ormlite.stmt.mapped;
import java.sql.SQLException;
import com.j256.ormlite.db.DatabaseType;
import com.j256.ormlite.field.FieldType;
import com.j256.ormlite.table.TableInfo;
/**
* A mapped statement for deleting an object.
*
* @author graywatson
*/
public class MappedDelete<T, ID> extends BaseMappedStatement<T, ID> {
private MappedDelete(TableInfo<T, ID> tableInfo, String statement, FieldType[] argFieldTypes) {
super(tableInfo, statement, argFieldTypes);
}
public static <T, ID> MappedDelete<T, ID> build(DatabaseType databaseType, TableInfo<T, ID> tableInfo)
throws SQLException {
FieldType idField = tableInfo.getIdField();
if (idField == null) {
throw new SQLException("Cannot delete from " + tableInfo.getDataClass()
+ " because it doesn't have an id field");
}
StringBuilder sb = new StringBuilder(64);
appendTableName(databaseType, sb, "DELETE FROM ", tableInfo.getTableName());
appendWhereId(databaseType, idField, sb, null);
return new MappedDelete<T, ID>(tableInfo, sb.toString(), new FieldType[] { idField });
}
}