Search in sources :

Example 31 with DBQuery

use of org.olat.core.commons.persistence.DBQuery in project openolat by klemens.

the class EPArtefactManager method getArtefactPoolForUser.

protected List<AbstractArtefact> getArtefactPoolForUser(Identity ident) {
    long start = System.currentTimeMillis();
    StringBuilder sb = new StringBuilder();
    sb.append("select artefact from ").append(AbstractArtefact.class.getName()).append(" artefact").append(" where author=:author");
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setEntity("author", ident);
    @SuppressWarnings("unchecked") List<AbstractArtefact> artefacts = query.list();
    if (artefacts.isEmpty())
        return null;
    long duration = System.currentTimeMillis() - start;
    if (isLogDebugEnabled())
        logDebug("loading the full artefact pool took " + duration + "ms");
    return artefacts;
}
Also used : AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 32 with DBQuery

use of org.olat.core.commons.persistence.DBQuery in project openolat by klemens.

the class EPNotificationManager method getRatingNotifications.

private List<EPRatingNotification> getRatingNotifications(List<Long> mapKey, Date compareDate) {
    if (mapKey == null || mapKey.isEmpty()) {
        return Collections.emptyList();
    }
    StringBuilder sb = new StringBuilder();
    sb.append("select notification from ").append(EPRatingNotification.class.getName()).append(" as notification").append(" inner join fetch notification.author").append(" where notification.creationDate>=:currentDate and notification.mapKey in (:mapKey)");
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setDate("currentDate", compareDate);
    query.setParameterList("mapKey", mapKey);
    @SuppressWarnings("unchecked") List<EPRatingNotification> notifications = query.list();
    return notifications;
}
Also used : EPRatingNotification(org.olat.portfolio.model.notification.EPRatingNotification) DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 33 with DBQuery

use of org.olat.core.commons.persistence.DBQuery in project openolat by klemens.

the class EPStructureManager method loadStructureChildren.

/**
 * @param structure
 * @param firstResult
 * @param maxResults
 * @return
 */
protected List<PortfolioStructure> loadStructureChildren(PortfolioStructure structure, int firstResult, int maxResults) {
    if (structure == null)
        throw new NullPointerException();
    StringBuilder sb = new StringBuilder();
    sb.append("select link.child from ").append(EPStructureToStructureLink.class.getName()).append(" link").append(" where link.parent=:structureEl order by link.order");
    DBQuery query = dbInstance.createQuery(sb.toString());
    if (firstResult > 0) {
        query.setFirstResult(firstResult);
    }
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    query.setEntity("structureEl", structure);
    @SuppressWarnings("unchecked") List<PortfolioStructure> resources = query.list();
    return resources;
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) EPStructureToStructureLink(org.olat.portfolio.model.structel.EPStructureToStructureLink) DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 34 with DBQuery

use of org.olat.core.commons.persistence.DBQuery in project openolat by klemens.

the class EPStructureManager method countArtefactsRecursively.

/**
 * Count all artefacts (links) in a map
 */
protected int countArtefactsRecursively(PortfolioStructure structure) {
    // return countArtefactsRecursively(structure, 0);
    StringBuilder sb = new StringBuilder();
    sb.append("select count(link) from ").append(EPStructureToArtefactLink.class.getName()).append(" link").append(" inner join link.structureElement structure ").append(" inner join structure.rootMap root").append(" where root=:structureEl");
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setEntity("structureEl", structure);
    Number count = (Number) query.uniqueResult();
    return count.intValue();
}
Also used : EPStructureToArtefactLink(org.olat.portfolio.model.structel.EPStructureToArtefactLink) DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 35 with DBQuery

use of org.olat.core.commons.persistence.DBQuery in project openolat by klemens.

the class RepositoryManager method countByTypeLimitAccess.

/**
 * Count by type, limit by role accessability.
 * @param restrictedType
 * @param roles
 * @return Number of repo entries
 */
public int countByTypeLimitAccess(String restrictedType, int restrictedAccess) {
    StringBuilder query = new StringBuilder(400);
    query.append("select count(*) from" + " org.olat.repository.RepositoryEntry v, " + " org.olat.resource.OLATResourceImpl res " + " where v.olatResource = res and res.resName= :restrictedType and v.access >= :restrictedAccess ");
    DBQuery dbquery = dbInstance.createQuery(query.toString());
    dbquery.setString("restrictedType", restrictedType);
    dbquery.setInteger("restrictedAccess", restrictedAccess);
    dbquery.setCacheable(true);
    return ((Long) dbquery.list().get(0)).intValue();
}
Also used : DBQuery(org.olat.core.commons.persistence.DBQuery)

Aggregations

DBQuery (org.olat.core.commons.persistence.DBQuery)108 EPStructureToArtefactLink (org.olat.portfolio.model.structel.EPStructureToArtefactLink)12 AbstractArtefact (org.olat.portfolio.model.artefacts.AbstractArtefact)10 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)10 Calendar (java.util.Calendar)8 IdentityImpl (org.olat.basesecurity.IdentityImpl)6 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 DB (org.olat.core.commons.persistence.DB)4 Publisher (org.olat.core.commons.services.notifications.Publisher)4 Tag (org.olat.core.commons.services.tagging.model.Tag)4 Identity (org.olat.core.id.Identity)4 EPStructureToStructureLink (org.olat.portfolio.model.structel.EPStructureToStructureLink)4 EPStructuredMap (org.olat.portfolio.model.structel.EPStructuredMap)4 EPStructuredMapTemplate (org.olat.portfolio.model.structel.EPStructuredMapTemplate)4 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 StringTokenizer (java.util.StringTokenizer)2