Skip to content
Snippets Groups Projects
Commit 62ad5240 authored by srosse's avatar srosse
Browse files

OO-1524: fix too much parameters in a select not in ()

parent 427ca618
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,7 @@ package org.olat.course.archiver; ...@@ -28,6 +28,7 @@ package org.olat.course.archiver;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
...@@ -383,6 +384,7 @@ public class ScoreAccountingHelper { ...@@ -383,6 +384,7 @@ public class ScoreAccountingHelper {
BusinessGroupService businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class); BusinessGroupService businessGroupService = CoreSpringFactory.getImpl(BusinessGroupService.class);
List<Identity> userList = businessGroupService.getMembers(groups, GroupRoles.participant.name()); List<Identity> userList = businessGroupService.getMembers(groups, GroupRoles.participant.name());
userList = new ArrayList<>(new HashSet<>(userList));
OLATResourceable ores = OresHelper.createOLATResourceableInstance(CourseModule.class, courseEnv.getCourseResourceableId()); OLATResourceable ores = OresHelper.createOLATResourceableInstance(CourseModule.class, courseEnv.getCourseResourceableId());
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(ores, false); RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntry(ores, false);
if(re != null) { if(re != null) {
...@@ -391,7 +393,10 @@ public class ScoreAccountingHelper { ...@@ -391,7 +393,10 @@ public class ScoreAccountingHelper {
} }
List<Identity> assessedList = courseEnv.getCoursePropertyManager().getAllIdentitiesWithCourseAssessmentData(userList); List<Identity> assessedList = courseEnv.getCoursePropertyManager().getAllIdentitiesWithCourseAssessmentData(userList);
userList.addAll(assessedList); if(assessedList.size() > 0) {
assessedList.removeAll(userList);//deduplicate
userList.addAll(assessedList);
}
return userList; return userList;
} }
......
...@@ -32,10 +32,10 @@ import java.util.List; ...@@ -32,10 +32,10 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
import javax.persistence.TypedQuery;
import org.olat.basesecurity.IdentityImpl; import org.olat.basesecurity.IdentityImpl;
import org.olat.core.commons.persistence.DB;
import org.olat.core.commons.persistence.DBFactory; import org.olat.core.commons.persistence.DBFactory;
import org.olat.core.commons.persistence.DBQuery;
import org.olat.core.id.Identity; import org.olat.core.id.Identity;
import org.olat.core.id.OLATResourceable; import org.olat.core.id.OLATResourceable;
import org.olat.core.logging.AssertException; import org.olat.core.logging.AssertException;
...@@ -219,8 +219,11 @@ public class PersistingCoursePropertyManager extends BasicManager implements Cou ...@@ -219,8 +219,11 @@ public class PersistingCoursePropertyManager extends BasicManager implements Cou
} }
/** /**
* @see org.olat.course.properties.CoursePropertyManager#getAllIdentitiesWithCourseAssessmentData() * The specified exclude identities is only a best effort used for performance. If you want
* unique identities, deduplicate them afterwards.
*
*/ */
@Override
public List<Identity> getAllIdentitiesWithCourseAssessmentData(Collection<Identity> excludeIdentities) { public List<Identity> getAllIdentitiesWithCourseAssessmentData(Collection<Identity> excludeIdentities) {
StringBuilder query = new StringBuilder(); StringBuilder query = new StringBuilder();
query.append("select distinct i from ") query.append("select distinct i from ")
...@@ -235,20 +238,21 @@ public class PersistingCoursePropertyManager extends BasicManager implements Cou ...@@ -235,20 +238,21 @@ public class PersistingCoursePropertyManager extends BasicManager implements Cou
query.append(" and p.identity.key not in (:excludeIdentities) "); query.append(" and p.identity.key not in (:excludeIdentities) ");
} }
DB db = DBFactory.getInstance(); TypedQuery<Identity> db = DBFactory.getInstance().getCurrentEntityManager()
DBQuery dbq = db.createQuery(query.toString()); .createQuery(query.toString(), Identity.class)
dbq.setLong("resid", ores.getResourceableId()); .setParameter("resid", ores.getResourceableId())
dbq.setString("resname", ores.getResourceableTypeName()); .setParameter("resname", ores.getResourceableTypeName());
if(excludeIdentities != null && !excludeIdentities.isEmpty()) { if(excludeIdentities != null && !excludeIdentities.isEmpty()) {
List<Long> excludeKeys = new ArrayList<Long>(); List<Long> excludeKeys = new ArrayList<Long>();
for(Identity identity:excludeIdentities) { for(Identity identity:excludeIdentities) {
excludeKeys.add(identity.getKey()); excludeKeys.add(identity.getKey());
} }
dbq.setParameterList("excludeIdentities", excludeKeys); //limit because Oracle and Hibernate doesn't like more than 1000
if(excludeKeys.size() > 900) {
excludeKeys = excludeKeys.subList(0, 900);
}
db.setParameter("excludeIdentities", excludeKeys);
} }
return db.getResultList();
List<Identity> res = dbq.list();
return res;
} }
} }
\ No newline at end of file
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