Skip to content

Commit

Permalink
MIR-1354 use count query insteand of select
Browse files Browse the repository at this point in the history
  • Loading branch information
toKrause committed Sep 12, 2024
1 parent c069927 commit acb8da6
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,17 @@ public void startUp(ServletContext servletContext) {
private boolean alreadyDone() {
EntityManager manager = MCREntityManagerProvider.getCurrentEntityManager();
CriteriaBuilder builder = manager.getCriteriaBuilder();
CriteriaQuery<MCRJob> criteria = builder.createQuery(MCRJob.class);
CriteriaQuery<Long> criteria = builder.createQuery(Long.class);
Root<MCRJob> root = criteria.from(MCRJob.class);

List<Predicate> predicates = new ArrayList<Predicate>();
List<Predicate> predicates = new ArrayList<>();
predicates.add(builder.equal(root.get(MCRJob_.action), MIRMigrateStaticHistoryContentJobAction.class));
predicates.add(builder.equal(root.get(MCRJob_.status), MCRJobStatus.FINISHED));

criteria.select(builder.count(root));
criteria.where(predicates.toArray(new Predicate[] {}));
List<MCRJob> resultList = manager.createQuery(criteria).getResultList();
Long result = manager.createQuery(criteria).getSingleResult();

return resultList.size() > 0;
return result > 0;
}
}

0 comments on commit acb8da6

Please sign in to comment.