KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > smile > stored > s_editUser


1 package smile.stored;
2
3 import java.util.*;
4 import java.sql.*;
5
6 /**
7  * s_editUser is an implements the ProcedureInterface and is a sub-class of
8  * StoredProcedure. This class updates or inserts users in the database.
9  *
10  * Copyright 2002 Smile Les motoristes Internet http://www.smile.fr/ Contact
11  * cofax@smile.fr for further information
12  *
13  * @author Smile Les motoristes Internet
14  * @author Lee Bolding
15  */

16 public class s_editUser extends StoredProcedure implements ProcedureInterface {
17
18     // proprietes propres a cette stored proc
19
String JavaDoc in_userID;
20
21     String JavaDoc in_userName;
22
23     String JavaDoc in_userPassword;
24
25     String JavaDoc in_lastName;
26
27     String JavaDoc in_firstName;
28
29     String JavaDoc in_homepub;
30
31     String JavaDoc in_email;
32
33     String JavaDoc in_workPhone;
34
35     String JavaDoc in_cellPhone;
36
37     String JavaDoc include;
38
39     String JavaDoc in_pager;
40
41     String JavaDoc in_notes;
42
43     String JavaDoc duplicateUser;
44
45     String JavaDoc in_newuserid;
46
47     public s_editUser() {
48
49     }
50
51     public void init(HashMap initData, Connection con) {
52         // on initialise le hashmap de donnees et la connection de l'objet
53
super.init(initData, con);
54         // on initialise les propprietes de l'objet
55
in_userID = utils.getString(data, "USERID", "");
56         in_userName = utils.getString(data, "USERNAME", "");
57         in_userPassword = utils.getString(data, "USERPASSWORD", "");
58         in_lastName = utils.getString(data, "LASTNAME", "");
59         in_firstName = utils.getString(data, "FIRSTNAME", "");
60         in_homepub = utils.getString(data, "HOMEPUB", "");
61         in_email = utils.getString(data, "EMAIL", "");
62         in_workPhone = utils.getString(data, "WORKPHONE", "");
63         in_cellPhone = utils.getString(data, "CELLPHONE", "");
64         in_pager = utils.getString(data, "PAGER", "");
65         in_notes = utils.getString(data, "NOTES", "");
66     }
67
68     public void checkParams() throws SQLException {
69     }
70
71     public void checkAction() throws SQLException {
72         if (in_userID.equals("0")) {
73             action = "insert";
74         } else {
75             action = "update";
76         }
77     }
78
79     public void executeAction() throws SQLException {
80         String JavaDoc v_select = "";
81         v_select = "select " + in_userID + " as USERID";
82
83         if (action.equals("update")) {
84             StringBuffer JavaDoc v_sb = new StringBuffer JavaDoc();
85             v_sb.append("UPDATE tblpermusers ").append(" SET username = '" + in_userName + "',");
86             if (!(in_userPassword.equals("")))
87                 v_sb.append(" userpassword = MD5('" + in_userName + ":" + in_userPassword + "'),");
88             v_sb.append(" lastname = '" + in_lastName + "',").append(" firstname = '" + in_firstName + "',").append(" homepub = " + in_homepub + ",").append(
89                     " email = '" + in_email + "',").append(" workphone = '" + in_workPhone + "',").append(" cellphone = '" + in_cellPhone + "',").append(
90                     " pager = '" + in_pager + "',").append(" notes = '" + in_notes + "'").append(" WHERE userid = " + in_userID);
91             execStatement(v_sb.toString());
92
93         } else if (action.equals("insert")) {
94             StringBuffer JavaDoc v_sbSelect = new StringBuffer JavaDoc();
95             v_sbSelect.append("SELECT count(*) ").append(" FROM tblpermusers ").append(" WHERE userName = '" + in_userName + "'");
96
97             duplicateUser = execStatementToValue(v_sbSelect.toString());
98
99             if (Integer.parseInt(duplicateUser) > 0) {
100                 duplicateUser = in_userName;
101             } else {
102                 StringBuffer JavaDoc v_sbInsert = new StringBuffer JavaDoc();
103                 v_sbInsert.append("INSERT INTO tblpermusers ").append(
104                         "(username, userpassword, lastname, firstname, homepub, email, workphone, cellphone, pager, notes)").append(
105                         " VALUES ('" + in_userName + "', MD5('" + in_userName + ":" + in_userPassword + "'), '" + in_lastName + "', '" + in_firstName + "', "
106                                 + in_homepub + ", '" + in_email + "', '" + in_workPhone + "', '" + in_cellPhone + "', '" + in_pager + "', '" + in_notes + "')");
107
108                 // we synchronize this code in order to get the good user ID
109
synchronized (this) {
110                     execStatement(v_sbInsert.toString());
111
112                     // get back the userID Max
113
String JavaDoc new_userID = getMax("tblpermusers", "userid");
114                     v_select = "select " + new_userID + " as USERID";
115                 }
116             }
117         }
118         execStatementToRS(v_select);
119     }
120 }
121
Popular Tags