}
/**
*/
public void testQueryReferencableResourcesLimitType() {
DB db = DBFactory.getInstance();
OLATResourceManager resm = OLATResourceManager.getInstance();
RepositoryManager rm = RepositoryManager.getInstance();
Manager securityManager = ManagerFactory.getManager();
Identity id1 = JunitTestHelper.createAndPersistIdentityAsAuthor("id1");
Identity id2 = JunitTestHelper.createAndPersistIdentityAsAuthor("id2");
// generate 5000 repo entries
int numbRes = 5000;
long startCreate = System.currentTimeMillis();
for (int i = 1; i < numbRes; i++) {
// create course and persist as OLATResourceImpl
final int ifin = i;
OLATResourceable resourceable = new OLATResourceable() {
public String getResourceableTypeName() { return CourseModule.getCourseTypeName();}
public Long getResourceableId() {return new Long(ifin);}
};
OLATResource r = resm.createOLATResourceInstance(resourceable);
db.saveObject(r);
// now make a repository entry for this course
RepositoryEntry re = rm.createRepositoryEntryInstance("Florian Gnägi", "Lernen mit OLAT " + i, "yo man description bla bla + i");
re.setDisplayname("JunitTest_RepositoryEntry_" + i);
re.setOlatResource(r);
re.setAccess(RepositoryEntry.ACC_OWNERS_AUTHORS);
if ((i % 2 > 0)) {
re.setCanReference(true);
} else {
re.setCanReference(false);
}
// create security group
SecurityGroup ownerGroup = securityManager.createAndPersistSecurityGroup();
// member of this group may modify member's membership
securityManager.createAndPersistPolicy(ownerGroup, Constants.PERMISSION_ACCESS, ownerGroup);
// members of this group are always authors also
securityManager.createAndPersistPolicy(ownerGroup, Constants.PERMISSION_HASROLE, Constants.ORESOURCE_AUTHOR);
if ((i % 2 > 0)) {
securityManager.addIdentityToSecurityGroup(id1, ownerGroup);
} else {
securityManager.addIdentityToSecurityGroup(id2, ownerGroup);
}
re.setOwnerGroup(ownerGroup);
// save the repository entry
rm.saveRepositoryEntry(re);
// Create course admin policy for owner group of repository entry
// -> All owners of repository entries are course admins
securityManager.createAndPersistPolicy(re.getOwnerGroup(), Constants.PERMISSION_ADMIN, re.getOlatResource());
// flush database and hibernate session cache after 10 records to improve performance
// without this optimization, the first entries will be fast but then the adding new
// entries will slow down due to the fact that hibernate needs to adjust the size of
// the session cache permanently. flushing or transactions won't help since the problem
// is in the session cache.
if (i%2 == 0) {
db.closeSession();
db = DBFactory.getInstance();
}
}
long endCreate = System.currentTimeMillis();
Tracing.logDebug("created " + numbRes + " repo entries in " + (endCreate - startCreate) + "ms", RepositoryManagerTest.class);