Search in sources :

Example 36 with DBQuery

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;
}
Also used : RepositoryEntryUpgrade(org.olat.upgrade.model.RepositoryEntryUpgrade) DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 37 with DBQuery

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;
}
Also used : BusinessGroupUpgrade(org.olat.upgrade.model.BusinessGroupUpgrade) DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 38 with DBQuery

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;
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) DBQuery(org.olat.core.commons.persistence.DBQuery)

Example 39 with DBQuery

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;
}
Also used : BGContextImpl(org.olat.upgrade.model.BGContextImpl) DBQuery(org.olat.core.commons.persistence.DBQuery) DB(org.olat.core.commons.persistence.DB)

Example 40 with DBQuery

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;
    }
}
Also used : HashMap(java.util.HashMap) Calendar(java.util.Calendar) DBQuery(org.olat.core.commons.persistence.DBQuery)

Aggregations

DBQuery (org.olat.core.commons.persistence.DBQuery)108 EPStructureToArtefactLink (org.olat.portfolio.model.structel.EPStructureToArtefactLink)12 AbstractArtefact (org.olat.portfolio.model.artefacts.AbstractArtefact)10 PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)10 Calendar (java.util.Calendar)8 IdentityImpl (org.olat.basesecurity.IdentityImpl)6 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 DB (org.olat.core.commons.persistence.DB)4 Publisher (org.olat.core.commons.services.notifications.Publisher)4 Tag (org.olat.core.commons.services.tagging.model.Tag)4 Identity (org.olat.core.id.Identity)4 EPStructureToStructureLink (org.olat.portfolio.model.structel.EPStructureToStructureLink)4 EPStructuredMap (org.olat.portfolio.model.structel.EPStructuredMap)4 EPStructuredMapTemplate (org.olat.portfolio.model.structel.EPStructuredMapTemplate)4 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 StringTokenizer (java.util.StringTokenizer)2