use of org.olat.core.commons.persistence.DBQuery in project openolat by klemens.
the class EPStructureManager method getStructureElements.
protected List<PortfolioStructure> getStructureElements(int firstResult, int maxResults, ElementType... types) {
StringBuilder sb = new StringBuilder();
sb.append("select stEl from ").append(EPStructureElement.class.getName()).append(" stEl");
sb.append(" where type(stEl) in (");
boolean first = true;
for (ElementType type : types) {
if (first)
first = false;
else
sb.append(",");
sb.append(getImplementation(type).getName());
}
sb.append(")");
DBQuery query = dbInstance.createQuery(sb.toString());
if (firstResult > 0) {
query.setFirstResult(firstResult);
}
if (maxResults > 0) {
query.setMaxResults(maxResults);
}
@SuppressWarnings("unchecked") List<PortfolioStructure> pStructs = query.list();
return pStructs;
}
use of org.olat.core.commons.persistence.DBQuery in project openolat by klemens.
the class EPStructureManager method countArtefacts.
/**
* Return the number of artefacts hold by a structure element
* @param structure
* @return
*/
public int countArtefacts(PortfolioStructure structure) {
StringBuilder sb = new StringBuilder();
sb.append("select count(link) from ").append(EPStructureToArtefactLink.class.getName()).append(" link").append(" where link.structureElement=:structureEl");
DBQuery query = dbInstance.createQuery(sb.toString());
query.setEntity("structureEl", structure);
Number count = (Number) query.uniqueResult();
return count.intValue();
}
use of org.olat.core.commons.persistence.DBQuery in project openolat by klemens.
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 klemens.
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 klemens.
the class EPArtefactManager method isArtefactClosed.
protected boolean isArtefactClosed(AbstractArtefact artefact) {
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.root rootStructure").append(" where link.artefact=:artefact and rootStructure.status='closed'");
DBQuery query = dbInstance.createQuery(sb.toString());
query.setEntity("artefact", artefact);
Number count = (Number) query.uniqueResult();
return count.intValue() > 0;
}
Aggregations