use of org.olat.core.commons.persistence.DBQuery in project openolat by klemens.
the class OLATUpgrade_7_1_1 method queryEntries.
public List<RepositoryEntryUpgrade> queryEntries(int firstResult) {
StringBuilder sb = new StringBuilder();
sb.append("select v from ").append(RepositoryEntryUpgrade.class.getName()).append(" v inner join fetch v.olatResource as res order by v.key asc");
DBQuery dbquery = DBFactory.getInstance().createQuery(sb.toString());
dbquery.setFirstResult(firstResult);
dbquery.setMaxResults(REPO_ENTRIES_BATCH_SIZE);
@SuppressWarnings("unchecked") List<RepositoryEntryUpgrade> entries = dbquery.list();
return entries;
}
use of org.olat.core.commons.persistence.DBQuery in project openolat by klemens.
the class OLATUpgrade_7_1_1 method getGroupsOfBGContext.
private List<BusinessGroupUpgrade> getGroupsOfBGContext(BGContextImpl bgContext) {
String q = "select bg from org.olat.upgrade.model.BusinessGroupImpl bg where bg.groupContextKey = :contextKey";
DBQuery query = DBFactory.getInstance().createQuery(q);
query.setLong("contextKey", bgContext.getKey());
@SuppressWarnings("unchecked") List<BusinessGroupUpgrade> groups = query.list();
return groups;
}
use of org.olat.core.commons.persistence.DBQuery in project openolat by klemens.
the class OLATUpgrade_7_1_1 method loadMapChildrenByInternalFK.
// helper to get child not by link, but internal direct link to root-element
private List<PortfolioStructure> loadMapChildrenByInternalFK(PortfolioStructure linkedChildStruct, PortfolioStructure root) {
if (root == null)
return null;
StringBuilder sb = new StringBuilder();
sb.append("select stEl from ").append(EPStructureElement.class.getName()).append(" stEl");
// sb.append(" where stEl.root=:rootEl and stEl.structureElSource=:sourceEl"); // filtered by filterLinkedStructs()
sb.append(" where stEl.root=:rootEl");
DBQuery query = DBFactory.getInstance().createQuery(sb.toString());
query.setEntity("rootEl", root);
// query.setLong("sourceEl", ((EPStructureElement)linkedChildStruct).getStructureElSource());
@SuppressWarnings("unchecked") List<PortfolioStructure> resources = query.list();
return resources;
}
use of org.olat.core.commons.persistence.DBQuery in project openolat by klemens.
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 klemens.
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;
}
}
Aggregations