Exemple #1
0
 /**
  * 修改帖子
  *
  * @param topic
  */
 public static void update(TopicBean topic, boolean updateTags) {
   try {
     beginTransaction();
     if (updateTags) {
       TagDAO.deleteTagByRefId(topic.getId(), DiaryBean.TYPE_BBS);
       List tags = topic.getKeywords();
       if (tags != null && tags.size() > 0) {
         int tag_count = 0;
         for (int i = 0; i < tags.size(); i++) {
           if (tag_count >= MAX_TAG_COUNT) break;
           String tag_name = (String) tags.get(i);
           if (tag_name.getBytes().length > MAX_TAG_LENGTH) continue;
           TagBean tag = new TagBean();
           tag.setSite(topic.getSite());
           tag.setRefId(topic.getId());
           tag.setRefType(DiaryBean.TYPE_BBS);
           tag.setName((String) tags.get(i));
           topic.getTags().add(tag);
           tag_count++;
         }
       }
     }
     commit();
   } catch (HibernateException e) {
     rollback();
     throw e;
   }
 }
Exemple #2
0
  /**
   * 删除帖子
   *
   * @param topic
   * @throws SQLException
   * @throws IOException
   */
  public static void delete(TopicOutlineBean topic) throws Exception {
    if (topic == null) return;
    Session ssn = getSession();
    try {
      beginTransaction();
      // 论坛的帖子数减一
      topic.getForum().incTopicCount(-1);
      // 论坛的最后回帖
      if (topic.getForum().getLastTopic() != null
          && topic.getForum().getLastTopic().getId() == topic.getId()) {
        topic.getForum().setLastTopic(null);
        topic.getForum().setLastPostTime(null);
        topic.getForum().setLastUsername(null);
        topic.getForum().setLastUser(null);
      }
      topic.getUser().getCount().incTopicCount(-1);

      List rpls = topic.getReplies();
      for (int i = rpls.size() - 1; i >= 0; i--) {
        TopicReplyBean rbean = (TopicReplyBean) rpls.get(i);
        if (rbean.getUser() != null) rbean.getUser().getCount().incTopicReplyCount(-1);
      }

      ssn.delete(topic);

      // 删除标签
      TagDAO.deleteTagByRefId(topic.getId(), TagBean.TYPE_BBS);

      // 删除附件
      FCKUploadFileDAO.deleteFilesByRef(
          ssn, topic.getSite().getId(), topic.getId(), DiaryBean.TYPE_BBS);

      commit();
    } catch (HibernateException e) {
      rollback();
      throw e;
    }
  }