1 package org.apache.fulcrum.security.impl.db.entity; 2 3 56 57 import java.util.List ; 58 59 import org.apache.fulcrum.security.TurbineSecurity; 60 import org.apache.fulcrum.security.entity.Group; 61 import org.apache.fulcrum.security.entity.Role; 62 import org.apache.fulcrum.security.entity.User; 63 import org.apache.fulcrum.security.impl.db.DBSecurityService; 64 import org.apache.fulcrum.security.util.DataBackendException; 65 import org.apache.fulcrum.security.util.RoleSet; 66 import org.apache.torque.om.Persistent; 67 import org.apache.torque.util.BasePeer; 68 import org.apache.torque.util.Criteria; 69 70 80 public class TurbineRolePeer 81 extends org.apache.fulcrum.security.impl.db.entity.BaseTurbineRolePeer 82 { 83 84 public static final String NAME = ROLE_NAME; 85 86 96 public static boolean checkExists(Role role) 97 throws DataBackendException, Exception 98 { 99 Criteria criteria = new Criteria(); 100 criteria.addSelectColumn(ROLE_ID); 101 criteria.add(NAME, role.getName()); 102 List results = BasePeer.doSelect(criteria); 103 if (results.size() > 1) 104 { 105 throw new DataBackendException("Multiple roles named '" + 106 role.getName() + "' exist!"); 107 } 108 return (results.size() == 1); 109 } 110 111 116 public static String getColumnName(String name) 117 { 118 StringBuffer sb = new StringBuffer (); 119 sb.append(TurbineRolePeer.TABLE_NAME); 120 sb.append("."); 121 sb.append(name); 122 return sb.toString(); 123 } 124 125 130 public static String getTableName() 131 { 132 return TABLE_NAME; 133 } 134 135 138 public static RoleSet retrieveSet(Criteria criteria) throws Exception 139 { 140 List results = doSelect(criteria); 141 RoleSet rs = new RoleSet(); 142 for (int i=0; i<results.size(); i++) 143 { 144 rs.add( (Role)results.get(i) ); 145 } 146 return rs; 147 } 148 149 157 public static RoleSet retrieveSet(User user, Group group) 158 throws Exception 159 { 160 Criteria criteria = new Criteria(); 161 162 169 UserPeer up = ((DBSecurityService)TurbineSecurity.getService()) 170 .getUserPeerInstance(); 171 172 criteria.add(TurbineUserPeer.USERNAME, user.getUserName()); 173 criteria.add(TurbineUserGroupRolePeer.GROUP_ID, 174 ((Persistent)group).getPrimaryKey()); 175 176 criteria.addJoin(TurbineUserPeer.USER_ID, TurbineUserGroupRolePeer.USER_ID); 177 criteria.addJoin(TurbineUserGroupRolePeer.ROLE_ID, TurbineRolePeer.ROLE_ID); 178 return retrieveSet(criteria); 179 } 180 181 } 182 | Popular Tags |