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

📄 dbprofilemanager.java

📁 Jive 是一个系统工程
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/** * $RCSfile: DbProfileManager.java,v $ * $Revision: 1.4 $ * $Date: 2000/12/21 17:48:08 $ * * Copyright (C) 2000 CoolServlets.com. All rights reserved. * * =================================================================== * The Apache Software License, Version 1.1 * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. * * 3. The end-user documentation included with the redistribution, *    if any, must include the following acknowledgment: *       "This product includes software developed by *        CoolServlets.com (http://www.coolservlets.com)." *    Alternately, this acknowledgment may appear in the software itself, *    if and wherever such third-party acknowledgments normally appear. * * 4. The names "Jive" and "CoolServlets.com" must not be used to *    endorse or promote products derived from this software without *    prior written permission. For written permission, please *    contact webmaster@coolservlets.com. * * 5. Products derived from this software may not be called "Jive", *    nor may "Jive" appear in their name, without prior written *    permission of CoolServlets.com. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED.  IN NO EVENT SHALL COOLSERVLETS.COM OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of CoolServlets.com. For more information * on CoolServlets.com, please see <http://www.coolservlets.com>. */package com.coolservlets.forum.database;import java.util.*;import java.sql.*;import com.coolservlets.forum.*;import com.coolservlets.util.*;/** * Database implementation of the ProfileManager interface. */public class DbProfileManager implements ProfileManager {    /** DATABASE QUERIES **/    private static final String USER_GROUPS =        "SELECT groupID from jiveGroupUser WHERE userID=?";    private static final String USER_MESSAGE_COUNT =        "SELECT count(*) FROM jiveMessage,jiveForum,jiveThread WHERE " +        "jiveMessage.userID=? AND jiveForum.forumID=? AND " +        "jiveThread.forumID=jiveForum.forumID AND " +        "jiveMessage.threadID=jiveThread.threadID";    private static final String USER_COUNT = "SELECT count(*) FROM jiveUser";    private static final String ALL_USER_MESSAGES =        "SELECT messageID FROM jiveMessage WHERE userID=?";    private static final String DELETE_USER_MESSAGES =        "UPDATE jiveMessage set userID=-1 WHERE userID=?";    private static final String DELETE_USER_PERMS =        "DELETE FROM jiveUserPerm WHERE userID=?";    private static final String DELETE_USER_GROUPS =        "DELETE FROM jiveGroupUser WHERE userID=?";    private static final String DELETE_USER_PROPS =        "DELETE FROM jiveUserProp WHERE userID=?";    private static final String DELETE_USER =        "DELETE FROM jiveUser WHERE userID=?";    private static final String GROUP_COUNT = "SELECT count(*) FROM jiveGroup";    private static final String DELETE_GROUP_USERS =        "DELETE FROM jiveGroupUser WHERE groupID=?";    private static final String DELETE_GROUP =        "DELETE FROM jiveGroup WHERE groupID=?";    private User anonymousUser = null;    private User specialUser = null;    private DbForumFactory factory;    /**     * Creates a new ProfileManager.     */    public DbProfileManager(DbForumFactory factory) {        this.factory = factory;        try {            anonymousUser = getUser(-1);            specialUser = getUser(0);        }        catch (UserNotFoundException unfe) {  }    }    //FROM THE PROFILEMANAGER INTERFACE//    public User createUser(String username, String password, String email)            throws UserAlreadyExistsException    {        User newUser = null;        try {            User existingUser = getUser(username);            //The user already exists since now exception, so:            throw new UserAlreadyExistsException();        }        catch (UserNotFoundException unfe) {            //The user doesn't already exist so we can create a new user            newUser = new DbUser(username, password, email);        }        return newUser;    }    public User getUser(int userID) throws UserNotFoundException {        DbCacheManager cacheManager = factory.getCacheManager();        //If cache is not enabled, do a new lookup of object        if (!cacheManager.isCacheEnabled()) {            return new DbUser(userID);        }        //Cache is enabled.        Integer userIDInteger = new Integer(userID);        DbUser user = (DbUser)cacheManager.get(                DbCacheManager.USER_CACHE,                userIDInteger        );        if(user == null) {            user = new DbUser(userID);            cacheManager.add(DbCacheManager.USER_CACHE, userIDInteger, user);        }        return user;    }    public User getUser(String username) throws UserNotFoundException {        DbCacheManager cacheManager = factory.getCacheManager();        //If cache is not enabled, do a new lookup of object        if (!cacheManager.isCacheEnabled()) {            User user = new DbUser(username);            return getUser(user.getID());        }        //Cache is enabled.        CacheableInteger userIDInteger = (CacheableInteger)cacheManager.get(                DbCacheManager.USER_ID_CACHE,                username        );        //if id wan't found in cache, load it up and put it there.        if (userIDInteger == null) {            User user = new DbUser(username);            userIDInteger = new CacheableInteger(new Integer(user.getID()));            cacheManager.add(DbCacheManager.USER_ID_CACHE, username, userIDInteger);        }        return getUser(userIDInteger.getInteger().intValue());    }    public User getAnonymousUser() {        return anonymousUser;    }    public User getSpecialUser() {        return specialUser;    }    public void deleteUser(User user) throws UnauthorizedException {        int userID = user.getID();        int [] messages;        //Get array of all user's messages in the system so that        //we can expire them from cache.        ArrayList tempMessages = new ArrayList();        Connection con = null;        PreparedStatement pstmt = null;        try {            con = DbConnectionManager.getConnection();            pstmt = con.prepareStatement(ALL_USER_MESSAGES);            pstmt.setInt(1, user.getID());            ResultSet rs = pstmt.executeQuery();            while (rs.next()) {                tempMessages.add(new Integer(rs.getInt("messageID")));            }        }        catch( SQLException sqle ) {            System.err.println("Error in DbProfileManager:deleteUser()-" + sqle);            sqle.printStackTrace();        }        finally {            try {  pstmt.close(); }            catch (Exception e) { e.printStackTrace(); }            try {  con.close();   }            catch (Exception e) { e.printStackTrace(); }        }        //Now copy into an array.        messages = new int[tempMessages.size()];        for (int i=0; i<messages.length; i++) {            messages[i] = ((Integer)tempMessages.get(i)).intValue();        }        con = null;        pstmt = null;        try {            con = DbConnectionManager.getConnection();            //mark all message by user as anonymous            pstmt = con.prepareStatement(DELETE_USER_MESSAGES);            pstmt.setInt(1,userID);            pstmt.execute();            pstmt.close();            //remove all permissions given to user            pstmt = con.prepareStatement(DELETE_USER_PERMS);            pstmt.setInt(1,userID);            pstmt.execute();            pstmt.close();            //remove user from all groups            pstmt = con.prepareStatement(DELETE_USER_GROUPS);            pstmt.setInt(1,userID);            pstmt.execute();            pstmt.close();            //delete all of the users's extended properties            pstmt = con.prepareStatement(DELETE_USER_PROPS);            pstmt.setInt(1,userID);            pstmt.execute();            pstmt.close();            //delete the actual user entry            pstmt = con.prepareStatement(DELETE_USER);            pstmt.setInt(1,userID);            pstmt.execute();        }        catch( SQLException sqle ) {            sqle.printStackTrace();        }        finally {            try {  pstmt.close(); }            catch (Exception e) { e.printStackTrace(); }            try {  con.close();   }

⌨️ 快捷键说明

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