Skip to content
Snippets Groups Projects
Commit 1215d1a8 authored by srosse's avatar srosse
Browse files

CL-220: retrieve the course infos for groups as batch (Oracle doesn't like...

CL-220: retrieve the course infos for groups as batch (Oracle doesn't like in(...) statement with more than 1000 keys)
parent 22997d72
No related branches found
No related tags found
No related merge requests found
...@@ -290,19 +290,35 @@ public class BusinessGroupRelationDAO { ...@@ -290,19 +290,35 @@ public class BusinessGroupRelationDAO {
if(groupKeys == null || groupKeys.isEmpty()) { if(groupKeys == null || groupKeys.isEmpty()) {
return Collections.emptyList(); return Collections.emptyList();
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("select rel from ").append(BGRepositoryEntryRelation.class.getName()).append(" as rel ") sb.append("select rel from ").append(BGRepositoryEntryRelation.class.getName()).append(" as rel ")
.append(" where rel.groupKey in (:groupKeys)"); .append(" where rel.groupKey in (:groupKeys)");
TypedQuery<BGRepositoryEntryRelation> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), BGRepositoryEntryRelation.class); TypedQuery<BGRepositoryEntryRelation> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), BGRepositoryEntryRelation.class);
query.setFirstResult(firstResult);
if(maxResults > 0) { if(firstResult >= 0 && maxResults >= 0) {
query.setMaxResults(maxResults); 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); int count = 0;
return query.getResultList(); 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) { public List<BGResourceRelation> findRelations(Collection<Long> groupKeys, int firstResult, int maxResults) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment