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();
}
use of org.olat.core.commons.persistence.DBQuery in project OpenOLAT by OpenOLAT.
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;
}
use of org.olat.core.commons.persistence.DBQuery in project OpenOLAT by OpenOLAT.
the class EPStructureManager method loadOlatResourceFromStructureElByKey.
public OLATResource loadOlatResourceFromStructureElByKey(Long key) {
if (key == null)
throw new NullPointerException();
StringBuilder sb = new StringBuilder();
sb.append("select element.olatResource from ").append(EPStructureElement.class.getName()).append(" element").append(" where element.key=:key or element.olatResource.resId=:key ");
DBQuery query = dbInstance.createQuery(sb.toString());
query.setLong("key", key);
@SuppressWarnings("unchecked") List<OLATResource> resources = query.list();
// if not found, it is an empty list
if (resources.isEmpty())
return null;
return resources.get(0);
}
use of org.olat.core.commons.persistence.DBQuery in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
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;
}
Aggregations