org.locomotive.loco.perm
Class GroupManager

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

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

Maintains all database transactions dealing with groups.

See Also:
Serialized Form

Constructor Summary
GroupManager()
           
 
Method Summary
static void addGroup(Group group, java.sql.Connection conn)
          Adds a new group to the database.
static void addUserToGroup(int groupId, int userId, java.sql.Connection conn)
          Adds a user to a group.
static int convertToGroupId(java.lang.String groupName, java.sql.Connection conn)
          Converts a group name into a group id.
static java.util.Vector convertToGroupIds(java.util.Vector groupNames, java.sql.Connection conn)
          Converts a Vector of group names into a Vector of group ids.
static java.lang.String convertToGroupName(int groupId, java.sql.Connection conn)
          Converts a group id into a group name.
static java.util.Vector convertToGroupNames(java.util.Vector groupIds, java.sql.Connection conn)
          Converts a Vector of group ids into a Vector of group names.
static boolean exists(java.lang.String groupName, java.sql.Connection conn)
          Verifies that a group exists in the DB.
static Group getGroup(java.lang.String groupName, java.sql.Connection conn)
          Returns a group object from the database via its name.
static java.util.Vector getGroupNames(java.sql.Connection conn)
          Returns an enumeration of all the group names in the database.
static int getNextId(java.sql.Connection conn)
          Returns a unique id for a new group.
static java.util.Vector getUserIdsFromGroup(int groupId, java.sql.Connection conn)
          Lists all the user ids contained in a group.
static void removeGroup(java.lang.String groupName, java.sql.Connection conn)
          Removes an existing group from the database.
static void removeUserFromGroup(int groupId, int userId, java.sql.Connection conn)
          Removes an existing user from a group.
static void updateGroup(Group group, java.sql.Connection conn)
          Updates an existing group in the database with new information.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GroupManager

public GroupManager()
Method Detail

getNextId

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

addGroup

public static void addGroup(Group group,
                            java.sql.Connection conn)
                     throws java.sql.SQLException
Adds a new group to the database. Only adds the existence of the group, not any of the users. Use addUserToGroup or updateGroup to add users to the group (after calling this function to initially create the group).
Parameters:
group - group to be added to the database
conn - database connection
Throws:
java.sql.SQLException - if some database error occurs

removeGroup

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

updateGroup

public static void updateGroup(Group group,
                               java.sql.Connection conn)
                        throws java.sql.SQLException,
                               LoadUserException,
                               UserNotFoundException
Updates an existing group in the database with new information.
Parameters:
group - updated group
conn - database connection
Throws:
java.sql.SQLException - if some database error occurs
LoadUserException - when a user cannot be loaded
UserNotFoundException - when a user does not exist in the db

getGroup

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

addUserToGroup

public static void addUserToGroup(int groupId,
                                  int userId,
                                  java.sql.Connection conn)
                           throws java.sql.SQLException
Adds a user to a group.
Parameters:
groupId - id of the group
userId - id of the user being added to the group
conn - database connection
Throws:
java.sql.SQLException - if some database error occurs

removeUserFromGroup

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

getUserIdsFromGroup

public static java.util.Vector getUserIdsFromGroup(int groupId,
                                                   java.sql.Connection conn)
                                            throws java.sql.SQLException
Lists all the user ids contained in a group.
Parameters:
groupId - id of the group
conn - database connection
Returns:
Vector of user ids contained in the group
Throws:
java.sql.SQLException - if some database error occurs

getGroupNames

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

exists

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

convertToGroupId

public static int convertToGroupId(java.lang.String groupName,
                                   java.sql.Connection conn)
                            throws java.sql.SQLException
Converts a group name into a group id.
Parameters:
groupName - name of group
conn - database connection
Returns:
int id of group (-1 if group does not exist)
Throws:
java.sql.SQLException - if some database error occurs

convertToGroupIds

public static java.util.Vector convertToGroupIds(java.util.Vector groupNames,
                                                 java.sql.Connection conn)
                                          throws java.sql.SQLException
Converts a Vector of group names into a Vector of group ids.
Parameters:
groupNames - Vector containing the names of groups
conn - database connection
Returns:
Vector of group ids
Throws:
java.sql.SQLException - if some database error occurs

convertToGroupName

public static java.lang.String convertToGroupName(int groupId,
                                                  java.sql.Connection conn)
                                           throws java.sql.SQLException
Converts a group id into a group name.
Parameters:
groupId - id of group
conn - database connection
Returns:
String name of group (null if group does not exist)
Throws:
java.sql.SQLException - if some database error occurs

convertToGroupNames

public static java.util.Vector convertToGroupNames(java.util.Vector groupIds,
                                                   java.sql.Connection conn)
                                            throws java.sql.SQLException
Converts a Vector of group ids into a Vector of group names.
Parameters:
groupIds - Vector containing the ids of groups
conn - database connection
Returns:
Vector of group names
Throws:
java.sql.SQLException - if some database error occurs