KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > smile > stored > s_editGroup


1 package smile.stored;
2
3 import java.util.*;
4 import java.sql.*;
5
6 /**
7  * s_editGroup is an implements the ProcedureInterface and is a sub-class of
8  * StoredProcedure. This class updates or inserts groups 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  *
15  */

16 public class s_editGroup extends StoredProcedure implements ProcedureInterface {
17
18     // proprietes propres a cette stored proc
19
String JavaDoc in_groupID;
20
21     String JavaDoc in_groupName;
22
23     String JavaDoc in_groupDesc;
24
25     String JavaDoc in_groupType;
26
27     String JavaDoc in_newgroupid;
28
29     public s_editGroup() {
30     }
31
32     public void init(HashMap initData, Connection con) {
33         // on initialise le hashmap de donnees et la connection de l'objet
34
super.init(initData, con);
35         // on initialise les propprietes de l'objet
36
in_groupID = utils.getString(data, "GROUPID", "");
37         in_groupName = utils.getString(data, "GROUPNAME", "");
38         in_groupDesc = utils.getString(data, "GROUPDESC", "");
39         in_groupType = utils.getString(data, "GROUPTYPE", "");
40     }
41
42     public void checkParams() throws SQLException {
43     }
44
45     public void checkAction() throws SQLException {
46         if (in_groupID.equals("0")) {
47             action = "insert";
48         } else {
49             action = "update";
50         }
51     }
52
53     public void executeAction() throws SQLException {
54         String JavaDoc v_select = "";
55         v_select = "select " + in_groupID + " as GROUPID";
56
57         if (action.equals("update")) {
58             StringBuffer JavaDoc v_sb = new StringBuffer JavaDoc();
59             v_sb.append("UPDATE tblpermgroups ").append(" SET groupname = '" + in_groupName + "',").append(" groupdesc = '" + in_groupDesc + "',").append(
60                     " grouptype = " + in_groupType).append(" WHERE groupid = " + in_groupID);
61
62             execStatement(v_sb.toString());
63         } else if (action.equals("insert")) {
64             StringBuffer JavaDoc v_sb = new StringBuffer JavaDoc();
65             v_sb.append("INSERT INTO tblpermgroups ").append("(groupname, groupdesc, grouptype)").append(
66                     " VALUES ('" + in_groupName + "', '" + in_groupDesc + "', " + in_groupType + ")");
67
68             // we synchronize this code in order to get the good group ID
69
synchronized (this) {
70                 execStatement(v_sb.toString());
71
72                 // get back the grouID Max
73
String JavaDoc new_groupID = getMax("tblpermgroups", "groupid");
74                 v_select = "select " + new_groupID + " as GROUPID";
75             }
76         }
77         execStatementToRS(v_select);
78     }
79 }
Popular Tags