KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > Yasna > forum > Tasks > CleanAccounts


1 package com.Yasna.forum.Tasks;
2
3 import com.Yasna.forum.database.SystemProperty;
4 import com.Yasna.forum.database.DbConnectionManager;
5
6 import java.sql.Connection JavaDoc;
7 import java.sql.PreparedStatement JavaDoc;
8 import java.sql.SQLException JavaDoc;
9 import java.sql.ResultSet JavaDoc;
10
11 /**
12  * Copyright (C) 2001 Yasna.com. All rights reserved.
13  *
14  * ===================================================================
15  * The Apache Software License, Version 1.1
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions
19  * are met:
20  *
21  * 1. Redistributions of source code must retain the above copyright
22  * notice, this list of conditions and the following disclaimer.
23  *
24  * 2. Redistributions in binary form must reproduce the above copyright
25  * notice, this list of conditions and the following disclaimer in
26  * the documentation and/or other materials provided with the
27  * distribution.
28  *
29  * 3. The end-user documentation included with the redistribution,
30  * if any, must include the following acknowledgment:
31  * "This product includes software developed by
32  * Yasna.com (http://www.yasna.com)."
33  * Alternately, this acknowledgment may appear in the software itself,
34  * if and wherever such third-party acknowledgments normally appear.
35  *
36  * 4. The names "Yazd" and "Yasna.com" must not be used to
37  * endorse or promote products derived from this software without
38  * prior written permission. For written permission, please
39  * contact yazd@yasna.com.
40  *
41  * 5. Products derived from this software may not be called "Yazd",
42  * nor may "Yazd" appear in their name, without prior written
43  * permission of Yasna.com.
44  *
45  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
46  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48  * DISCLAIMED. IN NO EVENT SHALL YASNA.COM OR
49  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
52  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
54  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56  * SUCH DAMAGE.
57  * ====================================================================
58  *
59  * This software consists of voluntary contributions made by many
60  * individuals on behalf of Yasna.com. For more information
61  * on Yasna.com, please see <http://www.yasna.com>.
62  */

63
64 /**
65  * This class is used to remove the accounts that haven't been activated.
66  */

67 public class CleanAccounts {
68     private static final String JavaDoc GET_NOTACTIVE= "select distinct userID from yazdUserProp where name=?";
69     private static final String JavaDoc DELETE_PERMISSIONS =
70             "DELETE FROM yazdUserPerm WHERE userID=?";
71     private static final String JavaDoc DELETE_PROPERTIES =
72             "DELETE FROM yazdUserProp WHERE userID=?";
73     private static final String JavaDoc DELETE_GROUPS=
74             "delete from yazdGroupUser where userID=?";
75     private static final String JavaDoc DELETE_USER=
76              "delete from "+ SystemProperty.getProperty("User.Table")+" where "+SystemProperty.getProperty("User.Column.UserID")+"=?";
77     public CleanAccounts(){
78         Connection JavaDoc con = null;
79         PreparedStatement JavaDoc pstmt = null;
80         try {
81             con = DbConnectionManager.getConnection();
82             pstmt = con.prepareStatement(GET_NOTACTIVE);
83             pstmt.setString(1,"notactive");
84             ResultSet JavaDoc rs = pstmt.executeQuery();
85             while(rs.next()){
86                 int userid=rs.getInt("userID");
87                 pstmt = con.prepareStatement(DELETE_PERMISSIONS);
88                 pstmt.setInt(1,userid);
89                 pstmt.executeUpdate();
90                 pstmt = con.prepareStatement(DELETE_PROPERTIES);
91                 pstmt.setInt(1,userid);
92                 pstmt.executeUpdate();
93                 pstmt = con.prepareStatement(DELETE_GROUPS);
94                 pstmt.setInt(1,userid);
95                 pstmt.executeUpdate();
96                 pstmt = con.prepareStatement(DELETE_USER);
97                 pstmt.setInt(1,userid);
98                 pstmt.executeUpdate();
99             }
100         }
101         catch( SQLException JavaDoc sqle ) {
102             System.err.println("CleanAccounts (3) Exception:"+sqle.getMessage());
103             sqle.printStackTrace();
104         }
105         catch (Exception JavaDoc e) {
106             System.err.println("CleanAccounts (92) Exception:"+e.getMessage());
107         }
108         finally {
109             try { pstmt.close(); }
110             catch (Exception JavaDoc e) { e.printStackTrace(); }
111             try { con.close(); }
112             catch (Exception JavaDoc e) { e.printStackTrace(); }
113         }
114
115     }
116     
117 }
118
Popular Tags