KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > espada > bugtracker > app > Roles


1
2 package com.espada.bugtracker.app;
3
4
5 // Java core API
6
import java.io.*;
7
8 import java.sql.*;
9 import java.util.*;
10
11
12 // Espada API
13
import com.espada.*;
14
15
16 // Espada API
17
import org.webmacro.*;
18 import javax.servlet.*;
19
20
21 // DB Connection Pool API
22
import com.espada.bugtracker.persistence.*;
23
24
25
26 /**
27
28 * This is the User class.
29
30 *
31
32 * When an instance of User is created, the class searches the database for an<BR>
33
34 * existing user with the corresponding user id, and fills up the object properties.<BR>
35
36 *
37
38 * <b>Currently not implemented! I add users manually for now ... </B><BR>
39
40 * To create a new user in the database, the static method User.createUser() must be used.<BR>
41
42 *
43
44 *
45
46 * @version: $Id: Roles.java,v 1.9 2001/04/17 12:43:02 manik Exp $<BR>
47
48 * @author: Manik Surtani<BR>
49
50 **/

51
52
53
54 public class Roles
55 {
56
57
58 public int rid = 0;
59
60 public Project roleProject;
61
62 public User roleUser;
63
64 public String JavaDoc roleDescription;
65
66 public boolean found = true;
67
68   public Roles()
69   {
70   
71         //Default values
72

73   }
74
75
76   public Roles(int roleId)
77   {
78
79         try
80         {
81
82           Connection d = DatabaseConnectionPool.getConnection();
83           Statement st = d.createStatement();
84           ResultSet rs = st.executeQuery("select * from roles where rid='" + roleId + "'");
85
86           while (rs.next())
87           {
88
89                rid = rs.getInt(1);
90                roleDescription = rs.getString(2);
91                found = true;
92
93           }
94
95           st.close();
96           DatabaseConnectionPool.freeConnection(d);
97
98         }
99
100         catch (Exception JavaDoc E)
101         {
102
103                found = false;
104
105         }
106
107
108
109   } //end of method Roles
110

111
112   public static Vector getAllRoles()
113   {
114       return getRoles("select rid from roles");
115   }
116
117   public static Vector getAllRoles(int rid)
118   {
119     
120     Vector r = new Vector();
121
122         if(rid == 1)
123         {
124              r = getRoles("select rid from roles");
125         }
126         else
127             if(rid == 2)
128             {
129                r = getRoles("select rid from roles where rid > 2");
130             }
131     return r;
132
133   }
134
135
136
137
138
139   public static Vector getRoles(String JavaDoc SQL)
140   {
141
142     Vector v = new Vector();
143
144         try
145         {
146
147             Connection d = DatabaseConnectionPool.getConnection();
148             Statement st = d.createStatement();
149             ResultSet rs = st.executeQuery(SQL);
150
151             while (rs.next())
152             {
153
154                     v.add( new Roles( rs.getInt( 1 ) ) );
155
156             }
157
158             st.close();
159             DatabaseConnectionPool.freeConnection(d);
160             return v;
161
162         }
163
164         catch (Exception JavaDoc E)
165         {
166
167              return v;
168
169         }
170
171   } //end of method getRoles
172

173
174
175   public boolean update(int uid,int pid,int rid)
176   {
177
178         try
179         {
180
181             Connection d = DatabaseConnectionPool.getConnection();
182             Statement st = d.createStatement();
183             String JavaDoc SQL = "update projectuser set rid=" + rid + " where uid=" + uid + " and pid=" + pid;
184             int rs = st.executeUpdate(SQL);
185             st.close();
186             DatabaseConnectionPool.freeConnection(d);
187             return (rs != 0);
188
189         }
190
191         catch (Exception JavaDoc E)
192         {
193
194                  return false;
195
196         }
197
198
199   } //end of method update
200

201
202 } //end of class
Popular Tags