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

📄 dbtopicfactory.java

📁 bbs struts
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                pstm.close();
            }
            catch (Exception ex) {
                logger.error("关闭 pstm 失败 error : " + ex.getMessage());
            }
            try {
                conn.close();
            }
            catch (Exception ex) {
                logger.error("关闭数据库连接失败 error : " +ex.getMessage());
            }
        }
        return newTopic;
    }

    /**
     * 更新主题内容
     */
    public void editTopic(Topic topic){
        Connection conn = DBConnectionManager.getInstance().getConnection();
        PreparedStatement pstm = null;
        Timer timer = new TimerExpress("yyyy-MM-dd HH:mm:ss");
        try {
            pstm = conn.prepareStatement(UP_TOPIC);
            pstm.setString(1,CodeFilter.htmlEncode(topic.getTopicMood()+topic.getTopicTitle()));
            //StringBuffer stringBuffer = new StringBuffer();
            String topicContent = topic.getTopicContent();
            topicContent = topicContent + "\n此帖子于[ "+timer.getNowDate()+" ]被修改过";
            logger.info("修改后的topicConetent为 : " + topicContent);
            pstm.setString(2,CodeFilter.htmlEncode(topicContent));
            pstm.setInt(3,topic.getTopicId());
            pstm.executeUpdate();
        }
        catch (Exception ex) {
            logger.error("插入帖子失败 : " + ex.getMessage());
        }
        finally {
            try {
                pstm.close();
            }
            catch (Exception ex) {
                logger.error("关闭 pstm 失败 error : " + ex.getMessage());
            }
            try {
                conn.close();
            }
            catch (Exception ex) {
                logger.error("关闭数据库连接失败 error : " +ex.getMessage());
            }
        }
    }

    /**
     * 最新的主题
     */
    public Topic listNewTopic(int boaId){
        Connection conn = DBConnectionManager.getInstance().getConnection();
        PreparedStatement pstm = null;
        ResultSet rs = null;
        Topic topic = new DBTopic();
        try {
            pstm = conn.prepareStatement(NEWEST_TOPIC);
            pstm.setInt(1,boaId);
            rs = pstm.executeQuery();
            //当指针有数据时
            if(rs.next()){
                topic.setIsTopic(true);
                topic.setTopicId(rs.getInt("topicId"));
                topic.setTopicTitle(rs.getString("topicTitle"));
                topic.setTopicContent(rs.getString("topicContent"));
                topic.setTopicAuthor(rs.getString("topicAuthor"));
                topic.setTopicBoaId(rs.getInt("topicBoaId"));
                topic.setTopicHits(rs.getInt("topicHits"));
                topic.setTopicPubTime(rs.getString("topicPubTime"));
                topic.setTopicIp(rs.getString("topicIp"));
                topic.setIsSuccess(true);
            }
            /*else{
                topic.setIsTopic(false);
            }*/
        }
        catch (Exception ex) {
            logger.info("列出最新数据失败 : " + ex.getMessage());
        }
        finally {
            try {
                pstm.close();
            }
            catch (Exception ex) {
                logger.error("关闭 pstm 失败 error : " + ex.getMessage());
            }
            try {
                conn.close();
            }
            catch (Exception ex) {
                logger.error("关闭数据库连接失败 error : " + ex.getMessage());
            }
        }
        return topic;
    }

    /**
     * 模块主题总数
     */
    public int sumopic(){
        Connection conn = DBConnectionManager.getInstance().getConnection();
        PreparedStatement pstm = null;
        ResultSet rs = null;
        int topicNum = 0;
        try {
            pstm = conn.prepareStatement(SUM_BOARD_TOPIC);
            pstm.setInt(1,boaId);
            rs = pstm.executeQuery();
            rs.next();
            topicNum = rs.getInt(1);
        }
        catch (Exception ex) {
            logger.info("模块主题总和统计失败 : " + ex.getMessage());
        }
        finally {
            try {
                rs.close();
            }
            catch (Exception ex) {
                logger.error("关闭 rs 失败 error : " + ex.getMessage());
            }
            try {
                pstm.close();
            }
            catch (Exception ex) {
                logger.error("关闭 pstm 失败 error : " + ex.getMessage());
            }
            try {
                conn.close();
            }
            catch (Exception ex) {
                logger.error("关闭数据库连接失败 error : " + ex.getMessage());
            }
        }
        return topicNum;
    }

    /**
     * 主题列表
     */
    public Iterator topicList(int page) {
        Connection conn = DBConnectionManager.getInstance().getConnection();
        PreparedStatement pstm = null;
        ResultSet rs = null;
        List list = new ArrayList();
        TopicConfigDTO topicConfigDTO = TopicConfigXML.getInstance().getTopicConfigXML();
        int maxNum = topicConfigDTO.getTopicNum();
        int i = 0;
        try {
            try {
                pstm = conn.prepareStatement(LIST_BOARD_TOPIC);
                pstm.setInt(1,topicBoaId);
                rs = pstm.executeQuery();
            }
            catch (Exception e) {
                logger.error("创建指针对象错误 : " + e.getMessage());
            }
            if (page == 1) { //第一页
                try {
                    rs.absolute(1);
                }
                catch (Exception e) {
                    logger.error("指针移到第一条数据错误 : " + e.getMessage());
                }
            }
            else {
                rs.absolute( (page - 1) * maxNum);
            }
            /**
             * 根据定位的指针来取得主题的值
             */
            for (i = 0; i < maxNum; i++) {
                if (page != 1) {
                    if (!rs.next()) {
                        break;
                    }
                }
                Topic topic = new DBTopic();
                topic.setTopicId(rs.getInt("topicId"));
                String topicTitle = rs.getString("topicTitle");
                topic.setTopicTitle(topicTitle);
                topic.setTopicContent(rs.getString("topicContent"));
                String topicAuthor = rs.getString("topicAuthor");
                topic.setTopicAuthor(topicAuthor);
                String topicPubTime = rs.getString("topicPubTime");
                
                
            /*     int topicElite = rs.getInt("topicElite");
                topic.setTopicElite(topicElite);
                int topicTop = rs.getInt("topicTop");
                topic.setTopicTop(topicTop);
                 int topicDel = rs.getInt("topicDel");
                topic.setTopicDel(topicDel);
                
                topic.setTopicPubTime(topicPubTime);
                int topicReNum = rs.getInt("topicReNum");
                topic.setTopicReNum(topicReNum);
                topic.setTopicSign("<img src=\"../images/"+topicConfigDTO.getTopicCommon()+"\"/>");
                //回复总和
                if(topicReNum>10){
                    topic.setTopicSign("<img src=\"../images/"+topicConfigDTO.getTopicHot()+"\"/>");
                }
                //是否为精华帖子
                if (topicElite == 1) {
                    logger.info("精华帖子" + topicConfigDTO.getTopicElite());
                    topic.setTopicSign("<img src=\"../images/" +
                                       topicConfigDTO.getTopicElite() + "\"/>");
                }
                //琐定
                if(topicLock==1){
                    topic.setTopicSign("<img src=\"../images/"+topicConfigDTO.getTopicLock()+"\"/>");
                }
                //置顶
                if(topicTop==1){
                    logger.info("置顶帖子" + topic);
                    topic.setTopicSign("<img src=\"../images/"+topicConfigDTO.getTopicTop()+"\"/>");
                }
                String topicReUser = rs.getString("topicReUser");
                //logger.info("topicReUser : " + topicReUser);
                if("".equals(topicReUser)){
                    topic.setTopicTitle(topicTitle);
                    //如果时间是今天,显示为新贴
                    Timer timer = new TimerExpress("yyyy-MM-dd HH:mm:ss");
                    if((((new Date().getTime())-(timer.getTimeToLong(topicPubTime)))/(1000*60*60*24))==0){
                        topic.setTopicTitle(topicTitle+"&nbsp;&nbsp;<img src=\"../images/topicnew.gif\" border=0/>");
                    }
                    topic.setTopicReUser(topicAuthor);
                    topic.setTopicReTime(topicPubTime);
                }
                else{
                    topic.setTopicReUser(topicReUser);
                    topic.setTopicReTime(rs.getString("topicReTime"));
                }
                */
                list.add(topic);
                /**
                 * 当页数为1的时候(填充数据后在返回)
                 */
                if (page == 1) {
                    if (!rs.next()) {
                        break;
                    }
                }
            }
        }
        catch (Exception e) {
            logger.error("获取主题对象错误 : " + e.getMessage());
        }
        finally {
            try {
               rs.close();
           }
           catch (Exception ex) {
               logger.error("关闭rs失败 : " + ex.getMessage());
           }
            try {
                pstm.close();
            }
            catch (Exception ex) {
                logger.error("关闭pstm失败 : " + ex.getMessage());
            }
            try {
                conn.close();
            }
            catch (Exception ex) {
                logger.error("关闭conn失败 : " + ex.getMessage());
            }
        }
        return list.iterator();
    }

    /**
     * 查看主题,主题热度 + 1
     */
    public void upTopicHits(int topicId){
        Connection conn = DBConnectionManager.getInstance().getConnection();
        PreparedStatement pstm = null;
        try {
            pstm = conn.prepareStatement(UP_TOPIC_HITS);
            pstm.setInt(1,topicId);
            pstm.executeUpdate();
        }
        catch (Exception ex) {
            logger.error("模块主题总和统计失败 : " + ex.getMessage());
        }
        finally {
            try {
                pstm.close();
            }
            catch (Exception ex) {
                logger.error("关闭 pstm 失败 error : " + ex.getMessage());
            }
            try {
                conn.close();
            }
            catch (Exception ex) {
                logger.error("关闭数据库连接失败 error : " + ex.getMessage());
            }
        }
    }

}

⌨️ 快捷键说明

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