Package org.olat.core.commons.persistence

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


        // then we would run into an ERROR when we'd do more with this DB
        // hence we just issue a log.info here with the details
        //@TODO: lower to log_.info once we checked that it doesn't occur very often (best for 6.4)
        log_.warn("log: DB is in Error state therefore the UserActivityLoggerImpl cannot update the simpleDuration of log_id "+lastLogObj.getKey()+" with value "+duration+", loggingObject: "+lastLogObj);
      } else {
        DBQuery update = DBFactory.getInstance().createQuery(
            "update org.olat.core.logging.activity.LoggingObject set simpleDuration = :duration where log_id = :logid");
        update.setLong("duration", duration);
        update.setLong("logid", lastLogObj.getKey());
        // we have to do FlushMode.AUTO (which is the default anyway)
        update.executeUpdate(FlushMode.AUTO);
      }
    }
   
    // store the current logging object in the session - for duration calculation at next log
    session_.putEntry(USESS_KEY_USER_ACTIVITY_LOGGING_LAST_LOG, logObj);
View Full Code Here


  /**
   * @see org.olat.core.commons.services.commentAndRating.UserRatingsManager#calculateRatingAverage()
   */
  @Override
  public Float calculateRatingAverage() {
    DBQuery query;
    if (getOLATResourceableSubPath() == null) {
      // special query when sub path is null
      query = DBFactory
          .getInstance()
          .createQuery(
              "select avg(rating) from UserRatingImpl where resName=:resname AND resId=:resId AND resSubPath is NULL");
    } else {
      query = DBFactory
          .getInstance()
          .createQuery(
              "select avg(rating) from UserRatingImpl where resName=:resname AND resId=:resId AND resSubPath=:resSubPath");
      query.setString("resSubPath", getOLATResourceableSubPath());
    }
    query.setString("resname", getOLATResourceable()
        .getResourceableTypeName());
    query.setLong("resId", getOLATResourceable().getResourceableId());
    query.setCacheable(true);
    //
    List results = query.list();
    Double average = (Double) query.list().get(0);
    // When no ratings are found, a null value is returned!
    if (average == null) return Float.valueOf(0);
    else return average.floatValue();     
  }
View Full Code Here

  /**
   * @see org.olat.core.commons.services.commentAndRating.UserRatingsManager#countRatings()
   */
  @Override
  public Long countRatings() {
    DBQuery query;
    if (getOLATResourceableSubPath() == null) {
      // special query when sub path is null
      query = DBFactory
          .getInstance()
          .createQuery(
              "select count(*) from UserRatingImpl where resName=:resname AND resId=:resId AND resSubPath is NULL");
    } else {
      query = DBFactory
          .getInstance()
          .createQuery(
              "select count(*) from UserRatingImpl where resName=:resname AND resId=:resId AND resSubPath=:resSubPath");
      query.setString("resSubPath", getOLATResourceableSubPath());
    }
    query.setString("resname", getOLATResourceable()
        .getResourceableTypeName());
    query.setLong("resId", getOLATResourceable().getResourceableId());
    query.setCacheable(true);
    //
    Long count = (Long) query.list().get(0);
    return count;
  }
View Full Code Here

   *
   * @see org.olat.core.commons.services.commentAndRating.UserRatingsManager#getRating(org.olat.core.id.Identity)
   */
  @Override
  public UserRating getRating(Identity identity) {
    DBQuery query;
    if (getOLATResourceableSubPath() == null) {
      // special query when sub path is null
      query = DBFactory
          .getInstance()
          .createQuery(
              "select userRating from UserRatingImpl as userRating where creator=:creator AND resName=:resname AND resId=:resId AND resSubPath is NULL ");
    } else {
      query = DBFactory
          .getInstance()
          .createQuery(
              "select userRating from UserRatingImpl as userRating where creator=:creator AND resName=:resname AND resId=:resId AND resSubPath=:resSubPath");
      query.setString("resSubPath", getOLATResourceableSubPath());
    }
    query.setString("resname", getOLATResourceable()
        .getResourceableTypeName());
    query.setLong("resId", getOLATResourceable().getResourceableId());
    query.setEntity("creator", identity);
    query.setCacheable(true);
    //
    List<UserRating> results = query.list();
    if (results.size() == 0) return null;   
    return results.get(0);
  }
