Search in sources :

Example 1 with DBQuery

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

the class EPArtefactManager method getArtefacts.

/**
 * Used by the indexer to retrieve all the artefacts
 * @param artefactIds List of ids to seek (optional)
 * @param firstResult First position
 * @param maxResults Max number of returned artefacts (0 or below for all)
 * @return
 */
@SuppressWarnings("unchecked")
protected List<AbstractArtefact> getArtefacts(Identity author, List<Long> artefactIds, int firstResult, int maxResults) {
    StringBuilder sb = new StringBuilder();
    sb.append("select artefact from ").append(AbstractArtefact.class.getName()).append(" artefact");
    boolean where = false;
    if (author != null) {
        where = true;
        sb.append(" where artefact.author=:author");
    }
    if (artefactIds != null && !artefactIds.isEmpty()) {
        if (where)
            sb.append(" and ");
        else
            sb.append(" where ");
        sb.append(" artefact.id in (:artefactIds)");
    }
    DBQuery query = dbInstance.createQuery(sb.toString());
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    if (firstResult >= 0) {
        query.setFirstResult(firstResult);
    }
    if (author != null) {
        query.setEntity("author", author);
    }
    if (artefactIds != null && !artefactIds.isEmpty()) {
        query.setParameterList("artefactIds", artefactIds);
    }
    List<AbstractArtefact> artefacts = query.list();
    return artefacts;
}
Also used : AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 2 with DBQuery

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

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 3 with DBQuery

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

the class EPArtefactManager method loadArtefactByKey.

/**
 * Load the artefact by its primary key
 *
 * @param key The primary key
 * @return The artefact or null if nothing found
 */
protected AbstractArtefact loadArtefactByKey(Long key) {
    if (key == null)
        throw new NullPointerException();
    StringBuilder sb = new StringBuilder();
    sb.append("select artefact from ").append(AbstractArtefact.class.getName()).append(" artefact").append(" where artefact=:key");
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setLong("key", key);
    @SuppressWarnings("unchecked") List<AbstractArtefact> artefacts = query.list();
    // if not found, it is an empty list
    if (artefacts.isEmpty())
        return null;
    return artefacts.get(0);
}
Also used : AbstractArtefact(org.olat.portfolio.model.artefacts.AbstractArtefact) DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 4 with DBQuery

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

the class EPStructureManager method getAllReferencesForArtefact.

protected List<PortfolioStructure> getAllReferencesForArtefact(AbstractArtefact artefact) {
    StringBuilder sb = new StringBuilder();
    sb.append("select link.structureElement from ").append(EPStructureToArtefactLink.class.getName()).append(" link").append(" where link.artefact=:artefactEl ");
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setEntity("artefactEl", artefact);
    @SuppressWarnings("unchecked") List<PortfolioStructure> pfList = query.list();
    return pfList;
}
Also used : EPStructureToArtefactLink(org.olat.portfolio.model.structel.EPStructureToArtefactLink) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 5 with DBQuery

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

the class EPStructureManager method countStructureChildren.

/**
 * Number of children
 */
public int countStructureChildren(PortfolioStructure structure) {
    if (structure == null)
        throw new NullPointerException();
    StringBuilder sb = new StringBuilder();
    sb.append("select count(link) from ").append(EPStructureToStructureLink.class.getName()).append(" link").append(" where link.parent=:structureEl");
    DBQuery query = dbInstance.createQuery(sb.toString());
    query.setEntity("structureEl", structure);
    Number count = (Number) query.uniqueResult();
    return count.intValue();
}
Also used : EPStructureToStructureLink(org.olat.portfolio.model.structel.EPStructureToStructureLink) 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