Package org.olat.core.commons.persistence

Examples of org.olat.core.commons.persistence.DBQuery


    }
     
    // create query object now from string
    String query = sb.toString();
    DB db = DBFactory.getInstance();
    DBQuery dbq = db.createQuery(query);
   
    // add user attributes
    if (login != null)
      dbq.setString("login", login);

    //   add user properties attributes
    if (userproperties != null && !userproperties.isEmpty()) {
      for (String key : userproperties.keySet()) {
        String value = userproperties.get(key);
        value = makeFuzzyQueryString(value);
        dbq.setString(key + "_value", value.toLowerCase());
      }
    }

    // add named security group names
    if (hasGroups) {
      for (int i = 0; i < groups.length; i++) {
        SecurityGroupImpl group = (SecurityGroupImpl) groups[i]; // need to work with impls
        dbq.setEntity("group_" + i, group);
      }
    }
   
    // add policies
    if (hasPermissionOnResources) {
      for (int i = 0; i < permissionOnResources.length; i++) {
        PermissionOnResourceable permissionOnResource = permissionOnResources[i];
        dbq.setString("permission_" + i, permissionOnResource.getPermission());
        Long id = permissionOnResource.getOlatResourceable().getResourceableId();
        dbq.setLong("resourceId_" + i, (id == null ? 0 : id.longValue()));
        dbq.setString("resourceName_" + i, permissionOnResource.getOlatResourceable().getResourceableTypeName());
      }
    }

    // add authentication providers
    if (hasAuthProviders) {
      for (int i = 0; i < authProviders.length; i++) {
        String authProvider = authProviders[i];
        if (authProvider != null) {
          dbq.setString("authProvider_" + i, authProvider);
        }
        // ignore null auth provider, already set to null in query
      }
    }
   
    // add date restrictions
    if (createdAfter != null) {
      dbq.setDate("createdAfter", createdAfter);
    }
    if (createdBefore != null) {
      dbq.setDate("createdBefore", createdBefore);
    }
    if (status != null) {
      dbq.setInteger("status", status);
    }

    // execute query
    return dbq.list();
  }
View Full Code Here


   * @see org.olat.basesecurity.Manager#isIdentityVisible(java.lang.String)
   */
  public boolean isIdentityVisible(String identityName) {
    if (identityName == null) throw new AssertException("findIdentitybyName: name was null");
    String queryString = "select count(ident) from org.olat.basesecurity.IdentityImpl as ident where ident.name = :identityName and ident.status < :status";
    DBQuery dbq = DBFactory.getInstance().createQuery(queryString);
    dbq.setString("identityName", identityName);
    dbq.setInteger("status", Identity.STATUS_VISIBLE_LIMIT);
    List res = dbq.list();
    Long cntL = (Long) res.get(0);
    return (cntL.longValue() > 0);
  }
View Full Code Here

*/
public class DayOfWeekStatisticManager implements IStatisticManager {

