Package org.olat.core.commons.persistence

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


        duration = System.currentTimeMillis() - lastTime.getTime();
      } else {
        duration = currentTime.getTime() - lastTime.getTime();
      }
     
      DB db = DBFactory.getInstanceForClosing();
      if (db!=null && db.isError()) {
        // 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);

    if (resourceInfos!=null && resourceInfos.size()!=0) {
      // this should be the normal case - we do have LoggingResourceables which we can log
      // alongside the log message
     
      // check if we have more than 4 - if we do, issue a log and remove the middle ones
      if (resourceInfos.size()>4) {
        log_.warn("More than 4 resource infos set on a user activity log. Can only have 4. Having: "+resourceInfos.size());
        int diff = resourceInfos.size()-4;
        for(int i=0; i<diff; i++) {
          resourceInfos.remove(3);
        }
      }
     
      // get the target resourceable
      ILoggingResourceable ri = resourceInfos.get(resourceInfos.size()-1);
      logObj.setTargetResourceInfo(ri);
     
      // now set parent - if applicable
      if (resourceInfos.size()>1) {
        ri = resourceInfos.get(resourceInfos.size()-2);
        logObj.setParentResourceInfo(ri);
      }
     
      // and set the grand parent - if applicable
      if (resourceInfos.size()>2) {
        ri = resourceInfos.get(resourceInfos.size()-3);
        logObj.setGrandParentResourceInfo(ri);
      }
     
      // and set the great grand parent - if applicable
      if (resourceInfos.size()>3) {
        ri = resourceInfos.get(resourceInfos.size()-4);
        logObj.setGreatGrandParentResourceInfo(ri);
      }
    }
   
    // fill the remaining fields
    logObj.setBusinessPath(businessPath_);
    logObj.setSourceClass(callingClass.getCanonicalName());
    logObj.setSimpleDuration(-1);
    logObj.setResourceAdminAction(actionType.equals(ActionType.admin)?true:false);
    Locale locale = I18nManager.getInstance().getLocaleOrDefault(identity.getUser().getPreferences().getLanguage());
   
    //prepate the user properties, set them at once
    List<String> tmpUserProperties = new ArrayList<String>(12);
    for(Iterator<String> iterator = userProperties_.iterator(); iterator.hasNext();) {
      tmpUserProperties.add(identity.getUser().getPropertyOrIdentityEnvAttribute(iterator.next(), locale));
    }
    logObj.setUserProperties(tmpUserProperties);
   
    // and store it
    DB db = DBFactory.getInstanceForClosing();
    if (db!=null && db.isError()) {
      // 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 store the following logging action into the loggingtable: "+logObj);
    } else {
View Full Code Here


   */
  private void updateUserLocaleAndLogout(UserRequest ureq, String localeKey) {
    User currUser = ureq.getIdentity().getUser();
    // direct DB calls have to be made here because the
    // user manager is not available in the core
    DB db = DBFactory.getInstance();
    currUser = (User) db.loadObject(currUser);
    currUser.getPreferences().setLanguage(localeKey);
    db.saveObject(currUser);
    DispatcherAction.redirectToDefaultDispatcher(ureq.getHttpResp());
  }
View Full Code Here

    if (rating == null) {
      // Original rating has been deleted in the meantime. Don't delete it again.
      return 0;
    }
    // Delete this rating and finish
    DB db = DBFactory.getInstance();
    db.deleteObject(rating);
    return 1;

  }
View Full Code Here

  /**
   * @see org.olat.core.commons.services.commentAndRating.UserRatingsManager#deleteAllRatings()
   */
  @Override
  public int deleteAllRatings() {
    DB db = DBFactory.getInstance();
    String query;
    Object[] values;
    Type[] types;
    // special query when sub path is null
    if (getOLATResourceableSubPath() == null) {
      query = "from UserRatingImpl where resName=? AND resId=? AND resSubPath is NULL";
      values = new Object[] { getOLATResourceable().getResourceableTypeName(),  getOLATResourceable().getResourceableId() };
      types = new Type[] {Hibernate.STRING, Hibernate.LONG};
    } else {
      query = "from UserRatingImpl where resName=? AND resId=? AND resSubPath=?";
      values = new Object[] { getOLATResourceable().getResourceableTypeName(),  getOLATResourceable().getResourceableId(), getOLATResourceableSubPath() };
      types = new Type[] {Hibernate.STRING, Hibernate.LONG, Hibernate.STRING};
    }
    return db.delete(query, values, types);
  }
View Full Code Here

  public int deleteAllRatingsIgnoringSubPath() {
    // Don't limit to subpath. Ignore if null or not, just delete on the resource
    String query = "from UserRatingImpl where resName=? AND resId=?";
    Object[] values = new Object[] { getOLATResourceable().getResourceableTypeName(),  getOLATResourceable().getResourceableId() };
    Type[] types = new Type[] {Hibernate.STRING, Hibernate.LONG};
    DB db = DBFactory.getInstance();
    return db.delete(query, values, types);   
  }
View Full Code Here

   * @see org.olat.core.commons.services.commentAndRating.UserRatingsManager#reloadRating(org.olat.core.commons.services.commentAndRating.model.UserRating)
   */
  @Override
  public UserRating reloadRating(UserRating rating) {
    try {
      DB db = DBFactory.getInstance();
      return (UserRating) db.loadObject(rating);     
    } catch (Exception e) {
      // Huh, most likely the given object does not exist anymore on the
      // db, probably deleted by someone else
      logWarn("Tried to reload a user rating but got an exception. Probably deleted in the meantime", e);
      return null;
View Full Code Here

      // Original rating has been deleted in the meantime. Don't update it
      return null;
    }
    // Update DB entry
    rating.setRating(newRatingValue);
    DB db = DBFactory.getInstance();
    db.updateObject(rating);
    return rating;
  }
View Full Code Here

  /**
   * @see org.olat.core.commons.services.commentAndRating.UserCommentsManager#reloadComment(org.olat.core.commons.services.commentAndRating.model.UserComment)
   */
  public UserComment reloadComment(UserComment comment) {
    try {
      DB db = DBFactory.getInstance();
      return (UserComment) db.loadObject(comment);     
    } catch (Exception e) {
      // Huh, most likely the given object does not exist anymore on the
      // db, probably deleted by someone else
      logWarn("Tried to reload a user comment but got an exception. Probably deleted in the meantime", e);
      return null;
View Full Code Here

      // Original comment has been deleted in the meantime. Don't update it
      return null;
    }
    // Update DB entry
    comment.setComment(newCommentText);
    DB db = DBFactory.getInstance();
    db.updateObject(comment);
    return comment;
  }
View Full Code Here

    comment = reloadComment(comment);
    if (comment == null) {
      // 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);
      }
    } else {
      // To not delete the replies we have to set the parent to the parent
      // of the original comment for each reply
      for (UserComment reply : replies) {
        reply.setParent(comment.getParent());
        db.updateObject(reply);
      }
    }
    // Now delete this comment and finish
    db.deleteObject(comment);
    return counter+1;
  }
View Full Code Here

TOP

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

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.