⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clubtopicimpl.java

📁 特色: 1.今晚在线社区独有的双风格分桢形式 2.社区最多可进行3级分类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * Created on 2005-10-15
 * Last modified on 2006-1-24
 * Powered by GamVan.com
 */
package com.gamvan.club.dao.impl;

import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.gamvan.club.ClubInfo;
import com.gamvan.club.ClubInfoEdit;
import com.gamvan.club.dao.ClubTopicDAO;
import com.gamvan.club.item.ClubContentItem;
import com.gamvan.club.item.ClubContentReItem;
import com.gamvan.club.item.ClubTopicItem;
import com.gamvan.club.item.ClubTopicReItem;
import com.gamvan.conn.ConnClub;

/**
 * 社区帖子的  添加 删除  更新操作内容
 * @author GamVan by 我容易么我
 * Powered by GamVan.com
 */
public class ClubTopicImpl extends ClubTopicItem implements ClubTopicDAO {
    private static final long serialVersionUID = 1L;
    private boolean bea = false;
    private ClubContentImpl ccil = new ClubContentImpl();
    private static final Logger logger = 
    	Logger.getLogger(ClubTopicImpl.class.getName());
    /**
     * 认证以下id不为0的主题, 如果id为-1,则不加限定更新整个表数据
     * @param tid
     * @param reid
     * @return
     */
    public int topicUpdateIsPass(int tid, int reid, boolean ispass){
        int i = 0;
        Session session = ConnClub.getSession();
        Transaction tran = session.beginTransaction();
        StringBuffer hql_0 = new StringBuffer();
        StringBuffer hql_1 = new StringBuffer();
        Query query ;
        try{
            hql_0.append("update ClubTopicReItem set topicIsPass=? ");
            if(reid!=-1){
                hql_0.append(" where topicReID= "+ reid +" ");
            }
            if(reid>0 || reid==-1){
                query = session.createQuery(hql_0.toString())
                .setBoolean(0, ispass);
                i = query.executeUpdate();
            }
            
            hql_1.append("update ClubTopicItem set topicIsPass=? ");
            if(tid!=-1){
                hql_1.append(" where topicID= "+ tid +" ");
            }
            if(tid>0 || tid==-1){
                query = session.createQuery(hql_1.toString())
                .setBoolean(0, ispass);
                i += query.executeUpdate();
            }
            tran.commit();      
        }catch(HibernateException e){
            e.printStackTrace();
        }
        return i;
    }
    
    public int topicUpatePro(int tid, int reid, int pro){
        int i = 0;
        Session session = ConnClub.getSession();
        Transaction tran = session.beginTransaction();
        StringBuffer hql = new StringBuffer();
        int id = 0;
        try{
            if(reid>0){
                id = reid;
                hql.append("update ClubTopicReItem set topicPro=? where topicReID=?");
            }else{
                id = tid;
                hql.append("update ClubTopicItem set topicPro=? where topicID=?");
            }
            Query query = session.createQuery(hql.toString())
            .setInteger(0, pro)
            .setInteger(1, id)
            ;
            i = query.executeUpdate();
            tran.commit();            
        }catch(HibernateException e){
            e.printStackTrace();
        }
        return i;
    }

    public void topicDel(int id) {
        Session session = ConnClub.getSession();
        Transaction tran = session.beginTransaction();
        try{
            /**
             * 级联删除
             */
            ClubTopicItem cti = (ClubTopicItem)session.get(ClubTopicItem.class, new Integer(id));
            cti.setTopicID(id);
            session.delete(cti); 
            tran.commit();
            ccil.contentDel(id);        
        }catch(HibernateException e){
            e.printStackTrace();
        }
    }
    
    public void topicReDel(int id) {
        Session session = ConnClub.getSession();
        Transaction tran = session.beginTransaction();
        try{
            /**
             * 级联删除
             */
            ClubTopicReItem ctri = (ClubTopicReItem)session.get(ClubTopicReItem.class, new Integer(id));
            ctri.setTopicReID(id);
            session.delete(ctri);
            tran.commit();
            
            ccil.setTopicReID(id);
            ccil.contentReDel(id);   
        }catch(HibernateException e){
            e.printStackTrace();
        }
    }
    
    public void topicReDel_topicID(int id) {
        Session session = ConnClub.getSession();
        Transaction tran = session.beginTransaction();
        try{
            /**
             * 级联删除
             */
            ClubTopicReItem ctri = new ClubTopicReItem();
            ctri.setTopicReID(id);
            session.delete(ctri);
            tran.commit(); 
            session.evict(ctri);
            
            ccil.setTopicReID(id);
            ccil.contentReDel(id);   
        }catch(HibernateException e){
            e.printStackTrace();
        }
    }
    
