From 1215d1a8badf3ef2c526b3033de4c77f4f8ffc0f Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Mon, 22 Apr 2013 10:33:49 +0200 Subject: [PATCH] CL-220: retrieve the course infos for groups as batch (Oracle doesn't like in(...) statement with more than 1000 keys) --- .../manager/BusinessGroupRelationDAO.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/olat/group/manager/BusinessGroupRelationDAO.java b/src/main/java/org/olat/group/manager/BusinessGroupRelationDAO.java index 81b8619f70d..602b16d6595 100644 --- a/src/main/java/org/olat/group/manager/BusinessGroupRelationDAO.java +++ b/src/main/java/org/olat/group/manager/BusinessGroupRelationDAO.java @@ -290,19 +290,35 @@ public class BusinessGroupRelationDAO { if(groupKeys == null || groupKeys.isEmpty()) { return Collections.emptyList(); } - + StringBuilder sb = new StringBuilder(); sb.append("select rel from ").append(BGRepositoryEntryRelation.class.getName()).append(" as rel ") .append(" where rel.groupKey in (:groupKeys)"); TypedQuery<BGRepositoryEntryRelation> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), BGRepositoryEntryRelation.class); - query.setFirstResult(firstResult); - if(maxResults > 0) { - query.setMaxResults(maxResults); + + if(firstResult >= 0 && maxResults >= 0) { + query.setFirstResult(firstResult); + if(maxResults > 0) { + query.setMaxResults(maxResults); + } + query.setParameter("groupKeys", groupKeys); + return query.getResultList(); } + + List<Long> groupKeyList = new ArrayList<Long>(groupKeys); + List<BGRepositoryEntryRelation> relations = new ArrayList<BGRepositoryEntryRelation>(groupKeys.size()); - query.setParameter("groupKeys", groupKeys); - return query.getResultList(); + int count = 0; + int batch = 500; + do { + int toIndex = Math.min(count + batch, groupKeyList.size()); + List<Long> toLoad = groupKeyList.subList(count, toIndex); + List<BGRepositoryEntryRelation> batchOfRelations = query.setParameter("groupKeys", toLoad).getResultList(); + relations.addAll(batchOfRelations); + count += batch; + } while(count < groupKeyList.size()); + return relations; } public List<BGResourceRelation> findRelations(Collection<Long> groupKeys, int firstResult, int maxResults) { -- GitLab