dbforum.java

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

JAVA
1,659 行
字号
    }    public int getMessageCount() {        return getMessageCount(DEFAULT_MESSAGE_FILTER);    }    public int getMessageCount(ResultFilter resultFilter) {        String sql = getMessageListSQL(resultFilter, true);        QueryCacheKey key = new QueryCacheKey(JiveGlobals.FORUM, id, sql, -1);        return getCount(key);    }    public Query createQuery() {        return new DbQuery(new Forum [] { this }, factory);    }    public FilterManager getFilterManager() {        return filterManager;    }    public GatewayManager getGatewayManager() {        GatewayManager manager = null;        synchronized (factory.gatewayManagers) {            manager = (GatewayManager)factory.gatewayManagers.get(this.id);            // If there is no entry for the manager, add it.            if (manager == null) {                manager = new GatewayManager(factory, this);                factory.gatewayManagers.put(this.id, manager);            }        }        return manager;    }    public PermissionsManager getPermissionsManager() {        return new DbPermissionsManager(JiveGlobals.FORUM, id);    }    public ForumPermissions getPermissions(Authorization authorization) {        long userID = authorization.getUserID();        ForumPermissions forumPerms =  factory.permissionsManager.getFinalUserPerms(                JiveGlobals.FORUM, id, userID);        // Add-in permissions from the forum's category.        ForumPermissions categoryPerms = getForumCategory().getPermissions(                authorization);        return new ForumPermissions(forumPerms, categoryPerms);    }    public boolean hasPermission(int type) {        return true;    }    //FROM THE CACHEABLE INTERFACE//    public int getCachedSize() {        // Approximate the size of the object in bytes by calculating the size        // of each field.        int size = 0;        size += CacheSizes.sizeOfObject();              // overhead of object        size += CacheSizes.sizeOfObject();              // factory        size += CacheSizes.sizeOfLong();                // id        size += CacheSizes.sizeOfString(name);          // name        size += CacheSizes.sizeOfString(description);   // description        size += CacheSizes.sizeOfDate();                // creation date        size += CacheSizes.sizeOfDate();                // modified date        size += CacheSizes.sizeOfMap(properties);       // properties        size += CacheSizes.sizeOfObject() +                CacheSizes.sizeOfLong() * 5;            // approx of pop threads        size += CacheSizes.sizeOfInt() * 4;             // moderation values        size += CacheSizes.sizeOfObject();              // filter manager        // Make rough estimation of size of queryKeys        size += queryKeys.size() * 212;        return size;    }    //OTHER METHODS    /**     * Returns a String representation of the Forum object using the forum name.     *     * @return a String representation of the Forum object.     */    public String toString() {        return name;    }    public int hashCode() {        return (int)id;    }    public boolean equals(Object object) {        if (this == object) {            return true;        }        if (object != null && object instanceof DbForum) {            return id == ((DbForum)object).getID();        }        else {            return false;        }    }    /**     * Updates the modified date. It accepts a Connection so that it can     * participate in trasactions.     */    protected void updateModifiedDate(long date, Connection con) throws SQLException {        // Only update the modified date if it is newer than the current one.        if (date > this.modifiedDate.getTime()) {            this.modifiedDate.setTime(date);            PreparedStatement pstmt = null;            try {                pstmt = con.prepareStatement(UPDATE_FORUM_MODIFIED_DATE);                pstmt.setString(1, StringUtils.dateToMillis(modifiedDate));                pstmt.setLong(2, id);                pstmt.executeUpdate();            }            finally {                try {  pstmt.close(); }                catch (Exception e) { e.printStackTrace(); }            }            // Update the modified date of the category and all parent categories that this forum            // belongs to.            ((DbForumCategory)getForumCategory()).updateModifiedDate(date, con);        }    }    /**     * Does the actual work of deleteting a thread. It accepts a Connection so     * that it can participate in transactions.     */    protected void deleteThread(DbForumThread thread, Connection con)            throws SQLException, ForumMessageNotFoundException    {        // Delete any watches on the thread.        factory.watchManager.deleteThreadWatches(thread, con);        PreparedStatement pstmt = null;        // Deleting all message content of the thread is vastly more efficient        // than deleting individual messages. Unfortunately, SQL subselects        // are required for this to work. Use the more efficient mechanism        // if possible.        if (!ConnectionManager.supportsSubqueries) {            thread.deleteMessage(thread.getRootMessage(), con, true);        }        else {            // Delete all reward manager entries for the thread.            factory.rewardManager.deleteThreadReferences(thread, con);            try {                // Delete all message attachments if this isn't a Basic license.                if (!LicenseManager.getProduct().equals("Jive Forums Basic")) {                    LongList attachIDs = new LongList();                    pstmt = con.prepareStatement(ALL_MESSAGES_ATTACHMENTS);                    pstmt.setLong(1, thread.getID());                    ResultSet rs = pstmt.executeQuery();                    while (rs.next()) {                        attachIDs.add(rs.getLong(1));                    }                    pstmt.close();                    long [] attachments = attachIDs.toArray();                    for (int i=0; i<attachments.length; i++) {                        try {                            DbAttachment attachment =                                    factory.cacheManager.getAttachment(attachments[i]);                            attachment.delete(con);                        }                        catch (Exception e) {                            e.printStackTrace();                        }                    }                }                // Delete all message extended properties.                pstmt = con.prepareStatement(DELETE_MESSAGES_PROPERTIES);                pstmt.setLong(1, thread.getID());                pstmt.setLong(2, this.id);                pstmt.execute();                pstmt.close();                // Delete all message content.                pstmt = con.prepareStatement(DELETE_MESSAGES);                pstmt.setLong(1, thread.getID());                pstmt.execute();            }            finally {                try {  pstmt.close(); }                catch (Exception e) { e.printStackTrace(); }            }        }        try {            // Now delete thread db entry and thread properties.            pstmt = con.prepareStatement(DELETE_THREAD_PROPERTIES);            pstmt.setLong(1, thread.getID());            pstmt.execute();            pstmt.close();            pstmt = con.prepareStatement(DELETE_THREAD);            pstmt.setLong(1, thread.getID());            pstmt.execute();        }        finally {            try {  pstmt.close(); }            catch (Exception e) { e.printStackTrace(); }        }    }    /**     * Returns an array of all the thread id's in the forum. This method     * is primarily useful for the data export class, which needs a full list     * of all the id's for maximum efficiency.     *     * @return an array of all thread ID's in the forum.     */    protected long[] getAllThreads() {        LongList threads = new LongList(getThreadCount());        Connection con = null;        PreparedStatement pstmt = null;        try {            con = ConnectionManager.getConnection();            pstmt = con.prepareStatement(ALL_THREADS);            pstmt.setLong(1, this.id);            ResultSet rs = pstmt.executeQuery();            while (rs.next()) {                threads.add(rs.getLong(1));            }        }        catch( SQLException sqle ) {            sqle.printStackTrace();        }        finally {            try {  pstmt.close(); }            catch (Exception e) { e.printStackTrace(); }            try {  con.close();   }            catch (Exception e) { e.printStackTrace(); }        }        return threads.toArray();    }    /**     * Clears caches related to the object.     */    protected void clearCache() {        synchronized (queryKeys) {            // Clear out the query cache of lists and counts.            Object [] listElements = queryKeys.toArray();            queryKeys.clear();            for (int i=0; i<listElements.length; i++) {                Object key = listElements[i];                // If the short-term query cache is enabled, move the object                // there.                if (factory.cacheManager.isShortTermQueryCacheEnabled()) {                    Object value = factory.cacheManager.queryCache.get(key);                    // Add the object to the short-term cache and then remove it                    // from the normal cache.                    if (value != null) {                        factory.cacheManager.shortTermQueryCache.put(key, value);                    }                }                factory.cacheManager.queryCache.remove(key);            }        }        // Reset popular threads        this.popularThreads = null;        // Re-add forum to cache.        factory.cacheManager.forumCache.put(new Long(this.id), this);    }    /**     * Returns the SQL statement corresponding to a ResultFilter for threads.     */    protected String getThreadListSQL(ResultFilter resultFilter, boolean countQuery) {        int sortField = resultFilter.getSortField();        // Make sure the sort field is valid.        if (!countQuery && ! ( sortField == JiveGlobals.MODIFIED_DATE ||                sortField == JiveGlobals.CREATION_DATE ||                sortField == JiveGlobals.THREAD_NAME ||                ( sortField == JiveGlobals.EXTENDED_PROPERTY &&                  resultFilter.getSortPropertyName() != null                )              )            )        {            throw new IllegalArgumentException("The specified sort field is not valid.");        }        StringBuffer query = new StringBuffer(80);        if (!countQuery) {            query.append("SELECT jiveThread.threadID");        }        else {            query.append("SELECT count(1)");        }        boolean filterUser = resultFilter.getUserID() != ResultFilter.NULL_INT;        boolean filterCreationDate = resultFilter.getCreationDateRangeMin() != null ||                                     resultFilter.getCreationDateRangeMax() != null;        boolean filterModifiedDate = resultFilter.getModifiedDateRangeMin() != null ||                                     resultFilter.getModifiedDateRangeMax() != null;        int propertyCount = resultFilter.getPropertyCount();        // SELECT -- need to add value that we sort on        if (!countQuery) {            switch(sortField) {                case JiveGlobals.THREAD_NAME:                    query.append(", jiveMessage.subject");                    break;                case JiveGlobals.MODIFIED_DATE:                    query.append(", jiveThread.modifiedDate");                    break;                case JiveGlobals.CREATION_DATE:                    query.append(", jiveThread.creationDate");                    break;                case JiveGlobals.EXTENDED_PROPERTY:                    query.append(", propTable.propValue");                    break;            }        }        // FROM -- values (in addition to jiveThread)        query.append(" FROM jiveThread");        if (filterUser ||                (!countQuery && resultFilter.getSortField() == JiveGlobals.THREAD_NAME))        {            query.append(", jiveMessage");        }        for (int i=0; i<propertyCount; i++) {            query.append(", jiveThreadProp p").append(i);        }        if (resultFilter.getSortField() == JiveGlobals.EXTENDED_PROPERTY) {

⌨️ 快捷键说明

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