001: package com.espada.bugtracker.app;
002:
003: // Java core API
004: import java.io.*;
005:
006: import java.sql.*;
007: import java.util.*;
008:
009: // Espada API
010: import com.espada.*;
011:
012: // Espada API
013: import org.webmacro.*;
014: import javax.servlet.*;
015:
016: // DB Connection Pool API
017: import com.sr.espada.se.util.db.pool.*;
018: import com.sr.espada.se.util.logwriter.LogWriter;
019: import com.sr.espada.se.util.config.ConfigFactory;
020:
021: /**
022:
023: * This is the User class.
024:
025: *
026:
027: * When an instance of User is created, the class searches the database for an<BR>
028:
029: * existing user with the corresponding user id, and fills up the object properties.<BR>
030:
031: *
032:
033: * <b>Currently not implemented! I add users manually for now ... </B><BR>
034:
035: * To create a new user in the database, the static method User.createUser() must be used.<BR>
036:
037: *
038:
039: *
040:
041: * @version: $Id: Roles.java,v 1.7 2001/04/16 06:45:47 manik Exp $<BR>
042:
043: * @author: Manik Surtani<BR>
044:
045: **/
046:
047: public class Roles {
048:
049: public int rid = 0;
050:
051: public Project roleProject;
052:
053: public User roleUser;
054:
055: public String roleDescription;
056:
057: public boolean found = true;
058:
059: public Roles() {
060:
061: //Default values
062:
063: }
064:
065: public Roles(int roleId) {
066:
067: try {
068:
069: Connection d = DatabaseConnectionPool.getConnection();
070: Statement st = d.createStatement();
071: ResultSet rs = st
072: .executeQuery("select * from roles where rid='"
073: + roleId + "'");
074:
075: while (rs.next()) {
076:
077: rid = rs.getInt(1);
078: roleDescription = rs.getString(2);
079: found = true;
080:
081: }
082:
083: st.close();
084: DatabaseConnectionPool.freeConnection(d);
085:
086: }
087:
088: catch (Exception E) {
089:
090: found = false;
091:
092: }
093:
094: LogWriter.write("User Role:" + String.valueOf(found));
095:
096: } //end of method Roles
097:
098: public static Vector getAllRoles() {
099: return getRoles("select rid from roles");
100: }
101:
102: public static Vector getAllRoles(int rid) {
103:
104: Vector r = new Vector();
105:
106: if (rid == 1) {
107: r = getRoles("select rid from roles");
108: } else if (rid == 2) {
109: r = getRoles("select rid from roles where rid > 2");
110: }
111: return r;
112:
113: }
114:
115: public static Vector getRoles(String SQL) {
116:
117: Vector v = new Vector();
118:
119: try {
120:
121: Connection d = DatabaseConnectionPool.getConnection();
122: Statement st = d.createStatement();
123: ResultSet rs = st.executeQuery(SQL);
124:
125: while (rs.next()) {
126:
127: v.add(new Roles(rs.getInt(1)));
128:
129: }
130:
131: st.close();
132: DatabaseConnectionPool.freeConnection(d);
133: return v;
134:
135: }
136:
137: catch (Exception E) {
138:
139: LogWriter.write("User Roles " + E.getMessage());
140: return v;
141:
142: }
143:
144: } //end of method getRoles
145:
146: public boolean update(int uid, int pid, int rid) {
147:
148: try {
149:
150: Connection d = DatabaseConnectionPool.getConnection();
151: Statement st = d.createStatement();
152: String SQL = "update projectuser set rid=" + rid
153: + " where uid=" + uid + " and pid=" + pid;
154: LogWriter.write(SQL);
155: int rs = st.executeUpdate(SQL);
156: st.close();
157: DatabaseConnectionPool.freeConnection(d);
158: return (rs != 0);
159:
160: }
161:
162: catch (Exception E) {
163:
164: return false;
165:
166: }
167:
168: } //end of method update
169:
170: } //end of class
|