1 41 package com.mvnforum.auth; 42 43 import java.sql.*; 44 import java.util.ArrayList ; 45 46 import org.apache.commons.logging.Log; 47 import org.apache.commons.logging.LogFactory; 48 import com.mvnforum.MVNForumConstant; 49 import com.mvnforum.db.*; 50 import net.myvietnam.mvncore.db.DBUtils; 51 import net.myvietnam.mvncore.exception.DatabaseException; 52 53 54 class MVNForumPermissionWebHelper { 55 56 private static Log log = LogFactory.getLog(MVNForumPermissionWebHelper.class); 57 58 private static final String MemberGroup = MemberGroupDAO.TABLE_NAME; 59 private static final String GroupPermission = GroupPermissionDAO.TABLE_NAME; 60 private static final String GroupForum = GroupForumDAO.TABLE_NAME; 61 private static final String MemberPermission= MemberPermissionDAO.TABLE_NAME; 62 private static final String MemberForum = MemberForumDAO.TABLE_NAME; 63 64 private MVNForumPermissionWebHelper() { 65 } 66 67 static ArrayList getMemberPermissions(int memberID) 68 throws DatabaseException { 69 70 Connection connection = null; 71 PreparedStatement statement = null; 72 ResultSet resultSet = null; 73 ArrayList retValue = new ArrayList (); 74 StringBuffer sql = new StringBuffer (512); 75 sql.append("SELECT DISTINCT Permission"); 76 sql.append(" FROM ").append(MemberPermission); 77 sql.append(" WHERE MemberID = ?"); 78 79 82 try { 83 connection = DBUtils.getConnection(); 84 statement = connection.prepareStatement(sql.toString()); 85 statement.setInt(1, memberID); 86 resultSet = statement.executeQuery(); 87 while (resultSet.next()) { 88 Integer perm = new Integer (resultSet.getInt("Permission")); 89 retValue.add(perm); 90 } 91 return retValue; 92 } catch(SQLException sqle) { 93 log.error("Sql Execution Error!", sqle); 94 throw new DatabaseException("Error executing SQL in MVNForumPermissionWebHelper.getMemberPermissions."); 95 } finally { 96 DBUtils.closeResultSet(resultSet); 97 DBUtils.closeStatement(statement); 98 DBUtils.closeConnection(connection); 99 } 100 } 101 102 static ArrayList getGroupPermissions(int memberID) 103 throws DatabaseException { 104 105 Connection connection = null; 106 PreparedStatement statement = null; 107 ResultSet resultSet = null; 108 ArrayList retValue = new ArrayList (); 109 StringBuffer sql = new StringBuffer (512); 110 sql.append("SELECT DISTINCT Permission"); 111 sql.append(" FROM ").append(GroupPermission).append(", ").append(MemberGroup); 112 sql.append(" WHERE ( (").append(GroupPermission).append(".GroupID = ").append(MemberGroup).append(".GroupID) AND (").append(MemberGroup).append(".MemberID = ?) )"); 113 if ((memberID!=0) && (memberID!=MVNForumConstant.MEMBER_ID_OF_GUEST)) { 114 sql.append(" OR ").append(GroupPermission).append(".GroupID = ").append(MVNForumConstant.GROUP_ID_OF_REGISTERED_MEMBERS); 115 } 116 117 120 try { 121 connection = DBUtils.getConnection(); 122 statement = connection.prepareStatement(sql.toString()); 123 statement.setInt(1, memberID); 124 resultSet = statement.executeQuery(); 125 while (resultSet.next()) { 126 Integer perm = new Integer (resultSet.getInt("Permission")); 127 retValue.add(perm); 128 } 129 return retValue; 130 } catch(SQLException sqle) { 131 log.error("Sql Execution Error!", sqle); 132 throw new DatabaseException("Error executing SQL in MVNForumPermissionWebHelper.getGroupPermissions."); 133 } finally { 134 DBUtils.closeResultSet(resultSet); 135 DBUtils.closeStatement(statement); 136 DBUtils.closeConnection(connection); 137 } 138 } 139 140 static ArrayList getMemberPermissionsInForums(int memberID) 141 throws DatabaseException { 142 143 Connection connection = null; 144 PreparedStatement statement = null; 145 ResultSet resultSet = null; 146 ArrayList retValue = new ArrayList (); 147 StringBuffer sql = new StringBuffer (512); 148 sql.append("SELECT DISTINCT ForumID, Permission"); 149 sql.append(" FROM ").append(MemberForum); 150 sql.append(" WHERE MemberID = ?"); 151 152 155 try { 156 connection = DBUtils.getConnection(); 157 statement = connection.prepareStatement(sql.toString()); 158 statement.setInt(1, memberID); 159 resultSet = statement.executeQuery(); 160 while (resultSet.next()) { 161 ForumPermission forumPermission = new ForumPermission(); 162 forumPermission.setForumID(resultSet.getInt("ForumID")); 163 forumPermission.setPermission(resultSet.getInt("Permission")); 164 retValue.add(forumPermission); 165 } 166 return retValue; 167 } catch(SQLException sqle) { 168 log.error("Sql Execution Error!", sqle); 169 throw new DatabaseException("Error executing SQL in MVNForumPermissionWebHelper.getMemberPermissionsInForums."); 170 } finally { 171 DBUtils.closeResultSet(resultSet); 172 DBUtils.closeStatement(statement); 173 DBUtils.closeConnection(connection); 174 } 175 } 176 177 static ArrayList getGroupPermissionsInForums(int memberID) 178 throws DatabaseException { 179 180 Connection connection = null; 181 PreparedStatement statement = null; 182 ResultSet resultSet = null; 183 ArrayList retValue = new ArrayList (); 184 StringBuffer sql = new StringBuffer (512); 185 sql.append("SELECT DISTINCT ForumID, Permission"); sql.append(" FROM ").append(GroupForum).append(", ").append(MemberGroup); 187 sql.append(" WHERE ( (").append(GroupForum).append(".GroupID = ").append(MemberGroup).append(".GroupID) AND (").append(MemberGroup).append(".MemberID = ?) )"); 188 if ((memberID!=0) && (memberID!=MVNForumConstant.MEMBER_ID_OF_GUEST)) { 189 sql.append(" OR ").append(GroupForum).append(".GroupID = ").append(MVNForumConstant.GROUP_ID_OF_REGISTERED_MEMBERS); 190 } 191 192 195 try { 196 connection = DBUtils.getConnection(); 197 statement = connection.prepareStatement(sql.toString()); 198 statement.setInt(1, memberID); 199 resultSet = statement.executeQuery(); 200 while (resultSet.next()) { 201 ForumPermission forumPermission = new ForumPermission(); 202 forumPermission.setForumID(resultSet.getInt("ForumID")); 203 forumPermission.setPermission(resultSet.getInt("Permission")); 204 retValue.add(forumPermission); 205 } 206 return retValue; 207 } catch(SQLException sqle) { 208 log.error("Sql Execution Error!", sqle); 209 throw new DatabaseException("Error executing SQL in MVNForumPermissionWebHelper.getGroupPermissionsInForums."); 210 } finally { 211 DBUtils.closeResultSet(resultSet); 212 DBUtils.closeStatement(statement); 213 DBUtils.closeConnection(connection); 214 } 215 } 216 217 static ArrayList getPermissionsForGroupGuest() 218 throws DatabaseException { 219 220 Connection connection = null; 221 PreparedStatement statement = null; 222 ResultSet resultSet = null; 223 ArrayList retValue = new ArrayList (); 224 StringBuffer sql = new StringBuffer (512); 225 sql.append("SELECT Permission"); 226 sql.append(" FROM ").append(GroupPermission); 227 sql.append(" WHERE GroupID = ").append(MVNForumConstant.GROUP_ID_OF_GUEST); 228 try { 229 connection = DBUtils.getConnection(); 230 statement = connection.prepareStatement(sql.toString()); 231 resultSet = statement.executeQuery(); 232 while (resultSet.next()) { 233 Integer perm = new Integer (resultSet.getInt("Permission")); 234 retValue.add(perm); 235 } 236 return retValue; 237 } catch(SQLException sqle) { 238 log.error("Sql Execution Error!", sqle); 239 throw new DatabaseException("Error executing SQL in MVNForumPermissionWebHelper.getPermissionsForGroupGuest."); 240 } finally { 241 DBUtils.closeResultSet(resultSet); 242 DBUtils.closeStatement(statement); 243 DBUtils.closeConnection(connection); 244 } 245 } 246 247 static ArrayList getPermissionsForGroupGuestInForums() 248 throws DatabaseException { 249 250 ArrayList retValue = new ArrayList (); 252 Connection connection = null; 253 PreparedStatement statement = null; 254 ResultSet resultSet = null; 255 StringBuffer sql = new StringBuffer (512); 256 sql.append("SELECT ForumID, Permission"); 257 sql.append(" FROM ").append(GroupForum); 258 sql.append(" WHERE GroupID = ").append(MVNForumConstant.GROUP_ID_OF_GUEST); 259 260 263 try { 264 connection = DBUtils.getConnection(); 265 statement = connection.prepareStatement(sql.toString()); 266 resultSet = statement.executeQuery(); 267 while (resultSet.next()) { 268 ForumPermission forumPermission = new ForumPermission(); 269 forumPermission.setForumID(resultSet.getInt("ForumID")); 270 forumPermission.setPermission(resultSet.getInt("Permission")); 271 retValue.add(forumPermission); 272 } 273 return retValue; 274 } catch(SQLException sqle) { 275 log.error("Sql Execution Error!", sqle); 276 throw new DatabaseException("Error executing SQL in MVNForumPermissionWebHelper.getPermissionsForGroupGuestInForum."); 277 } finally { 278 DBUtils.closeResultSet(resultSet); 279 DBUtils.closeStatement(statement); 280 DBUtils.closeConnection(connection); 281 } 282 } 283 284 } 285 | Popular Tags |