package hirondelle.predict.main.lists;
import static hirondelle.predict.main.lists.PredictionListAction.PREDICTION_LIST_ADD;
import static hirondelle.predict.main.lists.PredictionListAction.PREDICTION_LIST_CHANGE;
import static hirondelle.predict.main.lists.PredictionListAction.PREDICTION_LIST_DELETE;
import static hirondelle.predict.main.lists.PredictionListAction.PREDICTION_LIST_FETCH;
import static hirondelle.predict.main.lists.PredictionListAction.PREDICTION_LIST_FETCH_PUBLIC;
import static hirondelle.predict.main.lists.PredictionListAction.PREDICTION_LIST_LIST;
import hirondelle.web4j.database.DAOException;
import hirondelle.web4j.database.Db;
import hirondelle.web4j.database.ForeignKeyException;
import hirondelle.web4j.model.DateTime;
import hirondelle.web4j.model.Id;
import hirondelle.web4j.util.Util;
import java.util.List;
public final class PredictionListDAO {
public List<PredictionList> list(Id aUserId) throws DAOException {
return Db.list(PredictionList.class, PREDICTION_LIST_LIST, aUserId);
}
public PredictionList fetch(Id aPredictionListId, Id aUserId) throws DAOException {
return Db.fetch(PredictionList.class, PREDICTION_LIST_FETCH, aPredictionListId, aUserId);
}
public PredictionList fetchPublic(Id aPredictionListId) throws DAOException {
return Db.fetch(PredictionList.class, PREDICTION_LIST_FETCH_PUBLIC, aPredictionListId);
}
Id add(PredictionList aPredictionList, DateTime aToday) throws DAOException {
Object[] params = {aPredictionList.getTitle(), aToday, aPredictionList.getUser()};
return Db.add(PREDICTION_LIST_ADD, params);
}
boolean change(PredictionList aPredictionList) throws DAOException {
Object[] params = {aPredictionList.getTitle(), aPredictionList.getId(), aPredictionList.getUser() };
return Util.isSuccess(Db.edit(PREDICTION_LIST_CHANGE, params));
}
void delete(Id aPredictionListId, Id aUserId) throws DAOException, ForeignKeyException {
Db.edit(PREDICTION_LIST_DELETE, aPredictionListId, aUserId);
}
}