001: package com.Yasna.forum.Tasks;
002:
003: import com.Yasna.forum.database.SystemProperty;
004: import com.Yasna.forum.database.DbConnectionManager;
005:
006: import java.sql.Connection;
007: import java.sql.PreparedStatement;
008: import java.sql.SQLException;
009: import java.sql.ResultSet;
010:
011: /**
012: * Copyright (C) 2001 Yasna.com. All rights reserved.
013: *
014: * ===================================================================
015: * The Apache Software License, Version 1.1
016: *
017: * Redistribution and use in source and binary forms, with or without
018: * modification, are permitted provided that the following conditions
019: * are met:
020: *
021: * 1. Redistributions of source code must retain the above copyright
022: * notice, this list of conditions and the following disclaimer.
023: *
024: * 2. Redistributions in binary form must reproduce the above copyright
025: * notice, this list of conditions and the following disclaimer in
026: * the documentation and/or other materials provided with the
027: * distribution.
028: *
029: * 3. The end-user documentation included with the redistribution,
030: * if any, must include the following acknowledgment:
031: * "This product includes software developed by
032: * Yasna.com (http://www.yasna.com)."
033: * Alternately, this acknowledgment may appear in the software itself,
034: * if and wherever such third-party acknowledgments normally appear.
035: *
036: * 4. The names "Yazd" and "Yasna.com" must not be used to
037: * endorse or promote products derived from this software without
038: * prior written permission. For written permission, please
039: * contact yazd@yasna.com.
040: *
041: * 5. Products derived from this software may not be called "Yazd",
042: * nor may "Yazd" appear in their name, without prior written
043: * permission of Yasna.com.
044: *
045: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
046: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
047: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
048: * DISCLAIMED. IN NO EVENT SHALL YASNA.COM OR
049: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
050: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
051: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
052: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
053: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
054: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
055: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
056: * SUCH DAMAGE.
057: * ====================================================================
058: *
059: * This software consists of voluntary contributions made by many
060: * individuals on behalf of Yasna.com. For more information
061: * on Yasna.com, please see <http://www.yasna.com>.
062: */
063:
064: /**
065: * This class is used to remove the accounts that haven't been activated.
066: */
067: public class CleanAccounts {
068: private static final String GET_NOTACTIVE = "select distinct userID from yazdUserProp where name=?";
069: private static final String DELETE_PERMISSIONS = "DELETE FROM yazdUserPerm WHERE userID=?";
070: private static final String DELETE_PROPERTIES = "DELETE FROM yazdUserProp WHERE userID=?";
071: private static final String DELETE_GROUPS = "delete from yazdGroupUser where userID=?";
072: private static final String DELETE_USER = "delete from "
073: + SystemProperty.getProperty("User.Table") + " where "
074: + SystemProperty.getProperty("User.Column.UserID") + "=?";
075:
076: public CleanAccounts() {
077: Connection con = null;
078: PreparedStatement pstmt = null;
079: try {
080: con = DbConnectionManager.getConnection();
081: pstmt = con.prepareStatement(GET_NOTACTIVE);
082: pstmt.setString(1, "notactive");
083: ResultSet rs = pstmt.executeQuery();
084: while (rs.next()) {
085: int userid = rs.getInt("userID");
086: pstmt = con.prepareStatement(DELETE_PERMISSIONS);
087: pstmt.setInt(1, userid);
088: pstmt.executeUpdate();
089: pstmt = con.prepareStatement(DELETE_PROPERTIES);
090: pstmt.setInt(1, userid);
091: pstmt.executeUpdate();
092: pstmt = con.prepareStatement(DELETE_GROUPS);
093: pstmt.setInt(1, userid);
094: pstmt.executeUpdate();
095: pstmt = con.prepareStatement(DELETE_USER);
096: pstmt.setInt(1, userid);
097: pstmt.executeUpdate();
098: }
099: } catch (SQLException sqle) {
100: System.err.println("CleanAccounts (3) Exception:"
101: + sqle.getMessage());
102: sqle.printStackTrace();
103: } catch (Exception e) {
104: System.err.println("CleanAccounts (92) Exception:"
105: + e.getMessage());
106: } finally {
107: try {
108: pstmt.close();
109: } catch (Exception e) {
110: e.printStackTrace();
111: }
112: try {
113: con.close();
114: } catch (Exception e) {
115: e.printStackTrace();
116: }
117: }
118:
119: }
120:
121: }
|