Ejemplo n.º 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;
   }
 }
Ejemplo n.º 2
0
  /**
   * 创建新帖子
   *
   * @param topic
   * @param add_bookmark
   */
  public static void create(TopicBean topic, boolean add_bookmark) {
    try {
      if (topic.getCreateTime() == null) topic.setCreateTime(new Date());
      Session ssn = getSession();
      beginTransaction();
      topic.getUser().getCount().incTopicCount(1);
      topic.getForum().incTopicCount(1);
      topic.getForum().setLastPostTime(new Date());
      topic.getForum().setLastUser(topic.getUser());
      topic.getForum().setLastUsername(topic.getUsername());
      topic.getForum().setLastTopic(topic);

      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(tag_name);
          ssn.save(tag);
          tag_count++;
        }
      }

      ssn.save(topic);
      if (add_bookmark) {
        BookmarkBean bmb = new BookmarkBean();
        bmb.setOwner(topic.getUser());
        bmb.setSite(topic.getSite());
        bmb.setCreateTime(new Date());
        bmb.setParentId(topic.getId());
        bmb.setParentType(_BeanBase.TYPE_BBS);
        bmb.setTitle(topic.getTitle());
        ssn.save(bmb);
      }
      commit();
    } catch (HibernateException e) {
      rollback();
      throw e;
    }
  }