use of org.olat.core.commons.persistence.DBQuery in project OpenOLAT by OpenOLAT.
the class OLATUpgrade_7_1_1 method countPortfolioTemplates.
private int countPortfolioTemplates() {
StringBuilder sb = new StringBuilder();
sb.append("select count(stEl) from ").append(EPStructureElement.class.getName()).append(" stEl");
sb.append(" where stEl.class in (" + EPStructuredMapTemplate.class.getName() + ")");
DBQuery query = DBFactory.getInstance().createQuery(sb.toString());
Number count = (Number) query.uniqueResult();
return count.intValue();
}
use of org.olat.core.commons.persistence.DBQuery in project OpenOLAT by OpenOLAT.
the class OLATUpgrade_7_1_1 method findBGContextsForResource.
private List<BGContextImpl> findBGContextsForResource(OLATResource resource, boolean defaultContexts, boolean nonDefaultContexts) {
DB db = DBFactory.getInstance();
StringBuilder q = new StringBuilder();
q.append(" select context from org.olat.group.context.BGContextImpl as context,");
q.append(" org.olat.group.context.BGContext2Resource as bgcr");
q.append(" where bgcr.resource = :resource");
q.append(" and bgcr.groupContext = context");
boolean checkDefault = defaultContexts != nonDefaultContexts;
if (checkDefault) {
q.append(" and context.defaultContext = :isDefault");
}
DBQuery query = db.createQuery(q.toString());
query.setEntity("resource", resource);
if (checkDefault) {
query.setBoolean("isDefault", defaultContexts ? true : false);
}
@SuppressWarnings("unchecked") List<BGContextImpl> contexts = query.list();
return contexts;
}
use of org.olat.core.commons.persistence.DBQuery in project OpenOLAT by OpenOLAT.
the class OLATUpgrade_8_1_0 method getLaunchProperties.
private Set<SimpleProp> getLaunchProperties() {
try {
StringBuilder query = new StringBuilder();
query.append("select p.resourceTypeId, p.identity.key, p.name, p.stringValue from ").append(Property.class.getName()).append(" as p ");
query.append(" where p.resourceTypeName='CourseModule' and p.name in ('initialCourseLaunchDate','recentCourseLaunchDate')");
DBQuery dbQuery = dbInstance.createQuery(query.toString());
@SuppressWarnings("unchecked") List<Object[]> props = dbQuery.list();
Calendar cal = Calendar.getInstance();
Map<SimpleProp, SimpleProp> simpleProps = new HashMap<SimpleProp, SimpleProp>((2 * props.size()) + 1);
for (Object[] prop : props) {
SimpleProp simpleProp = new SimpleProp();
simpleProp.resourceId = (Long) prop[0];
simpleProp.identityKey = (Long) prop[1];
if (simpleProps.containsKey(simpleProp)) {
simpleProp = simpleProps.get(simpleProp);
}
String name = (String) prop[2];
try {
long time = Long.valueOf((String) prop[3]);
cal.setTimeInMillis(time);
if (PROPERTY_INITIAL_LAUNCH_DATE.equals(name)) {
simpleProp.initialLaunch = cal.getTime();
} else if (PROPERTY_RECENT_LAUNCH_DATE.equals(name)) {
simpleProp.recentLaunch = cal.getTime();
}
simpleProps.put(simpleProp, simpleProp);
} catch (Exception e) {
log.error("", e);
}
}
return simpleProps.keySet();
} catch (Exception e) {
log.error("", e);
return null;
}
}
use of org.olat.core.commons.persistence.DBQuery in project OpenOLAT by OpenOLAT.
the class OLATUpgrade_8_1_0 method getAssessmentPublishers.
private List<Publisher> getAssessmentPublishers() {
StringBuilder sb = new StringBuilder();
sb.append("select pub from notipublisher pub where pub.resName='AssessmentManager' and type='AssessmentManager'");
DBQuery query = dbInstance.createQuery(sb.toString());
@SuppressWarnings("unchecked") List<Publisher> res = query.list();
return res;
}
use of org.olat.core.commons.persistence.DBQuery in project OpenOLAT by OpenOLAT.
the class CollaborationManagerImpl method lookupFolderAccess.
@Override
public Long lookupFolderAccess(OLATResourceable ores) {
StringBuilder query = new StringBuilder();
query.append("select prop.longValue from ").append(Property.class.getName()).append(" as prop where ").append(" prop.category='").append(PROP_CAT_BG_COLLABTOOLS).append("'").append(" and prop.resourceTypeName='").append(ores.getResourceableTypeName()).append("'").append(" and prop.resourceTypeId=").append(ores.getResourceableId()).append(" and prop.name='").append(KEY_FOLDER_ACCESS).append("'").append(" and prop.identity is null and prop.grp is null");
DBQuery dbquery = DBFactory.getInstance().createQuery(query.toString());
dbquery.setCacheable(true);
@SuppressWarnings("unchecked") List<Long> props = dbquery.list();
if (props.isEmpty()) {
return null;
} else {
return props.get(0);
}
}
Aggregations