View Full Code Here

  /**
   * @see org.olat.core.commons.services.commentAndRating.UserCommentsManager#countComments()
   */
  @Override
  public Long countComments() {
    DBQuery query;
    if (getOLATResourceableSubPath() == null) {
      // special query when sub path is null
      query = DBFactory
          .getInstance()
          .createQuery(
              "select count(*) from UserCommentImpl where resName=:resname AND resId=:resId AND resSubPath is NULL");
    } else {
      query = DBFactory
          .getInstance()
          .createQuery(
              "select count(*) from UserCommentImpl where resName=:resname AND resId=:resId AND resSubPath=:resSubPath");
      query.setString("resSubPath", getOLATResourceableSubPath());
    }
    query.setString("resname", getOLATResourceable()
        .getResourceableTypeName());
    query.setLong("resId", getOLATResourceable().getResourceableId());
    query.setCacheable(true);
    //
    Long count = (Long) query.list().get(0);
    return count;
  }
View Full Code Here

  /**
   * @see org.olat.core.commons.services.commentAndRating.UserCommentsManager#getComments()
   */
  @Override
  public List<UserComment> getComments() {
    DBQuery query;
    if (getOLATResourceableSubPath() == null) {
      // special query when sub path is null
      query = DBFactory
          .getInstance()
          .createQuery(
              "select comment from UserCommentImpl as comment where resName=:resname AND resId=:resId AND resSubPath is NULL");
    } else {
      query = DBFactory
          .getInstance()
          .createQuery(
              "select comment from UserCommentImpl as comment where resName=:resname AND resId=:resId AND resSubPath=:resSubPath");
      query.setString("resSubPath", getOLATResourceableSubPath());
    }
    query.setString("resname", getOLATResourceable()
        .getResourceableTypeName());
    query.setLong("resId", getOLATResourceable().getResourceableId());
    query.setCacheable(true);
    //
    List<UserComment> results = query.list();
    return results;
  }
View Full Code Here

      // Original comment has been deleted in the meantime. Don't delete it again.
      return 0;
    }
    DB db = DBFactory.getInstance();
    // First deal with all direct replies
    DBQuery query = db.createQuery("select comment from UserCommentImpl as comment where parent=:parent");
    query.setEntity("parent", comment);
    List<UserComment> replies = query.list();
    if (deleteReplies) {
      // Since we have a many-to-one we first have to recursively delete
      // the replies to prevent foreign key constraints
      for (UserComment reply : replies) {
        counter += deleteComment(reply, true);
View Full Code Here

    return INSTANCE;
  }
 
  LockImpl findLock(String asset) {
    Tracing.logInfo("findLock: "+asset+" START", getClass());
    DBQuery q = DBFactory.getInstance().createQuery(
        "select alock from org.olat.commons.coordinate.cluster.lock.LockImpl as alock inner join fetch alock.owner where alock.asset = :asset");
    q.setParameter("asset", asset);
    List res = q.list();
    if (res.size() == 0) {
      Tracing.logInfo("findLock: null END", getClass());
      return null;
    } else {
      Tracing.logInfo("findLock: "+res.get(0)+" END", getClass());
View Full Code Here

  }
 
  @SuppressWarnings("unchecked")
  List<LockImpl> getAllLocks() {
    Tracing.logInfo("getAllLocks START", getClass());
    DBQuery q = DBFactory.getInstance().createQuery(
        "select alock from org.olat.commons.coordinate.cluster.lock.LockImpl as alock inner join fetch alock.owner");
    List<LockImpl> res = q.list();
    Tracing.logInfo("getAllLocks END. res.length:"+ (res==null ? "null" : res.size()), getClass());
    return res;
  }
View Full Code Here

    }
    if (end != null) {
      query = query.concat(" AND (v.creationDate < :createdBefore)");
    }

    DBQuery dbQuery = DBFactory.getInstance().createQuery(query);
    dbQuery.setBoolean("resAdminAction", resourceAdminAction);
    dbQuery.setString("resId", Long.toString(resourceableId));
    if (begin != null) {
      dbQuery.setDate("createdAfter", begin);
    }
    if (end != null) {
      Calendar cal = Calendar.getInstance();
      cal.setTime(end);
      cal.add(Calendar.DAY_OF_MONTH, 1);
      end = cal.getTime();
      dbQuery.setDate("createdBefore", end);
    }

    List queryResult = dbQuery.list();
    result.append(logLineConverter_.getCSVHeader());
    result.append(LINE_SEPARATOR);
   
    for (Object loggingObject : queryResult) {
      result.append(logLineConverter_.getCSVRow((LoggingObject)loggingObject, anonymize, resourceableId ));
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.