dbwatchmanager.java
来自「Jive是基于JSP/JAVA技术构架的一个大型BBS论坛系统,这是Jive论坛」· Java 代码 · 共 484 行 · 第 1/2 页
JAVA
484 行
/** * $RCSfile: DbWatchManager.java,v $ * $Revision: 1.7 $ * $Date: 2002/06/21 05:55:11 $ * * Copyright (C) 1999-2001 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 java.util.*;import java.sql.*;import java.util.Date;import com.jivesoftware.forum.*;import com.jivesoftware.forum.util.*;import com.jivesoftware.util.*;/** * Database implementation of the WatchManager interface. The following Jive * properties control the behavior of this class:<ul> * * <li><tt>watches.emailNotifyEnabled</tt> -- set to <tt>true</tt> or </tt> false to * enable or disable email watch notifications. Default is false. * <li><tt>watches.deleteDays</tt> -- the number of days a thread can be * inactive before a watch on that thread is automatically deleted. Default * is 30 days. * </ul> * * @see EmailWatchUpdateTask */public class DbWatchManager implements WatchManager { /** DATABASE QUERIES **/ private static final String CREATE_WATCH = "INSERT INTO jiveWatch(userID,forumID,threadID,watchType,expirable) " + "VALUES (?,?,?,?,1)"; private static final String DELETE_WATCH = "DELETE FROM jiveWatch WHERE userID=? AND threadID=? AND watchType=?"; private static final String DELETE_THREAD_WATCHES = "DELETE FROM jiveWatch WHERE threadID=?"; private static final String ALL_WATCHES = "SELECT jiveWatch.threadID, jiveWatch.expirable, jiveThread.forumID, modifiedDate " + "FROM jiveWatch, jiveThread WHERE jiveWatch.userID=? AND " + "jiveWatch.watchType=? AND jiveWatch.threadID=jiveThread.threadID " + "ORDER BY modifiedDate DESC"; private static final String ALL_WATCHES_BY_FORUM = "SELECT jiveWatch.threadID, jiveThread.forumID, modifiedDate FROM " + "jiveWatch, jiveThread WHERE jiveWatch.userID=? AND jiveWatch.watchType=? " + "AND jiveWatch.threadID=jiveThread.threadID ORDER BY jiveThread.forumID, " + "modifiedDate DESC"; private static final String GET_EXPIRED_WATCHES = "SELECT jiveWatch.threadID FROM jiveWatch, jiveThread WHERE " + "jiveWatch.threadID=jiveThread.threadID AND jiveThread.modifiedDate < ? " + "AND jiveWatch.expirable=1"; private static final String EXPIRE_OLD_WATCHES = "DELETE FROM jiveWatch WHERE threadID IN (SELECT jiveWatch.threadID FROM " + "jiveWatch, jiveThread WHERE jiveWatch.threadID=jiveThread.threadID AND " + "jiveThread.modifiedDate < ? AND jiveWatch.expirable=1)"; private static final String UPDATE_WATCH_EXPIRATION = "UPDATE jiveWatch SET expirable=? WHERE userID=? AND threadID=? AND watchType=?"; // Jive property values. private boolean emailNotifyEnabled = false; private int deleteDays; private String fromName; private String fromEmail; private String subject; private String body; private DbForumFactory factory; /** * Creates a new DbWatchManager. */ public DbWatchManager() { factory = DbForumFactory.getInstance(); // Enable or disable email notifications String emailNotify = JiveGlobals.getJiveProperty("watches.emailNotifyEnabled"); if (!"false".equals(emailNotify)) { emailNotifyEnabled = true; } // Set number of days that watches on unmodified threads will live. // Default is 30 days. deleteDays = 30; String days = JiveGlobals.getJiveProperty("watches.deleteDays"); if (days != null) { try { deleteDays = Integer.parseInt(days); } catch (Exception e) { } } // Load email watch properties. fromName = JiveGlobals.getJiveProperty("watches.email.fromName"); fromEmail = JiveGlobals.getJiveProperty("watches.email.fromEmail"); subject = JiveGlobals.getJiveProperty("watches.email.subject"); body = JiveGlobals.getJiveProperty("watches.email.body"); // Add a scheduled task to delete old watches. long period = 12*JiveGlobals.HOUR; TaskEngine.scheduleTask(new DeleteWatchesTask(), period, period); } public int getDeleteDays() { return deleteDays; } public void setDeleteDays(int deleteDays) { this.deleteDays = deleteDays; JiveGlobals.setJiveProperty("watches.deleteDays", Integer.toString(deleteDays)); } public boolean isEmailNotifyEnabled() { return emailNotifyEnabled; } public void setEmailNotifyEnabled(boolean enabled) { this.emailNotifyEnabled = enabled; JiveGlobals.setJiveProperty("watches.emailNotifyEnabled", ""+emailNotifyEnabled); } public String getEmailBody() { return body; } public void setEmailBody(String body) { this.body = body; JiveGlobals.setJiveProperty("watches.email.body", body); } public String getEmailSubject() { return subject; } public void setEmailSubject(String subject) { this.subject = subject; JiveGlobals.setJiveProperty("watches.email.subject", subject); } public String getEmailFromName() { return fromName; } public void setEmailFromName(String fromName) { this.fromName = fromName; JiveGlobals.setJiveProperty("watches.email.fromName", fromName); } public String getEmailFromEmail() { return fromEmail; } public void setEmailFromEmail(String fromEmail) { this.fromEmail = fromEmail; JiveGlobals.setJiveProperty("watches.email.fromEmail", fromEmail); } public void createWatch(User user, ForumThread thread, int watchType) { // If the user is already watching the thread, do nothing. if (getWatchList(user, watchType).isWatchedThread(thread.getID())) { return; } // Otherwise, add a new watch. Connection con = null; PreparedStatement pstmt = null; try { con = ConnectionManager.getConnection(); pstmt = con.prepareStatement(CREATE_WATCH); pstmt.setLong(1, user.getID()); pstmt.setLong(2, thread.getForum().getID()); pstmt.setLong(3, thread.getID()); pstmt.setInt(4, watchType); pstmt.execute(); } catch( SQLException sqle ) { sqle.printStackTrace(); } finally { try { pstmt.close(); } catch (Exception e) { e.printStackTrace(); } try { con.close(); } catch (Exception e) { e.printStackTrace(); } } // Remove user's watch list from cache. StringBuffer key = new StringBuffer(Long.toString(user.getID())); key.append("-").append(watchType); factory.cacheManager.watchCache.remove(key.toString()); } public void deleteWatch(User user, ForumThread thread, int watchType) { Connection con = null; PreparedStatement pstmt = null; try { con = ConnectionManager.getConnection(); pstmt = con.prepareStatement(DELETE_WATCH); pstmt.setLong(1, user.getID()); pstmt.setLong(2, thread.getID()); pstmt.setInt(3, watchType); pstmt.execute(); } catch( SQLException sqle ) { sqle.printStackTrace(); } finally { try { pstmt.close(); } catch (Exception e) { e.printStackTrace(); } try { con.close(); } catch (Exception e) { e.printStackTrace(); } } // Remove user's watch list from cache. StringBuffer key = new StringBuffer(Long.toString(user.getID())); key.append("-").append(watchType); factory.cacheManager.watchCache.remove(key.toString()); } public boolean isWatchExpirable(User user, ForumThread thread, int watchType) { return getWatchList(user, watchType).isWatchExpirable(thread.getID()); } public void setWatchExpirable(User user, ForumThread thread, int watchType, boolean expirable) throws UnauthorizedException { WatchList wList = getWatchList(user, watchType); long threadID = thread.getID(); boolean isWatched = wList.isWatchedThread(threadID); boolean isExpirable = wList.isWatchExpirable(threadID); // Only change the entry if it exists and if it's a change from the // current value.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?