1 2 package com.espada.bugtracker.app; 3 4 5 import java.io.*; 7 8 import java.sql.*; 9 import java.util.*; 10 11 12 import com.espada.*; 14 15 16 import org.webmacro.*; 18 import javax.servlet.*; 19 20 21 import com.espada.bugtracker.persistence.*; 23 24 25 26 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 roleDescription; 65 66 public boolean found = true; 67 68 public Roles() 69 { 70 71 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 E) 101 { 102 103 found = false; 104 105 } 106 107 108 109 } 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 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 E) 165 { 166 167 return v; 168 169 } 170 171 } 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 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 E) 192 { 193 194 return false; 195 196 } 197 198 199 } 201 202 } | Popular Tags |