package hirondelle.fish.main.resto;
import java.util.*;
import hirondelle.web4j.model.Id;
import hirondelle.web4j.database.DAOException;
import hirondelle.web4j.database.DuplicateException;
import hirondelle.web4j.util.Util;
import hirondelle.web4j.database.Db;
import static hirondelle.fish.main.resto.RestoAction.LIST_RESTOS;
import static hirondelle.fish.main.resto.RestoAction.FETCH_RESTO;
import static hirondelle.fish.main.resto.RestoAction.CHANGE_RESTO;
import static hirondelle.fish.main.resto.RestoAction.ADD_RESTO;
import static hirondelle.fish.main.resto.RestoAction.DELETE_RESTO;
final class RestoDAO {
List<Resto> list() throws DAOException {
return Db.list(Resto.class, LIST_RESTOS);
}
Resto fetch(Id aRestoId) throws DAOException {
return Db.fetch(Resto.class, FETCH_RESTO, aRestoId);
}
Id add(Resto aResto) throws DAOException, DuplicateException {
Id result = Db.add(
ADD_RESTO,
aResto.getName(), aResto.getLocation(), aResto.getPrice(), aResto.getComment()
);
return result;
}
boolean change(Resto aResto) throws DAOException, DuplicateException {
Object[] params = { aResto.getName(), aResto.getLocation(), aResto.getPrice(), aResto.getComment(), aResto.getId() };
return Util.isSuccess(Db.edit(CHANGE_RESTO, params));
}
void delete(Id aRestoId) throws DAOException {
Db.delete(DELETE_RESTO, aRestoId);
}
}