From acb8da62c7061c171f2eeeb8879508d3776e4393 Mon Sep 17 00:00:00 2001 From: Torsten Krause Date: Thu, 12 Sep 2024 09:24:03 +0200 Subject: [PATCH] MIR-1354 use count query insteand of select --- .../mir/migration/MIRMigrateStaticHistoryContent.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mir-module/src/main/java/org/mycore/mir/migration/MIRMigrateStaticHistoryContent.java b/mir-module/src/main/java/org/mycore/mir/migration/MIRMigrateStaticHistoryContent.java index 21e382df6c..6dfb4379f9 100644 --- a/mir-module/src/main/java/org/mycore/mir/migration/MIRMigrateStaticHistoryContent.java +++ b/mir-module/src/main/java/org/mycore/mir/migration/MIRMigrateStaticHistoryContent.java @@ -51,16 +51,17 @@ public void startUp(ServletContext servletContext) { private boolean alreadyDone() { EntityManager manager = MCREntityManagerProvider.getCurrentEntityManager(); CriteriaBuilder builder = manager.getCriteriaBuilder(); - CriteriaQuery criteria = builder.createQuery(MCRJob.class); + CriteriaQuery criteria = builder.createQuery(Long.class); Root root = criteria.from(MCRJob.class); - List predicates = new ArrayList(); + List 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 resultList = manager.createQuery(criteria).getResultList(); + Long result = manager.createQuery(criteria).getSingleResult(); - return resultList.size() > 0; + return result > 0; } }