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;
}
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;
}
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);
}
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;
}
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();
}
Aggregations