org.locomotive.loco.perm
Class RoleManager

java.lang.Object
  |
  +--org.locomotive.loco.perm.RoleManager

public class RoleManager
extends java.lang.Object
implements java.io.Serializable

Maintains all database transactions dealing with roles.

See Also:
Serialized Form

Constructor Summary
RoleManager()
           
 
Method Summary
static void addRole(Role role, java.sql.Connection conn)
          Adds a new role to the database.
static void addRoleToUser(int userId, java.lang.String roleName, java.sql.Connection conn)
          Adds a role to a user.
static boolean exists(java.lang.String roleName, java.sql.Connection conn)
          Verifies that a role exists in the DB.
static int getNextId(java.sql.Connection conn)
          Returns a unique id for a new role.
static Role getRole(java.lang.String roleName, java.sql.Connection conn)
          Returns a role object from the database via its name.
static java.util.Vector getRoleNames(java.sql.Connection conn)
          Returns an enumeration of all the role names in the database.
static java.util.Vector getRoleNamesForUser(int userId, java.sql.Connection conn)
          Lists all the role names associated with a user.
static Role getRolesForUser(int userid, java.sql.Connection conn)
          Returns a role of all the user's roles OR'ed together.
static void removeRole(java.lang.String roleName, java.sql.Connection conn)
          Removes an existing role from the database.
static void removeRoleFromUser(int userId, java.lang.String roleName, java.sql.Connection conn)
          Removes an existing role from a user.
static void updateRole(Role role, java.sql.Connection conn)
          Updates an existing role in the database with new information (for instance, new permissions that get removed or added to a role).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RoleManager

public RoleManager()
Method Detail

getNextId

public static int getNextId(java.sql.Connection conn)
                     throws java.sql.SQLException
Returns a unique id for a new role.
Returns:
int id for a new role
Throws:
java.sql.SQLException - if some database error occurs

addRole

public static void addRole(Role role,
                           java.sql.Connection conn)
                    throws java.sql.SQLException
Adds a new role to the database.
Parameters:
role - role to be added to the database
conn - database connection
Throws:
java.sql.SQLException - if some database error occurs

removeRole

public static void removeRole(java.lang.String roleName,
                              java.sql.Connection conn)
                       throws java.sql.SQLException
Removes an existing role from the database.
Parameters:
roleName - name of role to be removed from the database
conn - database connection
Throws:
java.sql.SQLException - if some database error occurs

updateRole

public static void updateRole(Role role,
                              java.sql.Connection conn)
                       throws java.sql.SQLException
Updates an existing role in the database with new information (for instance, new permissions that get removed or added to a role).
Parameters:
role - updated role
conn - database connection
Throws:
java.sql.SQLException - if some database error occurs

getRole

public static Role getRole(java.lang.String roleName,
                           java.sql.Connection conn)
                    throws java.sql.SQLException
Returns a role object from the database via its name.
Parameters:
roleName - name of role being retrieved from the database
conn - database connection
Returns:
Role object (null if role does not exist)
Throws:
java.sql.SQLException - if some database error occurs

getRoleNames

public static java.util.Vector getRoleNames(java.sql.Connection conn)
                                     throws java.sql.SQLException
Returns an enumeration of all the role names in the database.
Parameters:
conn - database connection
Returns:
Vector containing all role names in the database
Throws:
java.sql.SQLException - if some database error occurs

exists

public static boolean exists(java.lang.String roleName,
                             java.sql.Connection conn)
                      throws java.sql.SQLException
Verifies that a role exists in the DB.
Parameters:
roleName - name of role in question
conn - database connection
Returns:
true if a role with this name exists
Throws:
java.sql.SQLException - if some database error occurs

addRoleToUser

public static void addRoleToUser(int userId,
                                 java.lang.String roleName,
                                 java.sql.Connection conn)
                          throws java.sql.SQLException
Adds a role to a user.
Parameters:
userId - id of the user
roleName - name of the role being added to the user
conn - database connection
Throws:
java.sql.SQLException - if some database error occurs

removeRoleFromUser

public static void removeRoleFromUser(int userId,
                                      java.lang.String roleName,
                                      java.sql.Connection conn)
                               throws java.sql.SQLException
Removes an existing role from a user.
Parameters:
userId - id of the user
roleName - name of the role being removed from the user
conn - database connection
Throws:
java.sql.SQLException - if some database error occurs

getRoleNamesForUser

public static java.util.Vector getRoleNamesForUser(int userId,
                                                   java.sql.Connection conn)
                                            throws java.sql.SQLException
Lists all the role names associated with a user.
Parameters:
userId - id of the user
conn - database connection
Returns:
Vector of all role names for a user
Throws:
java.sql.SQLException - if some database error occurs

getRolesForUser

public static Role getRolesForUser(int userid,
                                   java.sql.Connection conn)
                            throws java.sql.SQLException
Returns a role of all the user's roles OR'ed together.
Parameters:
userId - id of the user
conn - database connection
Returns:
one role of all the roles 'Or'ed together
Throws:
java.sql.SQLException - if some database error occurs