KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > smile > stored > s_editUserToGroup


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

17 public class s_editUserToGroup extends StoredProcedure implements ProcedureInterface {
18
19     // proprietes propres a cette stored proc
20
String JavaDoc in_userID;
21
22     String JavaDoc in_groupID;
23
24     String JavaDoc ifexists;
25
26     public s_editUserToGroup() {
27     }
28
29     public void init(HashMap initData, Connection con) {
30         // on initialise le hashmap de donnees et la connection de l'objet
31
super.init(initData, con);
32         // on initialise les propprietes de l'objet
33
in_userID = utils.getString(data, "USERID", "");
34         in_groupID = utils.getString(data, "GROUPID", "");
35         action = utils.getString(data, "ACTION", "");
36     }
37
38     public void checkAction() throws SQLException {
39         ifexists = execStatementToValue("SELECT count(*) FROM tblpermusergroup WHERE userID = " + in_userID + " AND groupID = " + in_groupID);
40         close();
41     }
42
43     public void checkParams() throws SQLException {
44     }
45
46     public void executeAction() throws SQLException {
47         if (ifexists.equals("0")) {
48             if (action.equals("1")) {
49                 StringBuffer JavaDoc v_sb = new StringBuffer JavaDoc();
50                 v_sb.append("INSERT into tblpermusergroup ").append(" values (" + in_userID + ", " + in_groupID + ")");
51
52                 execStatement(v_sb.toString());
53             }
54         } else if (ifexists.equals("1")) {
55             if (action.equals("0")) {
56                 StringBuffer JavaDoc v_sb = new StringBuffer JavaDoc();
57                 v_sb.append("DELETE FROM tblpermusergroup ").append(" WHERE userID = " + in_userID + " ").append(" AND groupID = " + in_groupID);
58
59                 execStatement(v_sb.toString());
60             }
61         }
62         execStatementToRS(queryResultOk);
63     }
64 }
Popular Tags