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

📄 homedb.java

📁 源码/软件简介: 云网论坛1.1RC国际版是采用JSP开发的集论坛、CMS(网站内容管理系统)、博客、聊天室、商城、交友、语音灌水等于一体的门户式社区。拥有CWBBS ( Cloud Web BBS
💻 JAVA
字号:
package com.redmoon.forum.miniplugin.home;

import java.sql.*;
import java.util.Vector;

import cn.js.fan.base.ObjectDb;
import cn.js.fan.db.Conn;
import cn.js.fan.db.PrimaryKey;
import cn.js.fan.util.*;
import com.redmoon.forum.*;
import com.redmoon.forum.plugin.auction.AuctionShopDb;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class HomeDb extends ObjectDb {
    final int id = 0;
    private String hot;

    public HomeDb() {
        init();
        load();
    }

    /**
     * del
     *
     * @return boolean
     * @throws ErrMsgException
     * @throws ResKeyException
     * @todo Implement this cn.js.fan.base.ObjectDb method
     */
    public boolean del() throws ErrMsgException, ResKeyException {
        return false;
    }

    /**
     *
     * @param pk Object
     * @return Object
     * @todo Implement this cn.js.fan.base.ObjectDb method
     */
    public ObjectDb getObjectRaw(PrimaryKey pk) {
        return new HomeDb();
    }

    /**
     * load
     *
     * @throws ErrMsgException
     * @throws ResKeyException
     * @todo Implement this cn.js.fan.base.ObjectDb method
     */
    public void load() {
        Conn conn = new Conn(connname);
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            pstmt = conn.prepareStatement(this.QUERY_LOAD);
            rs = conn.executePreQuery();
            if (rs.next()) {
                hot = rs.getString(1);
                recommandBoard = rs.getString(2);
                recommandMsg = rs.getString(3);
                primaryKey.setValue(new Integer(id));
            }
        } catch (SQLException e) {
            logger.error("load:" + e.getMessage());
        } finally {
            if (rs!=null) {
                try {
                    rs.close();
                }
                catch (Exception e) {}
                rs = null;
            }
            if (pstmt!=null) {
                try {
                    pstmt.close();
                }
                catch (Exception e) {}
                pstmt = null;
            }
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }
    }

    /**
     * save
     *
     * @return boolean
     * @throws ErrMsgException
     * @throws ResKeyException
     * @todo Implement this cn.js.fan.base.ObjectDb method
     */
    public boolean save() {
        // Based on the id in the object, get the message data from the database.
        Conn conn = new Conn(connname);
        PreparedStatement pstmt = null;
        try {
            pstmt = conn.prepareStatement(this.QUERY_SAVE);
            pstmt.setString(1, hot);
            pstmt.setString(2, recommandBoard);
            pstmt.setString(3, recommandMsg);
            if (conn.executePreUpdate() == 1) {
                HomeCache hc = new HomeCache(this);
                primaryKey.setValue(new Integer(id));
                hc.refreshSave(primaryKey);
            } else
                return false;
        } catch (SQLException e) {
            logger.error("save:" + e.getMessage());
        } finally {
            if (pstmt!=null) {
                try {
                    pstmt.close();
                }
                catch (Exception e) {}
                pstmt = null;
            }
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }
        return true;
    }

    public void initDB() {
        this.tableName = "miniplugin_home";
        primaryKey = new PrimaryKey("id", PrimaryKey.TYPE_INT);
        objectCache = new HomeCache(this);

        // this.QUERY_DEL =
        //        "delete FROM " + tableName + " WHERE id=?";
        // this.QUERY_CREATE =
        //        "INSERT " + tableName + " (url,title,image,userName,sort,kind) VALUES (?,?,?,?,?,?)";
        this.QUERY_LOAD =
                "SELECT hot,recommandBoard,recommandMsg FROM " + tableName + " WHERE id=0";
        this.QUERY_SAVE =
                "UPDATE " + tableName +
                " SET hot=?,recommandBoard=?,recommandMsg=? WHERE id=0";
        isInitFromConfigDB = false;
    }

    public void setHot(String hot) {
        this.hot = hot;
    }

    public void setRecommandBoard(String recommandBoard) {
        this.recommandBoard = recommandBoard;
    }

    public void setRecommandMsg(String recommandMsg) {
        this.recommandMsg = recommandMsg;
    }

    public String getHot() {
        return hot;
    }

    public String getRecommandBoard() {
        return recommandBoard;
    }

    public String getRecommandMsg() {
        return recommandMsg;
    }

    public int[] getHotIds() {
        HomeCache hc = new HomeCache(this);
        return hc.getHotIds();
    }

    public String[] getRecommandBoards() {
        HomeCache hc = new HomeCache(this);
        return hc.getRecommandBoards();
    }

    public int[] getRecommandMsgs() {
        HomeCache hc = new HomeCache(this);
        return hc.getRecommandMsgs();
    }

    public HomeDb getHomeDb() {
        return (HomeDb) getObjectDb(new Integer(id));
    }

    public MsgDb getMsgDbTopOne(String boardCode) {
        MsgDb md = new MsgDb();
        // 使用下句如果不加缓存,首页打开要十几秒,可能会导致磁盘长时间处于忙状态,致机器假死
        // String sql =
        //            "select id from sq_message where replyid=-1 and boardcode=" +
        //            StrUtil.sqlstr(boardCode) + " and level<=" +
        //            MsgDb.LEVEL_TOP_BOARD + " ORDER BY redate desc";
        // @task:换成下句后,明显快多了,但是还需再优化,因为下面的sql与listopic.jsp中的sql相比,少了order by level desc,因为要把最新的列出来,这就使得缓存中的block数据太多了
        String sql = "select id from sq_thread where boardcode="+StrUtil.sqlstr(boardCode)+" and level<=" + MsgDb.LEVEL_TOP_BOARD + " ORDER BY redate desc";

        ThreadBlockIterator irmsg = md.getThreads(sql, boardCode, 0, 1);
        if (irmsg.hasNext()) {
            md = (MsgDb) irmsg.next();
        }
        return md;
    }

    public Vector getBoardsByTodayPost(int count) {
        Vector v = new Vector();
        String sql = "select code from sq_board order by today_count desc";
        Conn conn = new Conn(connname);
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
            pstmt = conn.prepareStatement(sql);
            conn.setMaxRows(count);
            rs = conn.executePreQuery();
            conn.setFetchSize(count);
            Leaf lf = new Leaf();
            while (rs.next()) {
                lf = lf.getLeaf(rs.getString(1));
                v.addElement(lf);
            }
        } catch (SQLException e) {
            logger.error("getBoardsByTodayPost:" + e.getMessage());
        } finally {
            if (rs!=null) {
                try {
                    rs.close();
                }
                catch (Exception e) {}
                rs = null;
            }
            if (pstmt!=null) {
                try {
                    pstmt.close();
                }
                catch (Exception e) {}
                pstmt = null;
            }
            if (conn != null) {
                conn.close();
                conn = null;
            }
        }
        return v;
    }

    public Vector getNewShop(int count) {
        AuctionShopDb as = new AuctionShopDb();
        String sql = "select userName from " + as.getTableName() + " order by openDate desc";
        return as.list(sql, 0, count);
    }

    private String recommandBoard;
    private String recommandMsg;

}

⌨️ 快捷键说明

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