org.davesag.generica.peer
Class UserPeer

java.lang.Object
  extended byorg.davesag.generica.peer.UserPeer

public class UserPeer
extends Object

This peer manipulates Users using hibernate.

Since:
Generica 1.0
Version:
CVS Revision $Id: UserPeer.java,v 1.23 2004/04/03 11:22:50 davesag Exp $
Author:
Dave Sag http://www.davesag.com

Constructor Summary
UserPeer()
           
 
Method Summary
static boolean active(Session sess, String name, String userclass)
          A quick tests to determine if there is an active user object with the given name, using the supplied classname as qualifiers of the search.
static User ctLogin(Session sess, String username, String password, String userclass)
          Retrieve the User with the supplied username and cleartext password, if valid and the user is active.
static void delete(Session sess, User user)
          Delete this user.
static boolean exists(Session sess, String username, String userclass)
          A quick tests to determine if the username supplied matched a known user, whether active or inactive.
static User load(Session sess, String username, String userclass)
          Retrieve the User with the supplied username only, if valid, irrespecive of their active status.
static List loadAll(Session sess, String classname, String sort)
          loads all the users of the given optional classname and sort order.
static User login(Session sess, String username, String password, String userclass)
          Retrieve the User with the supplied username and cleartext password, if valid and the user is active.
static Long save(Session sess, User user)
          Save this user.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UserPeer

public UserPeer()
Method Detail

save

public static Long save(Session sess,
                        User user)
Save this user.

Parameters:
sess - The Session to use to save the user. The session will be flushed but not closed.
user - The user.
Returns:
The ID of the saved user, or null if there was an error.

delete

public static void delete(Session sess,
                          User user)
Delete this user.

NOTE: if an user is deleted any text they wrote will be left in an inconsistant state. hence we only allow the user to be deleted if they have not authored any texts. and simply deactivate them if they have.

Parameters:
sess - The Session to use to delete the user. The session will be flushed but not closed.
user - The user.

exists

public static boolean exists(Session sess,
                             String username,
                             String userclass)
A quick tests to determine if the username supplied matched a known user, whether active or inactive.

Parameters:
sess - The Session to use to query for the user.
username - The username to test.
userclass - The fully qualified class of user to test. Typically a site will have many kinds of users, eg admin users, subscribers and so forth.
Returns:
true if the username supplied corresponds to a known user.

load

public static User load(Session sess,
                        String username,
                        String userclass)
Retrieve the User with the supplied username only, if valid, irrespecive of their active status. Do not use this to log a user in, use login instead.

Parameters:
sess - The Session to use to query for the user.
username - The username of the user we wish to login.
userclass - The fully qualified class of user to test. Typically a site will have many kinds of users, eg admin users, subscribers and so forth.
Returns:
The matching User if the username matches exactly one User, or null if not.

active

public static boolean active(Session sess,
                             String name,
                             String userclass)
A quick tests to determine if there is an active user object with the given name, using the supplied classname as qualifiers of the search. Use this test if your application wishes to do a quick check on the status of a user by name.

Parameters:
sess - The Session to use to query for the persistable object.
name - The name The actual name we are looking for.
userclass - The fully qualified class of the persistable bean to test for.
Returns:
true if the name supplied corresponds to a known persistable object.
Throws:
RuntimeException - if the params were invalid, or if there was a HibernateException.

login

public static User login(Session sess,
                         String username,
                         String password,
                         String userclass)
Retrieve the User with the supplied username and cleartext password, if valid and the user is active. This method is the traditional login method that encrypts the password before handing it on.

Parameters:
sess - The Session to use to query for the user.
username - The username of the user we wish to login.
password - The clear text password of the user we wish to login. This is hashed before being passed on to the database.
userclass - The fully qualified class of user to test. Typically a site will have many kinds of users, eg admin users, subscribers and so forth.
Returns:
The matching User if the username and passwords match exactly one User, or null if not.
See Also:
ctLogin(net.sf.hibernate.Session, java.lang.String, java.lang.String, java.lang.String)

ctLogin

public static User ctLogin(Session sess,
                           String username,
                           String password,
                           String userclass)
Retrieve the User with the supplied username and cleartext password, if valid and the user is active.

Parameters:
sess - The Session to use to query for the user.
username - The username of the user we wish to login.
password - The clear text password of the user we wish to login.
userclass - The fully qualified class of user to test. Typically a site will have many kinds of users, eg admin users, subscribers and so forth.
Returns:
The matching User if the username and passwords match exactly one User, or null if not.
Throws:
RuntimeException - if the params were invalid, or if there was a HibernateException.

loadAll

public static List loadAll(Session sess,
                           String classname,
                           String sort)
loads all the users of the given optional classname and sort order. The sortorders are hibernate query language sort orders. Sort defaults to "username desc".

Parameters:
sess - The Hibernate session.
classname - The specific class of user to list. defaults to" org.davesag.generica.core.User".
sort - The sort order required. Defaults to "username asc".
Returns:
a list of loaded users.
Throws:
RuntimeException - if the params are invalid.


Dave Sag Generica API version 0.5.9 - (prerelease) Copyright 2003 - 2004 Dave Sag.