use of org.olat.core.commons.persistence.DBQuery in project openolat by klemens.
the class EPStructureManager method getOpenStructuredMapAfterDeadline.
protected List<PortfolioStructureMap> getOpenStructuredMapAfterDeadline() {
StringBuilder sb = new StringBuilder();
sb.append("select map from ").append(EPStructuredMap.class.getName()).append(" as map");
sb.append(" where (map.status is null or not(map.status = 'closed'))").append(" and map.deadLine<:currentDate");
DBQuery query = dbInstance.createQuery(sb.toString());
query.setDate("currentDate", new Date());
@SuppressWarnings("unchecked") List<PortfolioStructureMap> maps = query.list();
return maps;
}
use of org.olat.core.commons.persistence.DBQuery in project openolat by klemens.
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();
}
use of org.olat.core.commons.persistence.DBQuery in project openolat by klemens.
the class EPStructureManager method isTemplateInUse.
public boolean isTemplateInUse(PortfolioStructureMap template, OLATResourceable targetOres, String targetSubPath, String targetBusinessPath) {
StringBuilder sb = new StringBuilder();
sb.append("select count(map) from ").append(EPStructuredMap.class.getName()).append(" map").append(" where map.structuredMapSource=:template");
if (targetOres != null) {
sb.append(" and map.targetResource.resourceableId=:resourceId").append(" and map.targetResource.resourceableTypeName=:resourceType");
}
if (targetSubPath != null) {
sb.append(" and map.targetResource.subPath=:subPath");
}
if (targetBusinessPath != null) {
sb.append(" and map.targetResource.businessPath=:businessPath");
}
DBQuery query = dbInstance.createQuery(sb.toString());
query.setEntity("template", template);
if (targetOres != null) {
query.setLong("resourceId", targetOres.getResourceableId());
query.setString("resourceType", targetOres.getResourceableTypeName());
}
if (targetSubPath != null) {
query.setString("subPath", targetSubPath);
}
if (targetBusinessPath != null) {
query.setString("businessPath", targetBusinessPath);
}
Number count = (Number) query.uniqueResult();
return count.intValue() > 0;
}
use of org.olat.core.commons.persistence.DBQuery in project openolat by klemens.
the class EPStructureManager method getArtefacts.
/**
* Return the list of artefacts glued to this structure element
* @param structure
* @param firstResult
* @param maxResults
* @return
*/
public List<AbstractArtefact> getArtefacts(PortfolioStructure structure, int firstResult, int maxResults) {
StringBuilder sb = new StringBuilder();
sb.append("select link.artefact from ").append(EPStructureToArtefactLink.class.getName()).append(" link").append(" where link.structureElement.key=:structureElKey order by link.order");
DBQuery query = dbInstance.createQuery(sb.toString());
query.setLong("structureElKey", structure.getKey());
if (firstResult > 0) {
query.setFirstResult(firstResult);
}
if (maxResults > 0) {
query.setMaxResults(maxResults);
}
@SuppressWarnings("unchecked") List<AbstractArtefact> artefacts = query.list();
return artefacts;
}
use of org.olat.core.commons.persistence.DBQuery in project openolat by klemens.
the class EPStructureManager method isArtefactInStructure.
protected boolean isArtefactInStructure(AbstractArtefact artefact, PortfolioStructure structure) {
StringBuilder sb = new StringBuilder();
sb.append("select link.key from ").append(EPStructureToArtefactLink.class.getName()).append(" link").append(" where link.structureElement=:structureEl and link.artefact=:artefact");
DBQuery query = dbInstance.createQuery(sb.toString());
query.setEntity("structureEl", structure);
query.setEntity("artefact", artefact);
@SuppressWarnings("unchecked") List<Long> key = query.list();
return key.size() == 1 ? true : false;
}
Aggregations