    /*用户的主题*/
    public int userTopicCount(int userid){
        int i = 0;
        Session session = ConnClub.getSession();
        StringBuffer hql = new StringBuffer();
        try{
            hql.append("select count(*) from ClubTopicItem where userID=?");               
            Query query = session.createQuery(hql.toString());
            query.setInteger(0, userid);
            List list = query.list();
            Iterator it = list.iterator();
            Integer results = null;
            while(it.hasNext()){
                results = (Integer) it.next();
                i = results.intValue();
            }
        }catch(HibernateException e){
            e.printStackTrace();
        }
        return i;
    }
    
    public List userTopicList(int userid, int page, int pageNum){
        List list = null;        
        //计算从第几条记录开始读取数据  
        if(page<1)page=1;
        int startRow = pageNum * page - pageNum;
        int endRow  = pageNum;
        Session session = ConnClub.getSession();
        StringBuffer hql = new StringBuffer();
        try{
            hql.append("from ClubTopicItem  where userID=?");
            hql.append(" and topicIsDel=?");
            hql.append(" order by topicID desc");
            Query query = session.createQuery(hql.toString());
            query.setInteger(0, userid);
            query.setInteger(1, topicIsDel);
            query.setFirstResult(startRow);
            query.setMaxResults(endRow);
            list = query.list();           
        }catch(HibernateException e){
            list = null;
        }
        return list;
    }

    /*用户的回复*/
    public int userTopicReCount(int userid){
        int i = 0;
        Session session = ConnClub.getSession();
        StringBuffer hql = new StringBuffer();
        try{
            hql.append("select count(*) from ClubTopicReItem where userID=?");
            hql.append(" and topicIsDel=?");                 
            Query query = session.createQuery(hql.toString());
            query.setInteger(0, userid);
            query.setInteger(1, topicIsDel);
            List list = query.list();
            Iterator it = list.iterator();
            Integer results = null;
            while(it.hasNext()){
                results = (Integer) it.next();
                i = results.intValue();
            }
        }catch(HibernateException e){
            e.printStackTrace();
        }
        return i;
    }
    
    public List userTopicReList(int userid, int page, int pageNum){
        List list = null;        
        //计算从第几条记录开始读取数据  
        if(page<1)page=1;
        int startRow = pageNum * page - pageNum;
        int endRow  = pageNum;
        Session session = ConnClub.getSession();
        StringBuffer hql = new StringBuffer();
        try{
            hql.append("from ClubTopicReItem  where userID=?");
            hql.append(" and topicIsDel=?"); 
            hql.append(" order by topicReID desc");
            Query query = session.createQuery(hql.toString());
            query.setInteger(0, userid);
            query.setInteger(1, topicIsDel);
            query.setFirstResult(startRow);
            query.setMaxResults(endRow);
            list = query.list();           
        }catch(HibernateException e){
            list = null;
        }
        return list;
    }
    
