querycachekey.java

来自「Jive是基于JSP/JAVA技术构架的一个大型BBS论坛系统,这是Jive论坛」· Java 代码 · 共 129 行

JAVA
129
字号
/** * $RCSfile: QueryCacheKey.java,v $ * $Revision: 1.1 $ * $Date: 2002/05/10 22:20:01 $ * * Copyright 1999-2002 CoolServlets, Inc. All Rights Reserved. * * This software is the proprietary information of CoolServlets, Inc. * Use is subject to license terms. */package com.jivesoftware.forum.database;import com.jivesoftware.forum.*;import com.jivesoftware.util.*;/** * Represents a key in the QueryCache. All information needed to reload a * cache entry is included in the key. */public class QueryCacheKey implements java.io.Serializable, Cacheable  {    int objectType;    long objectID;    String sql;    int blockID;    /**     * Creates a new QueryCacheKey.     *     * @param objectType the type of the object: JiveGlobals.FORUM_CATEGORY,     *      JiveGlobals.FORUM, or JiveGlobals.THREAD.     * @param objectID the id of the parent object to which the query cache     *      entry corresponds.     * @param sql the sql query for the cache entry data.     * @param blockID the blockID of the entry.     */    public QueryCacheKey(int objectType, long objectID, String sql, int blockID) {        this.objectType = objectType;        this.objectID = objectID;        this.sql = sql;        this.blockID = blockID;    }    public boolean equals(Object obj) {        if (this == obj) {             return true;        }        else {            QueryCacheKey otherKey = (QueryCacheKey)obj;            return (objectType == otherKey.getObjectType() &&                    objectID == otherKey.getObjectID() &&                    blockID == otherKey.getBlockID() &&                    sql.equals(otherKey.getSql()));        }    }    public int hashCode() {        return objectType + (int)objectID + sql.hashCode() + blockID;    }    public String toString() {        StringBuffer result = new StringBuffer();        switch (objectType) {            case JiveGlobals.FORUM_CATEGORY:                result.append("Category ");                break;            case JiveGlobals.FORUM:                result.append("Forum ");                break;            case JiveGlobals.THREAD:                result.append("Thread ");        }        result.append(objectID).append(": ");        result.append(sql);        if (blockID != -1) {            result.append(", ").append(blockID);        }        return result.toString();    }    /**     * Returns the object type associated with the objectID. Possible values are     * JiveGlobals.FORUM_CATEGORY, JiveGlobals.FORUM, and JiveGlobals.THREAD.     *     * @return the object type..     */    public int getObjectType() {        return objectType;    }    /**     * Returns the objectID of the key.     *     * @return the objectID.     */    public long getObjectID() {        return objectID;    }    /**     * Returns the sql query of the key.     *     * @return the sql.     */    public String getSql() {        return sql;    }    /**     * Returns the blockID of the key, or -1 if there is not a blockID.     *     * @return the blockID, or -1 if not a blockID.     */    public int getBlockID() {        return blockID;    }    public int getCachedSize() {        int size = 0;        size += CacheSizes.sizeOfObject();              // overhead of object        size += CacheSizes.sizeOfInt();                 // object type        size += CacheSizes.sizeOfLong();                // object id        size += CacheSizes.sizeOfString(sql);           // sql        size += CacheSizes.sizeOfInt();                 // blockID        return size;    }}

⌨️ 快捷键说明

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