1 43 package net.jforum.dao.mysql.security; 44 45 import java.sql.PreparedStatement ; 46 import java.sql.ResultSet ; 47 48 import net.jforum.JForumExecutionContext; 49 import net.jforum.dao.generic.security.GenericGroupSecurityDAO; 50 import net.jforum.util.preferences.SystemGlobals; 51 52 58 public class MySQL323GroupSecurityDAO extends GenericGroupSecurityDAO 59 { 60 63 public void deleteAllRoles(int id) throws Exception 64 { 65 PreparedStatement p = JForumExecutionContext.getConnection().prepareStatement( 66 SystemGlobals.getSql("PermissionControl.getRoleIdsByGroup")); 67 p.setInt(1, id); 68 69 String roleIds = this.getCsvIdList(p); 70 71 p.close(); 72 73 if (roleIds.length() == 0) { 74 return; 75 } 76 77 p = this.getStatementForCsv( 78 SystemGlobals.getSql("PermissionControl.deleteRoleValuesByRoleId"), 79 roleIds); 80 81 p.executeUpdate(); 82 p.close(); 83 } 84 85 93 protected PreparedStatement getStatementForCsv(String sql, String csv) throws Exception 94 { 95 int index = sql.indexOf('?'); 96 sql = sql.substring(0, index) + csv + sql.substring(index + 1); 97 return JForumExecutionContext.getConnection().prepareStatement(sql); 98 } 99 100 107 protected String getCsvIdList(PreparedStatement p) throws Exception 108 { 109 ResultSet rs = p.executeQuery(); 110 111 StringBuffer sb = new StringBuffer (); 112 113 while (rs.next()) { 114 sb.append(rs.getInt(1)).append(","); 115 } 116 117 sb.append("-1"); 118 119 rs.close(); 120 121 return sb.toString(); 122 } 123 } 124 | Popular Tags |