dbarchivemanager.java

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

JAVA
446
字号
/** * $RCSfile: DbArchiveManager.java,v $ * $Revision: 1.7 $ * $Date: 2002/07/12 00:13:58 $ * * Copyright (C) 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.forum.util.*;import com.jivesoftware.jdom.*;import com.jivesoftware.jdom.output.XMLOutputter;import com.jivesoftware.util.*;import java.io.*;import java.util.*;import java.util.Date;import java.sql.*;/** * Database implementation of the ArchiveManager interface. * * @author Matt Tucker */public class DbArchiveManager implements ArchiveManager, Runnable {    private static final String ARCHIVED_THREADS =        "SELECT jiveThread.threadID FROM jiveThread, jiveThreadProp WHERE forumID=? AND " +        "jiveThread.threadID=jiveThreadProp.threadID AND jiveThreadProp.name='archived' AND " +        "jiveThreadProp.propValue='true'";    private static final String ARCHIVABLE_THREADS =        "SELECT threadID FROM jiveThread WHERE forumID=? AND modifiedDate <= ? AND threadID " +        "NOT IN (" + ARCHIVED_THREADS + ")";    private static final String ARCHIVABLE_THREADS_NO_SUBQUERIES =        "SELECT threadID FROM jiveThread WHERE forumID=? AND modifiedDate <= ?";    private static XMLProperties properties = null;    private static DbForumFactory factory;    private boolean busy;    private Object busyLock = new Object();    /**     * The scheduled task for auto-archiving.     */    private TimerTask timerTask = null;    public DbArchiveManager() {        this.factory = DbForumFactory.getInstance();        loadProperties();        // If auto archiving is enabled, we need to start a timer task at the specified interval.        if (isAutoArchiveEnabled()) {            timerTask = TaskEngine.scheduleTask(this, getAutoArchiveInterval()*JiveGlobals.HOUR,                    getAutoArchiveInterval()*JiveGlobals.HOUR);        }    }    public boolean isArchivingEnabled(Forum forum) {        if (forum == null) {            throw new NullPointerException("Forum argument to method is null");        }        String enabled = properties.getProperty("forum" + forum.getID() + ".archivingEnabled");        return "true".equals(enabled);    }    public void setArchivingEnabled(Forum forum, boolean enabled) {        if (forum == null) {            throw new NullPointerException("Forum argument to method is null");        }        properties.setProperty("forum" + forum.getID() + ".archivingEnabled",                String.valueOf(enabled));    }    public int getArchiveDays(Forum forum) {        if (forum == null) {            throw new NullPointerException("Forum argument to method is null");        }        // If archiving is disabled, return -1.        if (!isArchivingEnabled(forum)) {            return -1;        }        String days = properties.getProperty("forum" + forum.getID() + ".archiveDays");        if (days != null) {            return Integer.parseInt(days);        }        // The number of days isn't defined, so return the default of 180.        else {            return 180;        }    }    public void setArchiveDays(Forum forum, int days) {        if (days < 1) {            throw new IllegalArgumentException("Days must be greater than 0. " +                    "Value specified: " + days + ".");        }        if (forum == null) {            throw new NullPointerException("Forum argument to method is null");        }        properties.setProperty("forum" + forum.getID() + ".archiveDays",                String.valueOf(days));    }    public int getArchiveMode(Forum forum) {        if (forum == null) {            throw new NullPointerException("Forum argument to method is null");        }        String mode = properties.getProperty("forum" + forum.getID() + ".archiveMode");        // If the property is not defined, return the default.        if (mode == null) {            return ArchiveManager.MARK_ONLY;        }        else {            return Integer.parseInt(mode);        }    }    public void setArchiveMode(Forum forum, int mode) {        if (forum == null) {            throw new NullPointerException("Forum argument to method is null");        }        if (!(mode == ArchiveManager.MARK_ONLY ||              mode == ArchiveManager.MOVE_THREADS ||              mode == ArchiveManager.DELETE_THREADS))        {            throw new IllegalArgumentException("Mode not valid.");        }            properties.setProperty("forum" + forum.getID() + ".archiveMode",                    String.valueOf(mode));    }    public Forum getArchiveForum(Forum forum) {        if (forum == null) {            throw new NullPointerException("Forum argument to method is null");        }        String forumID = properties.getProperty("forum" + forum.getID() + ".archiveForum");        if (forumID == null) {            return null;        }        else {            try {                return factory.getForum(Integer.parseInt(forumID));            }            catch (Exception e) {                return null;            }        }    }    public void setArchiveForum(Forum forum, Forum archiveForum) {        if (forum == null || archiveForum == null) {            throw new NullPointerException("Forum argument to method is null");        }        properties.setProperty("forum" + forum.getID() + ".archiveForum",                String.valueOf(archiveForum.getID()));    }    public boolean isAutoArchiveEnabled() {        String enabled = properties.getProperty("autoArchiveEnabled");        return "true".equals(enabled);    }    public void setAutoArchiveEnabled(boolean enabled) {        // Do nothing if the value already matches the current setting.        if (enabled == isAutoArchiveEnabled()) {            return;        }        properties.setProperty("autoArchiveEnabled", String.valueOf(enabled));        // If we are switching from off to on, enable indexer        if (!isAutoArchiveEnabled() && enabled) {            if (timerTask != null) {                timerTask.cancel();            }            timerTask = TaskEngine.scheduleTask(this, getAutoArchiveInterval()*JiveGlobals.HOUR,                    getAutoArchiveInterval()*JiveGlobals.HOUR);        }        // Otherwise, if switching from on to off, disable indexer.        else if (isAutoArchiveEnabled() && !enabled) {            if (timerTask != null) {                timerTask.cancel();            }        }    }    public int getAutoArchiveInterval() {        // Default to 12 hours.        int interval = 12;        String value = properties.getProperty("autoArchiveInterval");        if (value != null) {            try {                interval = Integer.parseInt(value);            }            catch (NumberFormatException nfe) {                nfe.printStackTrace();            }        }        return interval;    }    public void setAutoArchiveInterval(int interval) {        if (interval < 1) {            throw new IllegalArgumentException("Invalid interval value: " + interval);        }        properties.setProperty("autoArchiveInterval", Integer.toString(interval));        // Restart auto-archiver with new schedule.        if (timerTask != null) {            timerTask.cancel();        }        timerTask = TaskEngine.scheduleTask(this, getAutoArchiveInterval()*JiveGlobals.HOUR,                    getAutoArchiveInterval()*JiveGlobals.HOUR);    }    public Date getLastArchivedDate() {        String lastArchived = properties.getProperty("lastArchivedDate");        if (lastArchived != null) {            return new Date(Long.parseLong(lastArchived));

⌨️ 快捷键说明

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