  @Override
  public StatisticResult generateStatisticResult(UserRequest ureq, ICourse course, long courseRepositoryEntryKey) {
    DBQuery dbQuery = DBFactory.getInstance().createQuery("select businessPath,day,value from org.olat.course.statistic.dayofweek.DayOfWeekStat sv "
        + "where sv.resId=:resId");
    dbQuery.setLong("resId", courseRepositoryEntryKey);

    StatisticResult result = new StatisticResult(course, dbQuery.list());
   
    // now sort by user's preferred firstDayOfWeek
    Calendar c = Calendar.getInstance(ureq.getLocale());
    int firstDayOfWeek = c.getFirstDayOfWeek();
   
View Full Code Here

 
  private OLATResource doQueryResourceable(Long resourceableId, String type){
    if (resourceableId == null) resourceableId = OLATResourceImpl.NULLVALUE;

    String s = new String("from org.olat.resource.OLATResourceImpl ori where ori.resName = :resname and ori.resId = :resid");
    DBQuery query = DBFactory.getInstance().createQuery(s);
    query.setString("resname", type);
    query.setLong("resid", resourceableId.longValue());
    query.setCacheable(true);
   
    List resources = query.list();
    // if not found, it is an empty list
    if (resources.size() == 0) return null;
    return (OLATResource)resources.get(0);
  }
View Full Code Here

*/
public class OrgTypeStatisticManager implements IStatisticManager {

  @Override
  public StatisticResult generateStatisticResult(UserRequest ureq, ICourse course, long courseRepositoryEntryKey) {
    DBQuery dbQuery = DBFactory.getInstance().createQuery("select businessPath,orgType,value from org.olat.course.statistic.orgtype.OrgTypeStat sv "
        + "where sv.resId=:resId");
    dbQuery.setLong("resId", courseRepositoryEntryKey);

    return new StatisticResult(course, dbQuery.list());
  }
View Full Code Here

   * @return List of catalog entries that are childern entries of given entry
   */
  public List<CatalogEntry> getChildrenOf(CatalogEntry ce) {
    String sqlQuery = "select cei from org.olat.catalog.CatalogEntryImpl as cei "
      + " where cei.parent = :parent order by cei.name ";
      DBQuery dbQuery = DBFactory.getInstance().createQuery(sqlQuery);
      dbQuery.setEntity("parent", ce);
      // cache this query
      dbQuery.setCacheable(true);
      return dbQuery.list();
  }
View Full Code Here

   * @return List of catalog entries of type CatalogEntry.TYPE_NODE
   */
  public List<CatalogEntry> getAllCatalogNodes() {
    String sqlQuery = "select cei from org.olat.catalog.CatalogEntryImpl as cei "
    + " where cei.type= :type ";
    DBQuery dbQuery = DBFactory.getInstance().createQuery(sqlQuery);
    dbQuery.setInteger("type", CatalogEntry.TYPE_NODE);
    // cache this query
    dbQuery.setCacheable(true);
    return dbQuery.list();
  }
View Full Code Here

   * @return true: entry has at least one child of type node
   */
  public boolean hasChildEntries(CatalogEntry ce, int type) {
    String sqlQuery = "select count(cei) from org.olat.catalog.CatalogEntryImpl as cei "
    + " where cei.parent = :parent AND cei.type= :type ";
    DBQuery dbQuery = DBFactory.getInstance().createQuery(sqlQuery);
    dbQuery.setEntity("parent", ce);
    dbQuery.setInteger("type", type);
    // cache this query
    dbQuery.setCacheable(true);
    List res = dbQuery.list();
    Long cntL = (Long) res.get(0);
    return (cntL.longValue() > 0);
  }
View Full Code Here

   * @return List of catalog entries
   */
  public List getCatalogEntriesReferencing(RepositoryEntry repoEntry) {
    String sqlQuery = "select cei from " + " org.olat.catalog.CatalogEntryImpl as cei " + " ,org.olat.repository.RepositoryEntry as re "
        + " where cei.repositoryEntry = re AND re.key= :reKey ";
    DBQuery dbQuery = DBFactory.getInstance().createQuery(sqlQuery);
    dbQuery.setCacheable(true);
    dbQuery.setLong("reKey", repoEntry.getKey().longValue());
    List resSet = dbQuery.list();
    return resSet;
  }
View Full Code Here

      + ", org.olat.catalog.CatalogEntryImpl as cei "
      + ", org.olat.repository.RepositoryEntry as re "
      + " where cei.repositoryEntry = re "
      + " and re.key= :reKey "
      + " and cei.parent = parent ";
    DBQuery dbQuery = DBFactory.getInstance().createQuery(sqlQuery);
    dbQuery.setCacheable(true);
    dbQuery.setLong("reKey", repoEntry.getKey().longValue());
    List resSet = dbQuery.list();
    return resSet;
  }
View Full Code Here

TOP

Related Classes of org.olat.core.commons.persistence.DBQuery

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.