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

📄 auctionworthcache.java

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

import cn.js.fan.base.ObjectCache;
import cn.js.fan.db.Conn;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.PreparedStatement;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2005</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class AuctionWorthCache extends ObjectCache {
    final String auctionPrefix = "AUCTIONWORTH_";

    public AuctionWorthCache() {
        super();
    }

    public AuctionWorthCache(AuctionWorthDb auctionWorthDb) {
        super(auctionWorthDb);
    }

    /**
     * setGroup
     *
     * @todo Implement this cn.js.fan.base.ObjectCache method
     */
    public void setGroup() {
        group = "AUCTIONWORTH";
    }

    /**
     * setGroupCount
     *
     * @todo Implement this cn.js.fan.base.ObjectCache method
     */
    public void setGroupCount() {
        COUNT_GROUP_NAME = "AUCTIONWORTH_COUNT";
    }

    public void refreshWorthOfAuction(int msgRootId) {
        try {
            rmCache.remove(auctionPrefix + msgRootId, group);
        }
        catch (Exception e) {
            logger.error("refreshWorthOfAuction:" + e.getMessage());
        }
    }

    public long[] getWorthOfAuction(long msgRootId) {
        //根据sql语句得出计算总数的sql查询语句
        String sql = "select id from " + objectDb.getTableName() +
                     " where msgRootId=?";
        long[] v = null;
        try {
            v = (long[]) rmCache.getFromGroup(auctionPrefix + msgRootId, group);
        } catch (Exception e) {
            logger.error("getWorthOfAuction:" + e.getMessage());
        }

        // If already in cache, return the count.
        if (v != null) {
            return v;
        }
        // Otherwise, we have to load the count from the db.
        else {
            Conn conn = new Conn(connname);
            ResultSet rs = null;
            try {
                PreparedStatement ps = conn.prepareStatement(sql);
                ps.setLong(1, msgRootId);
                rs = conn.executePreQuery();
                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(e.getMessage());
            } finally {
                if (rs != null) {
                    try {
                        rs.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    rs = null;
                }
                if (conn != null) {
                    conn.close();
                    conn = null;
                }
            }
            // Add the thread count to cache
            if (v!=null && v.length > 0) {
                try {
                    rmCache.putInGroup(auctionPrefix + msgRootId, group, v);
                } catch (Exception e) {
                    logger.error(e.getMessage());
                }
            }
            return v;
        }
    }

}

⌨️ 快捷键说明

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