blogcache.java

来自「cwbbs 云网论坛源码」· Java 代码 · 共 603 行 · 第 1/2 页

JAVA
603
字号
package com.redmoon.blog;import java.sql.*;import cn.js.fan.base.*;import cn.js.fan.cache.jcs.*;import cn.js.fan.db.*;import cn.js.fan.util.*;import cn.js.fan.util.file.*;import cn.js.fan.web.*;import com.cloudwebsoft.framework.template.*;import com.redmoon.blog.photo.*;import com.redmoon.forum.*;public class BlogCache extends ObjectCache implements ICacheMgr {    final String NEWBLOGMSG = "NEW_BLOG_MSG";    final String HOTBLOGMSG = "HOT_BLOG_MSG";    final String POSTRANKBLOG = "POST_RANK_BLOG";    final String NEWBLOG = "NEW_BLOG";    final String NEWUPDATEBLOG = "NEW_UPDATE_BLOG";    final String COMMENDBLOG = "COMMEND_BLOG";    final String ALLBLOG = "ALL_BLOG";    final String NEWBLOGPHOTOS = "NEW_BLOG_PHOTOS";    final String REPLYRANKBLOG = "REPLY_RANK_BLOG";    public BlogCache() {    }    public BlogCache(BlogDb blogDb) {        super(blogDb);    }    public void refreshHomePage() {        try {            rmCache.invalidateGroup(group);            Config cfg = Config.getInstance();            if (cfg.getBooleanProperty("createHtmlWhenRefreshHome")) {                String filePath = Global.realPath + "blog/template/index.htm";                TemplateLoader tl = new TemplateLoader(null, filePath);                FileUtil fu = new FileUtil();                fu.WriteFile(Global.getRealPath() +                             "blog/index.htm",                             tl.toString(), "UTF-8");            }        } catch (Exception e) {            logger.error("refreshHomePage:" + StrUtil.trace(e));        }    }    public int[] getNewPhotos(int n) {                PhotoDb pd = new PhotoDb();        String sql = "select id from " + pd.getTableName() +                     " ORDER BY addDate desc";        int[] v = null;        try {            v = (int[]) rmCache.getFromGroup(NEWBLOGPHOTOS, group);        } catch (Exception e) {            logger.error("getNewPhotos1:" + e.getMessage());        }                if (v != null) {            return v;        }                else {            Conn conn = new Conn(connname);            ResultSet rs = null;            try {                conn.setMaxRows(n);                rs = conn.executeQuery(sql);                int c = conn.getRows();                if (c<n)                    n = c;                v = new int[n];                conn.setFetchSize(n);                int id;                int i = 0;                if (rs != null) {                    while (rs.next()) {                        id = rs.getInt(1);                        v[i] = id;                        i++;                    }                }            } catch (SQLException e) {                logger.error("getNewPhotos2:" + e.getMessage());            } finally {                if (rs != null) {                    try {                        rs.close();                    } catch (Exception e) {                        e.printStackTrace();                    }                    rs = null;                }                if (conn != null) {                    conn.close();                    conn = null;                }            }                        if (v != null && v.length > 0) {                try {                    rmCache.putInGroup(NEWBLOGPHOTOS, group, v);                } catch (Exception e) {                    logger.error(e.getMessage());                }            }            return v;        }    }        public long[] getNewBlogMsgs(int n) {                String sql = "select id from sq_thread where check_status=" +                     MsgDb.CHECK_STATUS_PASS +                     " and isBlog=1 order by lydate desc";        long[] v = new long[0];        try {            v = (long[]) rmCache.getFromGroup(NEWBLOGMSG, group);        } catch (Exception e) {            logger.error("getTopBlogs:" + e.getMessage());        }                if (v != null) {            return v;        }                else {            Conn conn = new Conn(connname);            ResultSet rs = null;            try {                conn.setMaxRows(n);                rs = conn.executeQuery(sql);                conn.setFetchSize(n);                v = new long[conn.getRows()];                int id;                int i = 0;                while (rs.next()) {                    id = rs.getInt(1);                    v[i] = id;                    i++;                }            } catch (SQLException e) {                logger.error("getTopMsgs:" + e.getMessage());            } finally {                if (rs != null) {                    try {                        rs.close();                    } catch (Exception e) {                        e.printStackTrace();                    }                    rs = null;                }                if (conn != null) {                    conn.close();                    conn = null;                }            }                        if (v.length > 0) {                try {                    rmCache.putInGroup(NEWBLOGMSG, group, v);                } catch (Exception e) {                    logger.error(e.getMessage());                }            }            return v;        }    }        public long[] getHotBlogMsgs(int n) {                String sql = "select id from sq_thread where check_status=" +                     MsgDb.CHECK_STATUS_PASS +                     " and isBlog=1 order by hit desc";        long[] v = new long[0];        try {            v = (long[]) rmCache.getFromGroup(HOTBLOGMSG, group);        } catch (Exception e) {            logger.error("getHotBlogMsgs:" + e.getMessage());        }                if (v != null) {            return v;        }                else {            Conn conn = new Conn(connname);            ResultSet rs = null;            try {                conn.setMaxRows(n);                rs = conn.executeQuery(sql);                conn.setFetchSize(n);                v = new long[conn.getRows()];                int id;                int i = 0;                while (rs.next()) {                    id = rs.getInt(1);                    v[i] = id;                    i++;                }            } catch (SQLException e) {                logger.error("getTopMsgs:" + e.getMessage());            } finally {                if (rs != null) {                    try {                        rs.close();                    } catch (Exception e) {                        e.printStackTrace();                    }                    rs = null;                }                if (conn != null) {                    conn.close();                    conn = null;                }            }                        if (v.length > 0) {                try {                    rmCache.putInGroup(HOTBLOGMSG, group, v);                } catch (Exception e) {                    logger.error(e.getMessage());                }            }            return v;        }    }        public long[] getPostRank(int n) {                String sql = "select id from blog_user_config order by msgCount desc";        long[] v = null;        try {            v = (long[]) rmCache.getFromGroup(POSTRANKBLOG, group);        } catch (Exception e) {            logger.error("getPostRank:" + e.getMessage());        }                if (v != null) {            return v;        }                else {            Conn conn = new Conn(connname);            ResultSet rs = null;            try {                conn.setMaxRows(n);                rs = conn.executeQuery(sql);                conn.setFetchSize(n);                v = new long[conn.getRows()];                int i = 0;                while (rs.next()) {                    v[i] = rs.getLong(1);                    i++;                }            } catch (SQLException e) {                logger.error("getPostRank:" + e.getMessage());            } finally {                if (conn != null) {                    conn.close();                    conn = null;                }            }                        if (v.length > 0) {                try {                    rmCache.putInGroup(POSTRANKBLOG, group, v);                } catch (Exception e) {                    logger.error(e.getMessage());                }            }            return v;        }    }        public long[] getReplyRank(int n) {                String sql = "select id from blog_user_config order by replyCount desc";        long[] v = null;        try {            v = (long[]) rmCache.getFromGroup(REPLYRANKBLOG, group);        } catch (Exception e) {            logger.error("getPostRank:" + e.getMessage());        }                if (v != null) {            return v;

⌨️ 快捷键说明

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