Skip to content

Commit

Permalink
Jerahmeel: support deleting bundle problems
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar committed Dec 21, 2024
1 parent 0ade2bc commit e92c8dd
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import judgels.jerahmeel.persistence.BundleItemSubmissionModel;
import judgels.persistence.hibernate.HibernateDaoData;
import judgels.sandalphon.hibernate.AbstractBundleItemSubmissionHibernateDao;
import org.hibernate.query.Query;

public class BundleItemSubmissionHibernateDao
extends AbstractBundleItemSubmissionHibernateDao<BundleItemSubmissionModel>
Expand All @@ -19,4 +20,14 @@ public BundleItemSubmissionHibernateDao(HibernateDaoData data) {
public BundleItemSubmissionModel createSubmissionModel() {
return new BundleItemSubmissionModel();
}

@Override
public void deleteAllByProblemJid(String problemJid) {
Query<?> query = currentSession().createQuery(
"DELETE FROM jerahmeel_bundle_item_submission "
+ "WHERE problemJid = :problemJid");

query.setParameter("problemJid", problemJid);
query.executeUpdate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import judgels.jerahmeel.persistence.BundleItemSubmissionDao;
import judgels.jerahmeel.persistence.ChapterProblemDao;
import judgels.jerahmeel.persistence.ProblemSetProblemDao;
import judgels.jerahmeel.persistence.ProgrammingGradingDao;
Expand All @@ -20,6 +21,7 @@ public class DeleteProblemTask extends Task {
private final ProblemSetProblemDao problemSetProblemDao;
private final ProgrammingSubmissionDao programmingSubmissionDao;
private final ProgrammingGradingDao programmingGradingDao;
private final BundleItemSubmissionDao bundleItemSubmissionDao;
private final StatsUserProblemDao statsUserProblemDao;

public DeleteProblemTask(
Expand All @@ -28,6 +30,7 @@ public DeleteProblemTask(
ProblemSetProblemDao problemSetProblemDao,
ProgrammingSubmissionDao programmingSubmissionDao,
ProgrammingGradingDao programmingGradingDao,
BundleItemSubmissionDao bundleItemSubmissionDao,
StatsUserProblemDao statsUserProblemDao) {

super("jerahmeel-delete-problem");
Expand All @@ -37,6 +40,7 @@ public DeleteProblemTask(
this.problemSetProblemDao = problemSetProblemDao;
this.programmingSubmissionDao = programmingSubmissionDao;
this.programmingGradingDao = programmingGradingDao;
this.bundleItemSubmissionDao = bundleItemSubmissionDao;
this.statsUserProblemDao = statsUserProblemDao;
}

Expand All @@ -55,9 +59,14 @@ public void execute(Map<String, List<String>> parameters, PrintWriter out) {
}
String problemJid = maybeProblemModel.get().jid;

if (problemJid.startsWith("JIDPROG")) {
programmingGradingDao.deleteAllByProblemJid(problemJid);
programmingSubmissionDao.deleteAllByProblemJid(problemJid);
} else {
bundleItemSubmissionDao.deleteAllByProblemJid(problemJid);
}

statsUserProblemDao.deleteAllByProblemJid(problemJid);
programmingGradingDao.deleteAllByProblemJid(problemJid);
programmingSubmissionDao.deleteAllByProblemJid(problemJid);
chapterProblemDao.selectByProblemJid(problemJid).ifPresent(chapterProblemDao::delete);
problemSetProblemDao.selectAllByProblemJid(problemJid).forEach(problemSetProblemDao::delete);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dagger.Provides;
import io.dropwizard.hibernate.UnitOfWorkAwareProxyFactory;
import javax.inject.Singleton;
import judgels.jerahmeel.persistence.BundleItemSubmissionDao;
import judgels.jerahmeel.persistence.ChapterDao;
import judgels.jerahmeel.persistence.ChapterProblemDao;
import judgels.jerahmeel.persistence.ProblemSetProblemDao;
Expand All @@ -25,6 +26,7 @@ static DeleteProblemTask deleteProblemTask(
ProblemSetProblemDao problemSetProblemDao,
ProgrammingSubmissionDao programmingSubmissionDao,
ProgrammingGradingDao programmingGradingDao,
BundleItemSubmissionDao bundleItemSubmissionDao,
StatsUserProblemDao statsUserProblemDao) {

return unitOfWorkAwareProxyFactory.create(
Expand All @@ -35,13 +37,15 @@ static DeleteProblemTask deleteProblemTask(
ProblemSetProblemDao.class,
ProgrammingSubmissionDao.class,
ProgrammingGradingDao.class,
BundleItemSubmissionDao.class,
StatsUserProblemDao.class},
new Object[] {
problemDao,
chapterProblemDao,
problemSetProblemDao,
programmingSubmissionDao,
programmingGradingDao,
bundleItemSubmissionDao,
statsUserProblemDao});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public AbstractBundleItemSubmissionHibernateQueryBuilder<M> select() {
return new AbstractBundleItemSubmissionHibernateQueryBuilder<>(currentSession(), getEntityClass());
}

@Override
public void deleteAllByProblemJid(String problemJid) {
throw new UnsupportedOperationException();
}

private static class AbstractBundleItemSubmissionHibernateQueryBuilder<M extends AbstractBundleItemSubmissionModel> extends HibernateQueryBuilder<M> implements BaseBundleItemSubmissionQueryBuilder<M> {
AbstractBundleItemSubmissionHibernateQueryBuilder(Session currentSession, Class<M> entityClass) {
super(currentSession, entityClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public interface BaseBundleItemSubmissionDao<M extends AbstractBundleItemSubmiss
M createSubmissionModel();

BaseBundleItemSubmissionQueryBuilder<M> select();
void deleteAllByProblemJid(String problemJid);

interface BaseBundleItemSubmissionQueryBuilder<M extends AbstractBundleItemSubmissionModel> extends QueryBuilder<M> {
BaseBundleItemSubmissionQueryBuilder<M> whereContainerIs(String containerJid);
Expand Down

0 comments on commit e92c8dd

Please sign in to comment.