Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Creative commons Attribution-NonCommercial license. http://creativecommons.org/licenses/by-nc/2.5/au/deed.en_GB NO WARRANTY IS GIVEN OR IMPLIED, USE AT YOUR OWN RISK.
 
 package base.jee.api.sql.util;
 
Check if the given token is allocated the specified role. Returns the personId if the person associated with this token does have the specified role. Returning the personId instead of true or false is slightly clunky, however in many cases it is saving having to do two separate queries against the database, which is a minor performance optimisation.
public class UserHasRole {

Check if the given token is allocated the specified role.

Parameters:
c
token
role
Returns:
Returns the personId if this person is allocated this role, otherwise returns 0.
Throws:
java.sql.SQLException
	public static UUID userHasRole(Connection cString tokenString rolethrows SQLException {
		UUID personUuid = null;
		PreparedStatement s = null;
				"select distinct t.person_uuid "+
				"from token t join role r on (t.token=? and t.person_uuid=r.person_uuid and r.role=? and r.resource is null and r.uid is null)");
		s.setString(1, token);
		s.setString(2, role);
		if(r.next()) {
			personUuid = UUID.fromString(r.getString(1));
		}
		r.close();
		s.close();
		return personUuid;
	}
New to GrepCode? Check out our FAQ X