*/
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;