    /**
     * 更新主题
     * @param id
     * 2005-11-7 21:02:42 Made In GamVan
     * @see com.gamvan.club.dao.ClubTopicDAO#topicUpdate(int)
     */
    public void topicUpdate(int id){
        Session session = ConnClub.getSession();
        Transaction tran = session.beginTransaction();
        ClubTopicItem cti = null;
        //ClubContentItem cci = null;
        try{
            cti = (ClubTopicItem) session.load(ClubTopicItem.class, new Integer(id));
            cti.setTopic(topic);
            cti.setTopicList(topicList);
            cti.setTopicMood(topicMood);
            cti.setTopicType(topicType);
            cti.setTopicTypeNum(topicTypeNum);
            cti.setTopicLen(topicLen);
            session.update(cti);
            tran.commit();
            
            //级联更新帖子内容
            ccil.setTopicID(id);
            ccil.setContent(content);
            ccil.setContentCopyRight(contentCopyRight);
            ccil.setContentEmail(contentEmail);
            ccil.setContentImg(contentImg);
            ccil.setContentUrl(contentUrl);
            ccil.setContentUserPen(contentUserPen);
            ccil.contentUpdate(id);
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    
    /**
     * 更新回复
     * @param id
     * 2005-11-7 21:02:55 Made In GamVan
     * @see com.gamvan.club.dao.ClubTopicDAO#topicReUpdate(int)
     */
    public void topicReUpdate(int id){
        Session session = ConnClub.getSession();
        Transaction tran = session.beginTransaction();
        ClubTopicReItem ctri = null;
        try{
            ctri = (ClubTopicReItem) session.load(ClubTopicReItem.class, new Integer(id));
            ctri.setTopic(topic);
            ctri.setTopicList(topicList);
            ctri.setTopicMood(topicMood);
            ctri.setTopicType(topicType);
            ctri.setTopicTypeNum(topicTypeNum);
            ctri.setTopicLen(topicLen);
            session.save(ctri);
            tran.commit();
            //级联更新帖子内容
            ccil.setContent(content);
            ccil.setContentCopyRight(contentCopyRight);
            ccil.setContentEmail(contentEmail);
            ccil.setContentImg(contentImg);
            ccil.setContentUrl(contentUrl);
            ccil.setContentUserPen(contentUserPen);
            ccil.contentReUpdate(id);
        }catch(Exception e){
            e.printStackTrace();
        }
    }
    

    /**
     * 更新主题表topicReID,为回复表最后一条记录的ID,用于排序规则。
     */
    public void topicID_reID(int id){
        //提取回复表最后一片帖子的ID
		ClubInfo ci = new ClubInfo();
        int lastReID = ci.getLastReID();
        Session session = ConnClub.getSession();
        Transaction tran = session.beginTransaction();
        String hql = "";
        try{
	        hql = "update ClubTopicItem set topicReID=? where topicID=?";
	        session.createQuery(hql)
	        .setInteger(0, lastReID)
	        .setInteger(1, id)
	        .executeUpdate();
	        tran.commit();
        }catch(HibernateException e){
            e.printStackTrace();
        } 

    }
    
    
    public void topicUpdateLastInfo(int id, int reid, String sTime, String sUser){
        Session session = ConnClub.getSession();
        Transaction tran = session.beginTransaction();
        String hql = "";
        try{
        hql = "update ClubTopicItem set topicReID=?, topicLastReTime=?, topicLastReUser=? where topicID=?";
            session.createQuery(hql)
            .setInteger(0, reid)
            .setString(1, sTime)
            .setString(2, sUser)
            .setInteger(3, id)
            .executeUpdate();
            tran.commit();
        }catch(HibernateException e){
            e.printStackTrace();
        } 
    }
    
    
    /**
     * 向主题表添加主题和内容
     * @return
     * 2005-11-7 21:01:19 Made In GamVan
     * @see com.gamvan.club.dao.ClubTopicDAO#topicReAdd()
     */
    public ClubTopicItem topicAdd() {
        Session session = ConnClub.getSession();
        ClubTopicItem cti = null;
        ClubContentItem cci = null;
        try{
        	Transaction tran = session.beginTransaction();
            cti = new ClubTopicItem();
            cti.setTopicReID(topicReID);
            cti.setTopicOrder(topicOrder);
            cti.setTopicLayer(topicLayer);
            cti.setTopicTree(topicTree);
            cti.setTopic(topic);
            cti.setUserName(userName);
            cti.setCcID(ccID);
            cti.setCcID2(ccID2);
            cti.setCcID1(ccID1);
            cti.setMoveCCID(moveCCID);
            cti.setTopicList(topicList);
            cti.setTopicMood(topicMood);
            cti.setTopicPro(topicPro);
            cti.setTopicType(topicType);
            cti.setTopicTypeNum(topicTypeNum);
            cti.setTopicAddTime(topicAddTime);
            cti.setTopicAddip(topicAddip);
            cti.setTopicLastReUser(topicLastReUser);
            cti.setTopicLastReTime(topicLastReTime);
            cti.setMoveTime(moveTime);
            cti.setMoveUser(moveUser);
            cti.setTopicViewCount(topicViewCount);
            cti.setTopicReCount(topicViewCount);
            cti.setTopicLen(topicLen);
            cti.setUserID(userID);
            cti.setTopicIsPass(topicIsPass);
            cti.setTopicIsDel(topicIsDel);
            session.save(cti);
            this.topicID = cti.getTopicID();
            tran.commit();
            
            Transaction tran1 = session.beginTransaction();
            cci = new ClubContentItem();
            cci.setTopicID(topicID);
            cci.setContent(content);
            cci.setContentCopyRight(contentCopyRight);
            cci.setContentEmail(contentEmail);
            cci.setContentImg(contentImg);
            cci.setContentUrl(contentUrl);
            cci.setContentUserPen(contentUserPen);
            session.save(cci);
            tran1.commit();
        }catch(HibernateException e){
            cti = null;
            e.printStackTrace();
        }
        return cti;
    }

    /**
     * 向回复表添加主题和内容
     * @return
     * 2005-11-7 21:01:19 Made In GamVan
     * @see com.gamvan.club.dao.ClubTopicDAO#topicReAdd()
     */
    public ClubTopicReItem topicReAdd(){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -