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 UserHasResourceRole {

Check if the given token is allocated the specified role with a specific resource.

Parameters:
c
token
role
Returns:
Returns the personId if this person is allocated this role, otherwise returns 0.
Throws:
java.sql.SQLException
	public static long userHasResourceRole(Connection cString tokenString roleString resourceString uidthrows SQLException {
		long personId = 0;
		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=? and r.uid=?)");
		s.setString(1, token);
		s.setString(2, role);
		s.setString(3, resource);
		s.setString(4, uid);
		if(r.next()) {
			personId = r.getLong(1);
		}
		r.close();
		s.close();
		return personId;
	}
New to GrepCode? Check out our FAQ X