org.locomotive.loco.perm
Class Permission

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

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

Creates and maintains a single atomic permission. Also contains a cache for all the permissions presently in the database, and methods to access it, as well as methods to create and remove new permissions.

See Also:
Serialized Form

Field Summary
static int DB_TYPE
           
 
Constructor Summary
Permission(java.sql.Connection conn, java.lang.String name)
          Loads the permission object with the given name from the database, and puts it in the cache.
Permission(java.lang.String name, int id)
          Creates a permission associated by a name and id.
 
Method Summary
static Permission createPermission(java.sql.Connection conn, java.lang.String name)
          Creates a new permission and puts it in the cache.
static void deletePermission(java.sql.Connection conn, java.lang.String perm_name)
          deletes the permission with the specified name from the database
static boolean exists(java.lang.String permName)
          Checks the existence of a permission in the cache.
static Permission get(java.lang.String permName)
          Retrieves a permission from the permissions cache.
 int getId()
          Returns the id of the permission.
 java.lang.String getName()
          Returns the name of the permission.
static java.util.Vector getPermissions(java.sql.Connection conn)
          Returns all the permissions currently available.
static int getSize()
          Returns the number of permissions currently in the cache
static void initializeCache(java.sql.Connection conn)
          Reads permissions from the database and puts them into the permission hash.
static java.util.Vector names()
          Returns an Vector of all permission names presently in the cache.
static java.util.Enumeration permissions()
          Returns an enumeration of all the permissions currently in the cache
static void reloadCache(java.sql.Connection conn)
          Reloads the permissions from the database.
 java.lang.String toString()
          Method for displaying permissions- prints only the name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DB_TYPE

public static int DB_TYPE
Constructor Detail

Permission

public Permission(java.lang.String name,
                  int id)
Creates a permission associated by a name and id. This item is not put in the cache.
Parameters:
name - String name of the permission
id - int id of the permission

Permission

public Permission(java.sql.Connection conn,
                  java.lang.String name)
           throws java.sql.SQLException
Loads the permission object with the given name from the database, and puts it in the cache. To be used for atomic updates of the cache, or to ensure that the permission to be instantiated is the one in the database. To get a permission from the cache, use Permission.get();
Throws:
java.sql.SQLException - if we had database problems
See Also:
get(java.lang.String)
Method Detail

getName

public java.lang.String getName()
Returns the name of the permission.
Returns:
String name of the permission

getId

public int getId()
Returns the id of the permission.
Returns:
int id of the permission

initializeCache

public static void initializeCache(java.sql.Connection conn)
                            throws java.sql.SQLException
Reads permissions from the database and puts them into the permission hash. This function must be executed before any instances of this class are created.
Parameters:
conn - Connection object to the database
Throws:
java.sql.SQLException - if a database error occurs

reloadCache

public static void reloadCache(java.sql.Connection conn)
                        throws java.sql.SQLException
Reloads the permissions from the database. Use this to prevent inconsistency of data across multiple servers.
Parameters:
conn - the Database connection object
Throws:
java.sql.SQLException - if a database error occurs

get

public static Permission get(java.lang.String permName)
Retrieves a permission from the permissions cache. If the permission is not in the cache, then this returns null. To instantiate a permission directly from the database, use the constructor.
Parameters:
permName - String name of the permission to be retrieved

exists

public static boolean exists(java.lang.String permName)
Checks the existence of a permission in the cache. Does not check the database.
Parameters:
permName - String name of the permission

getSize

public static int getSize()
Returns the number of permissions currently in the cache

permissions

public static java.util.Enumeration permissions()
Returns an enumeration of all the permissions currently in the cache

names

public static java.util.Vector names()
Returns an Vector of all permission names presently in the cache. Don't confuse this with getPermissions(), which actually goes back to the database and returns the permissions ordered by name.
Returns:
Vector of String permission names

getPermissions

public static java.util.Vector getPermissions(java.sql.Connection conn)
                                       throws java.sql.SQLException
Returns all the permissions currently available. The vector contains a list of all the permissions sorted by their name, in ascending order. This goes directly to the database, bypassing the cache. The names() method retrieves from the cache and is more efficient.
Throws:
java.sql.SQLException - if we had database problems

createPermission

public static Permission createPermission(java.sql.Connection conn,
                                          java.lang.String name)
                                   throws java.sql.SQLException
Creates a new permission and puts it in the cache.
Returns:
the permission object, with the unique id it is associated with in the database.
Throws:
java.sql.SQLException - if we had database problems, or if a permission with that name already exists

deletePermission

public static void deletePermission(java.sql.Connection conn,
                                    java.lang.String perm_name)
                             throws java.sql.SQLException
deletes the permission with the specified name from the database

toString

public java.lang.String toString()
Method for displaying permissions- prints only the name
Overrides:
toString in class java.lang.Object